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
5 changes: 2 additions & 3 deletions imago/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ def _(self, request, *args, **kwargs):
return _


def no_authentication_or_is_authenticated():
def no_authentication_or_is_authenticated(request):
return (not hasattr(settings, 'USE_LOCKSMITH') or not settings.USE_LOCKSMITH
or hasattr(request, 'apikey') and request.apikey.status == 'A')

def authenticated(fn):
""" ensure that request.apikey is valid """
def _(self, request, *args, **kwargs):
if no_authentication_or_is_authenticated():
if no_authentication_or_is_authenticated(request):
if 'apikey' in request.params:
request.params.pop('apikey')

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
14 changes: 8 additions & 6 deletions imago/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@ def sfilter(obj, blacklist):
("note", {}), ("label", {})])


LINK_SERALIZE = dict([
LINK_SERIALIZE = dict([
("note", {}),
("url", {}),
])



Copy link
Member

Choose a reason for hiding this comment

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

No need for newline

IDENTIFIERS_SERIALIZE = {
"identifier": {},
"scheme": {},
Expand All @@ -116,7 +117,7 @@ def sfilter(obj, blacklist):
("extras", lambda x: x.extras),

("identifiers", IDENTIFIERS_SERIALIZE),
("links", LINK_SERALIZE),
("links", LINK_SERIALIZE),
("contact_details", CONTACT_DETAIL_SERIALIZE),
("other_names", OTHER_NAMES_SERIALIZE),
("classification", {}),
Expand Down Expand Up @@ -165,7 +166,7 @@ def sfilter(obj, blacklist):
("identifiers", IDENTIFIERS_SERIALIZE),
("other_names", OTHER_NAMES_SERIALIZE),
("contact_details", CONTACT_DETAIL_SERIALIZE),
("links", LINK_SERALIZE),
("links", LINK_SERIALIZE),
("sources", SOURCES_SERIALIZE),
])

Expand All @@ -176,7 +177,7 @@ def sfilter(obj, blacklist):
("role", {}),
("start_date", {}),
("end_date", {}),
("links", LINK_SERALIZE),
("links", LINK_SERIALIZE),
("contact_details", CONTACT_DETAIL_SERIALIZE),
("organization", ORGANIZATION_SERIALIZE),
("division", DIVISION_SERIALIZE),
Expand All @@ -200,6 +201,7 @@ def sfilter(obj, blacklist):
"person": PERSON_SERIALIZE,
"post": POST_SERIALIZE,
"on_behalf_of": ORGANIZATION_SERIALIZE,
"contact_details": CONTACT_DETAIL_SERIALIZE,
}


Expand Down Expand Up @@ -334,9 +336,9 @@ def sfilter(obj, blacklist):
"entity_id": {}}),

('documents', {"note": {}, "date": {}, "links": LINK_BASE}),
('media', {"note": {}, "date": {}, "offset": {}, "links": LINK_SERALIZE}),
('media', {"note": {}, "date": {}, "offset": {}, "links": LINK_BASE}),

("links", LINK_SERALIZE),
("links", LINK_SERIALIZE),

('created_at', {}),
('updated_at', {}),
Expand Down
4 changes: 4 additions & 0 deletions imago/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ class PersonDetail(PublicDetailEndpoint):
'memberships.post.id',
'memberships.post.division.id',
'memberships.post.division.name',
'memberships.contact_details.type',
'memberships.contact_details.value',
'memberships.contact_details.note',
'memberships.contact_details.label',
'memberships.organization.id',
'memberships.organization.name',
'memberships.organization.jurisdiction.id',
Expand Down