mirror of https://gitlab.com/bashrc2/epicyon
Show location category on post
parent
275c8a816d
commit
3ee7d3258c
35
maps.py
35
maps.py
|
@ -97,6 +97,17 @@ def _get_location_from_tags(tags: []) -> str:
|
|||
return None
|
||||
|
||||
|
||||
def _get_category_from_tags(tags: []) -> str:
|
||||
"""Returns the location category from the tags list
|
||||
"""
|
||||
locn = get_location_dict_from_tags(tags)
|
||||
if locn:
|
||||
if locn.get('category'):
|
||||
location_str = remove_html(locn['category'])
|
||||
return location_str
|
||||
return None
|
||||
|
||||
|
||||
def html_address_book_list(base_dir: str, nickname: str, domain: str) -> str:
|
||||
"""Creates a list of potential addresses when creating a new post
|
||||
with a location
|
||||
|
@ -211,6 +222,30 @@ def get_location_from_post(post_json_object: {}) -> str:
|
|||
return locn
|
||||
|
||||
|
||||
def get_category_from_post(post_json_object: {}) -> str:
|
||||
"""Returns the location category for the given post
|
||||
"""
|
||||
locn = None
|
||||
|
||||
# location represented via a tag
|
||||
post_obj = post_json_object
|
||||
if has_object_dict(post_json_object):
|
||||
post_obj = post_json_object['object']
|
||||
if post_obj.get('tag'):
|
||||
if isinstance(post_obj['tag'], list):
|
||||
locn = _get_category_from_tags(post_obj['tag'])
|
||||
|
||||
# location representation used by pixelfed
|
||||
locn2 = None
|
||||
if post_obj.get('location'):
|
||||
locn2 = post_obj['location']
|
||||
if isinstance(locn2, dict):
|
||||
if locn2.get('category'):
|
||||
locn = remove_html(locn2['category'])
|
||||
|
||||
return locn
|
||||
|
||||
|
||||
def _geocoords_from_osm_link(url: str, osm_domain: str) -> (int, float, float):
|
||||
"""Returns geocoordinates from an OSM map link
|
||||
"""
|
||||
|
|
|
@ -131,6 +131,7 @@ from maps import set_map_preferences_coords
|
|||
from maps import set_map_preferences_url
|
||||
from maps import geocoords_from_map_link
|
||||
from maps import get_location_from_post
|
||||
from maps import get_category_from_post
|
||||
from session import get_json_valid
|
||||
from session import get_json
|
||||
|
||||
|
@ -3187,6 +3188,10 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
|||
buy_links = get_buy_links(post_json_object, translate, buy_sites)
|
||||
# show embedded map if the location contains a map url
|
||||
location_str = get_location_from_post(post_json_object)
|
||||
category_str = ''
|
||||
if location_str:
|
||||
category_str = get_category_from_post(post_json_object)
|
||||
|
||||
loc_str = location_str
|
||||
if location_str:
|
||||
# if this is a location with an address then remove the address
|
||||
|
@ -3250,6 +3255,12 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
|||
'<br>' + translate['Address'] + ':<address>'
|
||||
location_str = \
|
||||
location_str.replace('<br><address>', address_prefix)
|
||||
if category_str:
|
||||
category_text = 'Category'
|
||||
if translate.get('Category'):
|
||||
category_text = translate['Category']
|
||||
map_str = '<p>' + category_text + ': ' + \
|
||||
category_str + '</p>\n'
|
||||
locn_text = 'Location'
|
||||
if translate.get('Location'):
|
||||
locn_text = translate['Location']
|
||||
|
|
Loading…
Reference in New Issue