manager: avoid validation error on journal date search (#54295)

This commit is contained in:
Valentin Deniaud 2021-05-26 11:34:02 +02:00
parent 1a236f7e1d
commit 66a058fac9
2 changed files with 9 additions and 2 deletions

View File

@ -104,12 +104,13 @@ class JournalForm(JournalForm):
def clean_event_type(self):
patterns = self.cleaned_data['event_type'].split(',')
qs_filter = functools.reduce(Q.__or__, (Q(name__regex=pattern) for pattern in patterns))
return EventType.objects.filter(qs_filter)
self.cleaned_data['_event_type'] = EventType.objects.filter(qs_filter)
return self.cleaned_data['event_type']
def get_queryset(self, **kwargs):
qs = super().get_queryset(**kwargs)
event_type = self.cleaned_data.get('event_type')
event_type = self.cleaned_data.get('_event_type')
if event_type:
qs = qs.filter(type__in=event_type)

View File

@ -952,8 +952,14 @@ def test_roles_journal(app, superuser, events):
def test_date_navigation(app, superuser, events):
response = login(app, user=superuser, path="/manage/journal/")
response = response.click('2020')
assert not response.context['form'].errors
response = response.click('January')
response = response.click('1')
content = extract_journal(response)
assert all(item['timestamp'].startswith('Jan. 1, 2020') for item in content)
response = response.click('January 2020')
response = response.click('2020')
response = response.click('All dates')