From a809e5ec7931bf601c19270a6e0341baca457cc8 Mon Sep 17 00:00:00 2001 From: Eric van Zanten Date: Thu, 24 Sep 2015 10:17:46 -0500 Subject: [PATCH 1/8] Making sure that we always find division IDs when mapping to boundaries --- imago/management/commands/loadmappings.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/imago/management/commands/loadmappings.py b/imago/management/commands/loadmappings.py index 7d341a4..3eeda98 100644 --- a/imago/management/commands/loadmappings.py +++ b/imago/management/commands/loadmappings.py @@ -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 @@ -19,8 +20,8 @@ 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 - - print('processing', boundary_set_id) + else: + geoid_mapping[div.id] = div.id boundary_set = BoundarySet.objects.get(pk=boundary_set_id) if callable(boundary_key): @@ -32,10 +33,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) From 5318e80eb28213a0c75b660f7e2b6498cb4a6fb8 Mon Sep 17 00:00:00 2001 From: Eric van Zanten Date: Thu, 24 Sep 2015 10:25:10 -0500 Subject: [PATCH 2/8] Sticking the print back in --- imago/management/commands/loadmappings.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/imago/management/commands/loadmappings.py b/imago/management/commands/loadmappings.py index 3eeda98..760b3d9 100644 --- a/imago/management/commands/loadmappings.py +++ b/imago/management/commands/loadmappings.py @@ -22,7 +22,9 @@ def load_mapping(boundary_set_id, key, prefix, boundary_key='external_id', ignor geoid_mapping[div.attrs[key]] = div.id else: geoid_mapping[div.id] = div.id - + + print('processing', boundary_set_id) + boundary_set = BoundarySet.objects.get(pk=boundary_set_id) if callable(boundary_key): fields = [] From ce054f08701bb712c6a9ac4844d26c7ce634a1d0 Mon Sep 17 00:00:00 2001 From: James McKinney Date: Wed, 4 Nov 2015 10:04:59 -0600 Subject: [PATCH 3/8] Fix "django.conf.urls.patterns() is deprecated" --- imago/urls.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/imago/urls.py b/imago/urls.py index 7f89403..b35d161 100644 --- a/imago/urls.py +++ b/imago/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls import patterns, url +from django.conf.urls import url from imago.views import (JurisdictionList, PeopleList, VoteList, @@ -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()), @@ -34,4 +33,4 @@ url(r'^(?Pocd-organization/.+)/$', OrganizationDetail.as_view()), url(r'^(?Pocd-bill/.+)/$', BillDetail.as_view()), url(r'^(?Pocd-division/.+)/$', DivisionDetail.as_view()), -) +] From 79017d4b5e9ee0083deeaf4b541d27be427323da Mon Sep 17 00:00:00 2001 From: James McKinney Date: Wed, 4 Nov 2015 10:09:13 -0600 Subject: [PATCH 4/8] Fix "get_all_field_names is an unofficial API that has been deprecated" --- imago/helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imago/helpers.py b/imago/helpers.py index 1cfa2d0..66d65d1 100644 --- a/imago/helpers.py +++ b/imago/helpers.py @@ -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): From 30e11e2cda6062d720792eef5eb4acde63f11440 Mon Sep 17 00:00:00 2001 From: James McKinney Date: Tue, 11 Aug 2015 20:01:07 -0400 Subject: [PATCH 5/8] Expose membership contact details, closes #60 --- imago/serialize.py | 1 + imago/views.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/imago/serialize.py b/imago/serialize.py index 6440e6e..cfb27ac 100644 --- a/imago/serialize.py +++ b/imago/serialize.py @@ -200,6 +200,7 @@ def sfilter(obj, blacklist): "person": PERSON_SERIALIZE, "post": POST_SERIALIZE, "on_behalf_of": ORGANIZATION_SERIALIZE, + "contact_details": CONTACT_DETAIL_SERIALIZE, } diff --git a/imago/views.py b/imago/views.py index ac6fe0f..64b449a 100644 --- a/imago/views.py +++ b/imago/views.py @@ -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', From 655df5cc274b584e81a5ac007340dbb6ec3ba0dc Mon Sep 17 00:00:00 2001 From: Forest Gregg Date: Mon, 21 Sep 2015 11:47:58 -0500 Subject: [PATCH 6/8] event media should be serialized with link_base --- imago/serialize.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/imago/serialize.py b/imago/serialize.py index cfb27ac..c8918e9 100644 --- a/imago/serialize.py +++ b/imago/serialize.py @@ -85,12 +85,13 @@ def sfilter(obj, blacklist): ("note", {}), ("label", {})]) -LINK_SERALIZE = dict([ +LINK_SERIALIZE = dict([ ("note", {}), ("url", {}), ]) + IDENTIFIERS_SERIALIZE = { "identifier": {}, "scheme": {}, @@ -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", {}), @@ -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), ]) @@ -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), @@ -335,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', {}), From 90b212ed82cb19b8dc23292778909fb64106d620 Mon Sep 17 00:00:00 2001 From: Bob Lannon Date: Mon, 19 Oct 2015 16:23:26 -0400 Subject: [PATCH 7/8] fixed auth helper --- imago/helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imago/helpers.py b/imago/helpers.py index dc75ae7..1cfa2d0 100644 --- a/imago/helpers.py +++ b/imago/helpers.py @@ -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') From 6b147df96bc5207239dabd01cf3017a1ae00ccaf Mon Sep 17 00:00:00 2001 From: Eric van Zanten Date: Tue, 15 Dec 2015 13:39:44 -0600 Subject: [PATCH 8/8] Removing distinct on from get so that sort works --- imago/helpers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/imago/helpers.py b/imago/helpers.py index 1cfa2d0..9bfc825 100644 --- a/imago/helpers.py +++ b/imago/helpers.py @@ -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)