This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Return contributor details from list API and include in CSV download #1005
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6786260
Return contributor details from list API and include in CSV download
jwalgran 32eae9f
Prevent contributor names and list names from containing |
jwalgran 77a4ea1
Show a determinate progress bar when download facility CSV
jwalgran 0ade4fb
Update CHANGELOG
jwalgran File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -416,11 +416,12 @@ def validate_status(self, value): | |
class FacilitySerializer(GeoFeatureModelSerializer): | ||
oar_id = SerializerMethodField() | ||
country_name = SerializerMethodField() | ||
contributors = SerializerMethodField() | ||
|
||
class Meta: | ||
model = Facility | ||
fields = ('id', 'name', 'address', 'country_code', 'location', | ||
'oar_id', 'country_name') | ||
'oar_id', 'country_name', 'contributors') | ||
geo_field = 'location' | ||
|
||
# Added to ensure including the OAR ID in the geojson properties map | ||
|
@@ -430,13 +431,33 @@ def get_oar_id(self, facility): | |
def get_country_name(self, facility): | ||
return COUNTRY_NAMES.get(facility.country_code, '') | ||
|
||
def get_contributors(self, facility): | ||
def format_source(source): | ||
if type(source) is Source: | ||
return { | ||
'id': source.contributor.admin.id | ||
if source.contributor else None, | ||
'name': source.display_name, | ||
'is_verified': source.contributor.is_verified | ||
if source.contributor else False, | ||
} | ||
return { | ||
'name': source, | ||
} | ||
request = self.context.get('request') \ | ||
if self.context is not None else None | ||
user = request.user if request is not None else None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An explicit None check is less helpful here, but I have opted to use the same construction for consistency. |
||
return [ | ||
format_source(source) | ||
for source | ||
in facility.sources(user=user) | ||
] | ||
|
||
|
||
class FacilityDetailsSerializer(GeoFeatureModelSerializer): | ||
oar_id = SerializerMethodField() | ||
class FacilityDetailsSerializer(FacilitySerializer): | ||
other_names = SerializerMethodField() | ||
other_addresses = SerializerMethodField() | ||
other_locations = SerializerMethodField() | ||
contributors = SerializerMethodField() | ||
country_name = SerializerMethodField() | ||
claim_info = SerializerMethodField() | ||
|
||
|
@@ -447,10 +468,6 @@ class Meta: | |
'country_name', 'claim_info', 'other_locations') | ||
geo_field = 'location' | ||
|
||
# Added to ensure including the OAR ID in the geojson properties map | ||
def get_oar_id(self, facility): | ||
return facility.id | ||
|
||
def get_other_names(self, facility): | ||
return facility.other_names() | ||
|
||
|
@@ -499,28 +516,6 @@ def get_other_locations(self, facility): | |
|
||
return facility_locations + facility_matches | ||
|
||
def get_contributors(self, facility): | ||
def format_source(source): | ||
if type(source) is Source: | ||
return { | ||
'id': source.contributor.admin.id | ||
if source.contributor else None, | ||
'name': source.display_name, | ||
'is_verified': source.contributor.is_verified | ||
if source.contributor else False, | ||
} | ||
return { | ||
'name': source, | ||
} | ||
request = self.context.get('request') \ | ||
if self.context is not None else None | ||
user = request.user if request is not None else None | ||
return [ | ||
format_source(source) | ||
for source | ||
in facility.sources(user=user) | ||
] | ||
|
||
def get_country_name(self, facility): | ||
return COUNTRY_NAMES.get(facility.country_code, '') | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be shortened to
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use this construction a few places in models.py too. In general I tend to prefer to use explicit
None
checks when I can to avoid type coercion ambiguity, like empty objects being falsey.