Skip to content

Commit

Permalink
fixes bug 1395629 - Ability to filter uploads by "cancelled" (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Bengtsson committed Aug 31, 2017
1 parent 5411e44 commit edf0753
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions tecken/api/forms.py
Expand Up @@ -154,6 +154,9 @@ def _clean_dates(self, values):
rest = operators.sub('', block).strip()
if rest.lower() in ('null', 'incomplete'):
date_obj = None
elif rest.lower() == 'cancelled':
# Exceptional exception
date_obj = 'cancelled'
else:
try:
date_obj = dateutil.parser.parse(rest)
Expand Down
4 changes: 3 additions & 1 deletion tecken/api/views.py
Expand Up @@ -328,7 +328,9 @@ def uploads(request):
qs = qs.filter(**{orm_operator: value})
for key in ('created_at', 'completed_at'):
for operator, value in form.cleaned_data.get(key, []):
if value is None:
if value == 'cancelled':
qs = qs.filter(cancelled_at__isnull=False)
elif value is None:
orm_operator = f'{key}__isnull'
qs = qs.filter(**{orm_operator: True})
elif operator == '=' and value.hour == 0 and value.minute == 0:
Expand Down
16 changes: 16 additions & 0 deletions tests/test_api.py
Expand Up @@ -616,6 +616,22 @@ def test_uploads(client):
data = response.json()
assert not data['uploads']

# Filter by cancelled
response = client.get(url, {
'completed_at': 'Cancelled',
})
assert response.status_code == 200
data = response.json()
assert not data['uploads']
upload.cancelled_at = timezone.now()
upload.save()
response = client.get(url, {
'completed_at': 'Cancelled',
})
assert response.status_code == 200
data = response.json()
assert data['uploads']


@pytest.mark.django_db
def test_upload(client):
Expand Down

0 comments on commit edf0753

Please sign in to comment.