diff --git a/contributors/forms/forms.py b/contributors/forms/forms.py index be83b5be..8191da71 100644 --- a/contributors/forms/forms.py +++ b/contributors/forms/forms.py @@ -4,6 +4,8 @@ from django import forms from django.utils.translation import gettext_lazy as _ +from contributors.models.repository import Repository + class TableSortSearchForm(forms.Form): """A search form.""" @@ -84,6 +86,13 @@ class NameStatusFilterForm(TableSortSearchForm): initial='', ) + repository = forms.ModelChoiceField( + queryset=Repository.objects.all(), + required=False, + label=False, + empty_label=_("Filter by repository"), + ) + @property def helper(self): """Control form attributes and its layout.""" @@ -92,8 +101,11 @@ def helper(self): helper.form_class = 'd-flex' helper.layout = Layout( Field('search', placeholder=_("Filter by name")), + Field('state'), + Field('repository'), + Field('created_after'), FieldWithButtons( - Field('state'), + Field('created_till'), StrictButton( _("Search"), type='submit', @@ -120,3 +132,25 @@ class PullRequestNameStatusFilterForm(NameStatusFilterForm): label=False, initial='', ) + created_till = forms.DateField( + required=False, + label=False, + widget=forms.DateInput( + attrs={ + 'type': 'text', + 'placeholder': _("Created till"), + 'onfocus': "(this.type='date')", + }, + ), + ) + created_after = forms.DateField( + required=False, + label=False, + widget=forms.DateInput( + attrs={ + 'type': 'text', + 'placeholder': _("Created after"), + 'onfocus': "(this.type='date')", + }, + ), + ) diff --git a/contributors/views/pull_requests.py b/contributors/views/pull_requests.py index f514353f..7ff8882e 100644 --- a/contributors/views/pull_requests.py +++ b/contributors/views/pull_requests.py @@ -37,14 +37,30 @@ def get_queryset(self): # noqa: WPS615 ) form_status = PullRequestNameStatusFilterForm(self.request.GET) + if form_status.is_valid(): status = form_status.cleaned_data['state'] + start_date = form_status.cleaned_data['created_after'] + end_date = form_status.cleaned_data['created_till'] + repository = form_status.cleaned_data['repository'] if status: self.queryset = self.queryset.filter( info__state=status, ).distinct() + if start_date: + self.queryset = self.queryset.filter( + created_at__gte=start_date, + ).distinct() + if end_date: + self.queryset = self.queryset.filter( + created_at__lte=end_date, + ).distinct() + if repository: + self.queryset = self.queryset.filter( + repository=repository, + ).distinct() - return super().get_queryset() + return super().get_queryset() def get_context_data(self, **kwargs): """Get search form by state.""" @@ -52,5 +68,4 @@ def get_context_data(self, **kwargs): context['form_status'] = PullRequestNameStatusFilterForm( self.request.GET, ) - return context diff --git a/locale/ru/LC_MESSAGES/django.mo b/locale/ru/LC_MESSAGES/django.mo index da26bef5..1bd00a81 100644 Binary files a/locale/ru/LC_MESSAGES/django.mo and b/locale/ru/LC_MESSAGES/django.mo differ diff --git a/locale/ru/LC_MESSAGES/django.po b/locale/ru/LC_MESSAGES/django.po index 0983c6b8..be0abed2 100644 --- a/locale/ru/LC_MESSAGES/django.po +++ b/locale/ru/LC_MESSAGES/django.po @@ -2,13 +2,13 @@ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. -# +# #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-12-06 22:13+0400\n" +"POT-Creation-Date: 2024-01-02 11:16+0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -81,6 +81,18 @@ msgstr "Фильтрация по организации" msgid "Filter by status" msgstr "Фильтрация по статусу" +#: contributors/forms/forms.py +msgid "Filter by repository" +msgstr "Фильтрация по репозиторию" + +#: contributors/forms/forms.py +msgid "Created till" +msgstr "Создан до" + +#: contributors/forms/forms.py +msgid "Created after" +msgstr "Создан после" + #: contributors/models/base.py msgid "name" msgstr "имя" diff --git a/locale/ru/LC_MESSAGES/djangojs.po b/locale/ru/LC_MESSAGES/djangojs.po index cf485736..167d97d7 100644 --- a/locale/ru/LC_MESSAGES/djangojs.po +++ b/locale/ru/LC_MESSAGES/djangojs.po @@ -2,13 +2,13 @@ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. -# +# #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-12-06 22:13+0400\n" +"POT-Creation-Date: 2024-01-02 11:16+0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n"