Skip to content

Commit

Permalink
Merge pull request #379 from al-ov73/pr_datefilter
Browse files Browse the repository at this point in the history
Make filtration of PR by repo and date
  • Loading branch information
sgmdlt authored Feb 5, 2024
2 parents f9e7146 + 051467d commit 17893b6
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 7 deletions.
36 changes: 35 additions & 1 deletion contributors/forms/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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."""
Expand All @@ -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',
Expand All @@ -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')",
},
),
)
19 changes: 17 additions & 2 deletions contributors/views/pull_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,35 @@ 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."""
context = super().get_context_data(**kwargs)
context['form_status'] = PullRequestNameStatusFilterForm(
self.request.GET,
)

return context
Binary file modified locale/ru/LC_MESSAGES/django.mo
Binary file not shown.
16 changes: 14 additions & 2 deletions locale/ru/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 <EMAIL@ADDRESS>, 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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -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 "имя"
Expand Down
4 changes: 2 additions & 2 deletions locale/ru/LC_MESSAGES/djangojs.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 <EMAIL@ADDRESS>, 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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down

0 comments on commit 17893b6

Please sign in to comment.