Commit 26166e00 authored by Michal Čihař's avatar Michal Čihař

Allow to specify end date for credits

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 289c474d
......@@ -821,9 +821,6 @@ class ReportDownloadForm(forms.Form):
('json', _('JSON'))
),
)
class CreditsForm(ReportDownloadForm):
start_date = forms.DateField(
label=_('Starting date'),
initial=date(2000, 1, 1),
......@@ -836,3 +833,19 @@ class CreditsForm(ReportDownloadForm):
format='%Y-%m-%d'
)
)
end_date = forms.DateField(
label=_('Ending date'),
initial=date(2100, 1, 1),
widget=forms.DateInput(
attrs={
'type': 'date',
'data-provide': 'datepicker',
'data-date-format': 'yyyy-mm-dd',
},
format='%Y-%m-%d'
)
)
class CreditsForm(ReportDownloadForm):
pass
......@@ -42,7 +42,8 @@ class ReportsTest(ViewTestCase):
def test_credits_empty(self):
data = generate_credits(
self.subproject,
timezone.now() - timedelta(days=1)
timezone.now() - timedelta(days=1),
timezone.now() + timedelta(days=1)
)
self.assertEqual(data, [])
......@@ -50,7 +51,8 @@ class ReportsTest(ViewTestCase):
self.add_change()
data = generate_credits(
self.subproject,
timezone.now() - timedelta(days=1)
timezone.now() - timedelta(days=1),
timezone.now() + timedelta(days=1)
)
self.assertEqual(
data,
......@@ -68,7 +70,11 @@ class ReportsTest(ViewTestCase):
self.add_change()
response = self.client.post(
reverse('credits', kwargs=self.kw_subproject),
{'style': 'json', 'start_date': '2000-01-01'},
{
'style': 'json',
'start_date': '2000-01-01',
'end_date': '2100-01-01'
},
)
data = json.loads(response.content)
self.assertEqual(
......@@ -80,7 +86,11 @@ class ReportsTest(ViewTestCase):
self.add_change()
response = self.client.post(
reverse('credits', kwargs=self.kw_subproject),
{'style': 'rst', 'start_date': '2000-01-01'},
{
'style': 'rst',
'start_date': '2000-01-01',
'end_date': '2100-01-01'
},
)
self.assertEqual(
response.content,
......
......@@ -30,14 +30,15 @@ from django.core.exceptions import PermissionDenied
import json
def generate_credits(component, start_date):
def generate_credits(component, start_date, end_date):
"""Generates credits data for given component."""
result = []
for translation in component.translation_set.all():
authors = Change.objects.content().filter(
translation=translation
translation=translation,
timestamp__range=(start_date, end_date),
).values_list(
'author__email', 'author__first_name'
)
......@@ -62,7 +63,11 @@ def get_credits(request, project, subproject):
if not form.is_valid():
return redirect(obj)
data = generate_credits(obj, form.cleaned_data['start_date'])
data = generate_credits(
obj,
form.cleaned_data['start_date'],
form.cleaned_data['end_date'],
)
if form.cleaned_data['style'] == 'json':
return HttpResponse(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment