Permalink
Browse files

fixes bug 1395629 - Ability to filter uploads by "cancelled" (#362)

  • Loading branch information...
peterbe committed Aug 31, 2017
1 parent 5411e44 commit edf0753bca3f91759c673ae0d8a690a5ccf92548
Showing with 22 additions and 1 deletion.
  1. +3 −0 tecken/api/forms.py
  2. +3 −1 tecken/api/views.py
  3. +16 −0 tests/test_api.py
View
@@ -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)
View
@@ -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:
View
@@ -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):

0 comments on commit edf0753

Please sign in to comment.