Skip to content
This repository has been archived by the owner on Mar 29, 2019. It is now read-only.

Get sort query parameter to work again #75

Closed
wants to merge 12 commits into from
3 changes: 1 addition & 2 deletions imago/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_field_list(model, without=None):
without = set()
else:
without = set(without)
return list(set(model._meta.get_all_field_names()) - without)
return list({f.name for f in model._meta.get_fields()} - without)


class FieldKeyError(KeyError):
Expand Down Expand Up @@ -289,7 +289,6 @@ def get(self, request, *args, **kwargs):
data = self.get_query_set(request, *args, **kwargs)
data = self.filter(data, **params)
data = self.sort(data, sort_by)
data = data.distinct("id")

try:
related, config = get_fields(self.serialize_config, fields=fields)
Expand Down
10 changes: 8 additions & 2 deletions imago/management/commands/loadmappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


def load_mapping(boundary_set_id, key, prefix, boundary_key='external_id', ignore=None, quiet=False):

if ignore:
ignore = re.compile(ignore)
ignored = 0
Expand All @@ -19,9 +20,11 @@ def load_mapping(boundary_set_id, key, prefix, boundary_key='external_id', ignor
for div in Division.get('ocd-division/country:' + settings.IMAGO_COUNTRY).children(levels=100):
if div.attrs[key]:
geoid_mapping[div.attrs[key]] = div.id

else:
geoid_mapping[div.id] = div.id

print('processing', boundary_set_id)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra whitespace. Remove the new newlines as well.

boundary_set = BoundarySet.objects.get(pk=boundary_set_id)
if callable(boundary_key):
fields = []
Expand All @@ -32,10 +35,13 @@ def load_mapping(boundary_set_id, key, prefix, boundary_key='external_id', ignor
boundary_property = boundary_key(boundary)
else:
boundary_property = boundary[boundary_key]

ocd_id = geoid_mapping.get(prefix + boundary_property)

if ocd_id:
division_geometries.append(DivisionGeometry(division_id=ocd_id,
boundary_id=boundary['id']))

elif not ignore or not ignore.match(boundary['name']):
if not quiet:
print('unmatched external id', boundary['name'], boundary_property)
Expand Down
7 changes: 3 additions & 4 deletions imago/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import patterns, url
from django.conf.urls import url
from imago.views import (JurisdictionList,
PeopleList,
VoteList,
Expand All @@ -16,8 +16,7 @@
DivisionDetail
)

urlpatterns = patterns(
'',
urlpatterns = [
url(r'^jurisdictions/$', JurisdictionList.as_view()),
url(r'^people/$', PeopleList.as_view()),
url(r'^votes/$', VoteList.as_view()),
Expand All @@ -34,4 +33,4 @@
url(r'^(?P<pk>ocd-organization/.+)/$', OrganizationDetail.as_view()),
url(r'^(?P<pk>ocd-bill/.+)/$', BillDetail.as_view()),
url(r'^(?P<pk>ocd-division/.+)/$', DivisionDetail.as_view()),
)
]