Skip to content

Commit

Permalink
Remove order_by id options (#669)
Browse files Browse the repository at this point in the history
  • Loading branch information
willemarcel authored Feb 16, 2024
1 parent 37d2f0c commit 8262c7c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
4 changes: 2 additions & 2 deletions osmchadjango/changeset/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ChangesetFilter(GeoFilterSet):
help_text="""Order the Changesets by one of the following fields: id,
date, check_date, create, modify, delete or number_reasons. Use a
minus sign (-) before the field name to reverse the ordering.
Default ordering is '-id'."""
Default ordering is '-date'."""
)
hide_whitelist = filters.BooleanFilter(
field_name='user',
Expand Down Expand Up @@ -443,7 +443,7 @@ def filter_number_reasons(self, queryset, name, value):

def order_queryset(self, queryset, name, value):
allowed_fields = [
'date', '-date', 'id', 'check_date', '-check_date', 'create',
'date', '-date', 'check_date', '-check_date', 'create',
'modify', 'delete', '-create', '-modify', '-delete',
'number_reasons', '-number_reasons', 'comments_count',
'-comments_count'
Expand Down
2 changes: 1 addition & 1 deletion osmchadjango/changeset/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def id_link(self):
return ""

class Meta:
ordering = ['-id']
ordering = ['-date']
indexes = [
GinIndex(fields=['tag_changes'])
]
Expand Down
16 changes: 3 additions & 13 deletions osmchadjango/changeset/tests/test_changeset_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,26 +380,16 @@ def setUp(self):
self.url = reverse('changeset:list')

def test_ordering(self):
# default ordering is by descending id
# descending date ordering is the default
response = self.client.get(self.url)
ids = [i['id'] for i in response.data.get('features')]
self.assertTrue(ids[0] > ids[1])

# ascending id
response = self.client.get(self.url, {'order_by': 'id'})
ids = [i['id'] for i in response.data.get('features')]
self.assertTrue(ids[0] < ids[1])
dates = [i['properties']['date'] for i in response.data.get('features')]
self.assertTrue(dates[0] > dates[1])

# ascending date ordering
response = self.client.get(self.url, {'order_by': 'date'})
dates = [i['properties']['date'] for i in response.data.get('features')]
self.assertTrue(dates[0] < dates[1])

# descending date ordering
response = self.client.get(self.url, {'order_by': '-date'})
dates = [i['properties']['date'] for i in response.data.get('features')]
self.assertTrue(dates[0] > dates[1])

# ascending check_date
response = self.client.get(self.url, {'order_by': 'check_date'})
check_dates = [i['properties']['check_date'] for i in response.data.get('features')]
Expand Down

0 comments on commit 8262c7c

Please sign in to comment.