<commit_before>"""Views for lutris main app"""
# pylint: disable=too-many-ancestors
from __future__ import absolute_import

import json
import logging

from django.conf import settings
from django.contrib import messages
from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.auth.decorators import login_required
from django.contrib.syndication.views import Feed
from django.core.mail import mail_managers
from django.db.models import Count, Q
from django.http import Http404, HttpResponse, HttpResponseBadRequest
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
from django.utils import timezone
from django.views.decorators.http import require_POST
from django.views.generic import ListView

import reversion
from reversion.models import Version
from sorl.thumbnail import get_thumbnail

from accounts.decorators import (check_installer_restrictions,
                                 user_confirmed_required)
from games import models
from games.forms import (ForkInstallerForm, GameEditForm, GameForm,
                         InstallerEditForm, InstallerForm, ScreenshotForm)
from games.models import Game, GameSubmission, Installer, InstallerIssue
from games.util.pagination import get_page_range
from platforms.models import Platform

LOGGER = logging.getLogger(__name__)


class GameList(ListView):
    """Game list view"""
    model = models.Game
    context_object_name = "games"
    paginate_by = 25

    def get_queryset(self):
        queryset = models.Game.objects
        unpublished_filter = self.request.GET.get('unpublished-filter')
        if unpublished_filter:
            queryset = queryset.filter(change_for__isnull=True)
        else:
            queryset = queryset.with_installer()

        if self.request.GET.get('sort-by-popularity') or not self.request.GET:
            queryset = queryset.annotate(
                library_count=Count('gamelibrary', distinct=True)
            ).order_by('-library_count')
        return self.get_filtered_queryset(queryset)

    def get_filtered_queryset(self, queryset):
        # Filter open source
        filters = []
        if self.request.GET.get('fully-libre-filter'):
            filters.append('fully_libre')
        if self.request.GET.get('open-engine-filter'):
            filters.append('open_engine')
        open_source_filters = " | ".join(["Q(flags=Game.flags.%s)" % flag for flag in filters])

        # Filter free
        filters = []
        if self.request.GET.get('free-filter'):
            filters.append('free')
        if self.request.GET.get('freetoplay-filter'):<commit_msg>Ignore page argument for popularity search<commit_after>"""Views for lutris main app"""
# pylint: disable=too-many-ancestors
from __future__ import absolute_import

import json
import logging

from django.conf import settings
from django.contrib import messages
from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.auth.decorators import login_required
from django.contrib.syndication.views import Feed
from django.core.mail import mail_managers
from django.db.models import Count, Q
from django.http import Http404, HttpResponse, HttpResponseBadRequest
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
from django.utils import timezone
from django.views.decorators.http import require_POST
from django.views.generic import ListView

import reversion
from reversion.models import Version
from sorl.thumbnail import get_thumbnail

from accounts.decorators import (check_installer_restrictions,
                                 user_confirmed_required)
from games import models
from games.forms import (ForkInstallerForm, GameEditForm, GameForm,
                         InstallerEditForm, InstallerForm, ScreenshotForm)
from games.models import Game, GameSubmission, Installer, InstallerIssue
from games.util.pagination import get_page_range
from platforms.models import Platform

LOGGER = logging.getLogger(__name__)


class GameList(ListView):
    """Game list view"""
    model = models.Game
    context_object_name = "games"
    paginate_by = 25

    def get_queryset(self):
        queryset = models.Game.objects
        unpublished_filter = self.request.GET.get('unpublished-filter')
        if unpublished_filter:
            queryset = queryset.filter(change_for__isnull=True)
        else:
            queryset = queryset.with_installer()

        search_params = [key for key in self.request.GET.keys() if key != 'page']

        if self.request.GET.get('sort-by-popularity') or not search_params:
            queryset = queryset.annotate(
                library_count=Count('gamelibrary', distinct=True)
            ).order_by('-library_count')
        return self.get_filtered_queryset(queryset)

    def get_filtered_queryset(self, queryset):
        # Filter open source
        filters = []
        if self.request.GET.get('fully-libre-filter'):
            filters.append('fully_libre')
        if self.request.GET.get('open-engine-filter'):
            filters.append('open_engine')
        open_source_filters = " | ".join(["Q(flags=Game.flags.%s)" % flag for flag in filters])

        # Filter free
        filters = []
        if self.request.GET.get('free-filter'):
            filters.append('free')
        if self.request.GET.get('freetoplay-filter'):
{'fraction_non_alphanumeric': 0.08491785120915636, 'fraction_numerical': 0.0029536643898836995, 'mean_word_length': 3.4666117065127784, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3057903', 'n_tokens_mistral': 1510, 'n_tokens_neox': 1462, 'n_words': 375}