<commit_before># Copyright (C) 2021 <NAME> <<EMAIL>>
# Licensed under GNU Affero GPL v3 or later

from enum import Enum

from django.contrib.syndication.views import Feed
from django.db.models import Q
from django.http import HttpRequest
from django.utils.translation import gettext_lazy as _

from ..models import DebianLogIndex, EventKind, IssueKind
from ..templatetags.debian_urls import wnpp_issue_url

_MAX_ENTRIES = 30


class _DataSet(Enum):
    ALL = 'all'
    BAD_NEWS = 'bad_news'
    GOOD_NEWS = 'good_news'
    HELP_EXISTING = 'help_existing'
    NEW_PACKAGES = 'new_packages'

    @classmethod
    def _missing_(cls, value):
        return cls.ALL


_FILTER_GOOD_NEWS: Q = (Q(event=EventKind.CLOSED.value)
                        | Q(event__in=(EventKind.MODIFIED.value, EventKind.OPENED.value),
                            kind__in=(IssueKind.ITA.value, IssueKind.ITP.value)))

_DATASETS: dict[_DataSet, tuple[str, Q]] = {
    _DataSet.ALL: (_('Debian Packaging News'), (Q())),
    _DataSet.BAD_NEWS: (_('Bad News on Debian Packages'), ~_FILTER_GOOD_NEWS),
    _DataSet.GOOD_NEWS: (_('Good News on Debian Packages'), _FILTER_GOOD_NEWS),
    _DataSet.HELP_EXISTING: (_('Existing Debian Packages In Need For Help'),
                             Q(event__in=(EventKind.MODIFIED.value, EventKind.OPENED.value),
                               kind__in=(IssueKind.O_.value, IssueKind.RFA.value,
                                         IssueKind.RFH.value))),
    _DataSet.NEW_PACKAGES: (_('New Debian Packages'), Q(event=EventKind.CLOSED,
                                                        kind=IssueKind.ITP)),
}


class WnppNewsFeedView(Feed):
    title = _('Debian Packaging News')
    description = _('Debian news feed on packaging bugs')
    ttl = 15  # seconds

    def __call__(self, request, *args, **kwargs):
        self.__request: HttpRequest = request
        self.__title_format_kind = self.__request.GET.get('title_format', '0')
        self.__data_set = self.__request.GET.get('data', 'all')

        self.feed_url = self.__request.build_absolute_uri(self.__request.get_full_path())
        self.link = self.feed_url

        return super().__call__(request, *args, **kwargs)

    def title(self):
        return _DATASETS[_DataSet(self.__data_set)][0]

    def _get_querset_filter(self):
        return _DATASETS[_DataSet(self.__data_set)][1]

    def items(self):
        return (DebianLogIndex.objects.filter(self._get_querset_filter()).select_related(
            'kind_change').order_by('-event_stamp')[:_MAX_ENTRIES])

    def item_author_email(self, item: DebianLogIndex):
        return f'{<EMAIL>'

    def item_author_name(self, item: DebianLogIndex):
        return f'Debian WNPP issue {item.ident}'

    def item_description(self, item: DebianLogIndex):
        return wnpp_issue_url(item.ident)  # for backwards-compatibility, only

    def item_guid(self, item: DebianLogIndex):
        # NOTE: The HTTP absolute URL is in place for backwards-compatibility, only
        return f'http://wnpp.debian.net/{item.ident}/{item.event_stamp.timestamp():.0f}'

    def item_link(self, item):<commit_msg>rss_feed.py: Expose object_list for upcoming tests<commit_after># Copyright (C) 2021 <NAME> <<EMAIL>>
# Licensed under GNU Affero GPL v3 or later

import sys
from enum import Enum

from django.contrib.syndication.views import Feed
from django.db.models import Q
from django.http import HttpRequest
from django.utils.translation import gettext_lazy as _

from ..models import DebianLogIndex, EventKind, IssueKind
from ..templatetags.debian_urls import wnpp_issue_url

_MAX_ENTRIES = 30


class _DataSet(Enum):
    ALL = 'all'
    BAD_NEWS = 'bad_news'
    GOOD_NEWS = 'good_news'
    HELP_EXISTING = 'help_existing'
    NEW_PACKAGES = 'new_packages'

    @classmethod
    def _missing_(cls, value):
        return cls.ALL


_FILTER_GOOD_NEWS: Q = (Q(event=EventKind.CLOSED.value)
                        | Q(event__in=(EventKind.MODIFIED.value, EventKind.OPENED.value),
                            kind__in=(IssueKind.ITA.value, IssueKind.ITP.value)))

_DATASETS: dict[_DataSet, tuple[str, Q]] = {
    _DataSet.ALL: (_('Debian Packaging News'), (Q())),
    _DataSet.BAD_NEWS: (_('Bad News on Debian Packages'), ~_FILTER_GOOD_NEWS),
    _DataSet.GOOD_NEWS: (_('Good News on Debian Packages'), _FILTER_GOOD_NEWS),
    _DataSet.HELP_EXISTING: (_('Existing Debian Packages In Need For Help'),
                             Q(event__in=(EventKind.MODIFIED.value, EventKind.OPENED.value),
                               kind__in=(IssueKind.O_.value, IssueKind.RFA.value,
                                         IssueKind.RFH.value))),
    _DataSet.NEW_PACKAGES: (_('New Debian Packages'), Q(event=EventKind.CLOSED,
                                                        kind=IssueKind.ITP)),
}


class WnppNewsFeedView(Feed):
    title = _('Debian Packaging News')
    description = _('Debian news feed on packaging bugs')
    ttl = 15  # seconds

    def __call__(self, request, *args, **kwargs):
        self.__request: HttpRequest = request
        self.__title_format_kind = self.__request.GET.get('title_format', '0')
        self.__data_set = self.__request.GET.get('data', 'all')

        self.feed_url = self.__request.build_absolute_uri(self.__request.get_full_path())
        self.link = self.feed_url

        response = super().__call__(request, *args, **kwargs)

        if 'test' in sys.argv:
            response.context_data = {
                'object_list': self.items(),
            }

        return response

    def title(self):
        return _DATASETS[_DataSet(self.__data_set)][0]

    def _get_querset_filter(self):
        return _DATASETS[_DataSet(self.__data_set)][1]

    def items(self):
        return (DebianLogIndex.objects.filter(self._get_querset_filter()).select_related(
            'kind_change').order_by('-event_stamp')[:_MAX_ENTRIES])

    def item_author_email(self, item: DebianLogIndex):
        return f'{<EMAIL>'

    def item_author_name(self, item: DebianLogIndex):
        return f'Debian WNPP issue {item.ident}'

    def item_description(self, item: DebianLogIndex):
        return wnpp_issue_url(item.ident)  # for backwards-compatibility, only

    def item_guid(self, item: DebianLogIndex):
        # NOTE: The HTTP absolute URL is in place for backwards-compatibility, only
        return f'http://wnpp.debian.net/{item.ident}/{item.event_stamp.timestamp():.0f}'

    def item_link(self, item):
{'fraction_non_alphanumeric': 0.1138537488429497, 'fraction_numerical': 0.004011107682813947, 'mean_word_length': 2.974862047823421, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7639438', 'n_tokens_mistral': 2105, 'n_tokens_neox': 2029, 'n_words': 433}