-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CB-260: Show external URLs and related places on place pages
- Loading branch information
Showing
4 changed files
with
75 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from flask_babel import lazy_gettext | ||
|
||
|
||
def process(place): | ||
"""Handles processing supported relation lists.""" | ||
|
||
if 'url-rels' in place and place['url-rels']: | ||
place['external-urls'] = _url(place['url-rels']) | ||
|
||
if 'place-rels' in place and place['place-rels']: | ||
place['place-rels'] = _place(place['place-rels']) | ||
return place | ||
|
||
|
||
def _url(url_list): | ||
"""Processor for Place-URL relationship.""" | ||
basic_types = { | ||
'wikidata': { | ||
'name': lazy_gettext('Wikidata'), 'icon': 'wikidata-16.png', | ||
}, | ||
'discogs': { | ||
'name': lazy_gettext('Discogs'), 'icon': 'discogs-16.png', | ||
}, | ||
'last.fm': { | ||
'name': lazy_gettext('Last.fm'), 'icon': 'lastfm-16.png', | ||
}, | ||
'official homepage': { | ||
'name': lazy_gettext('Official homepage'), 'icon': 'home-16.png', | ||
}, | ||
} | ||
external_urls = [] | ||
for relation in url_list: | ||
if relation['type'] in basic_types: | ||
external_urls.append(dict(list(relation.items()) + list(basic_types[relation['type']].items()))) | ||
return sorted(external_urls, key=lambda k: k['name']) | ||
|
||
|
||
def _place(place_list): | ||
"""Processor for Place-Place relationship.""" | ||
related_places = [] | ||
for relation in place_list: | ||
if relation['direction'] == 'backward': | ||
related_places.append(relation) | ||
return related_places |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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