Skip to content

Commit

Permalink
adds links to pantheon paragraph text
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandersimoes committed Dec 3, 2019
1 parent 45860e0 commit 36ab727
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
9 changes: 9 additions & 0 deletions oec/assets/scss/elements/_profile.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,15 @@ body.profile {
}

section aside a {
color: black;
border-bottom: 1px solid black;

&:hover {
border-bottom: none;
}
}

section aside a.viz_link {
color: black;
text-transform: uppercase;
letter-spacing: 0.1em;
Expand Down
26 changes: 24 additions & 2 deletions oec/profile/sections/pantheon.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
from flask_babel import gettext as _
import requests
import json

def format_pantheon_link(pantheon_obj, name_accessor="name"):
profile_type = "person" if name_accessor == "name" else "place"
return u"<a target='_blank' href='https://pantheon.world/profile/{}/{}/'>{}</a>".format(profile_type, pantheon_obj["slug"], pantheon_obj[name_accessor])

def make_pantheon_section(pantheon_id, attr):
country_name = attr.get_name()
memorable_people_xhr = requests.get('https://api.pantheon.world/person?select=name,hpi,id,slug,gender,birthyear,deathyear,bplace_country(id,country,continent,slug),bplace_geonameid(id,place,country,slug,lat,lon)&birthyear=gte.-3501&birthyear=lte.2015&bplace_country=eq.{}&hpi=gte.4&order=hpi.desc.nullslast&limit=10'.format(country_name))
memorable_people = json.loads(memorable_people_xhr.text)

memorable_places_xhr = requests.get('https://api.pantheon.world/place?select=place,hpi,id,slug,num_born&country=eq.{}&order=hpi.desc.nullslast&limit=10'.format(country_name))
memorable_places = json.loads(memorable_places_xhr.text)

pantheon_fields_iframe = "https://pantheon.world/explore/viz/embed?viz=treemap&show=occupations&years=-3501,2015&place={}".format(pantheon_id)
pantheon_fields_subtitle = [_(u"This treemap shows the cultural exports %(of_country)s, as proxied by the production of globally famous historical characters.", of_country=attr.get_name(article="of"))]
pantheon_fields_subtitle.append(u"<a target='_blank' href='https://pantheon.world/explore/viz?viz=treemap&show=occupations&years=-3501,2015&place={}'>{} <i class='fa fa-external-link'></i></a>".format(pantheon_id, _("Explore on Pantheon")))
if(memorable_people):
memorable_people_as_links = [format_pantheon_link(p) for p in memorable_people]
memorable_people_as_links_str = u", ".join(memorable_people_as_links[:-2] + [u" and ".join(memorable_people_as_links[-2:])])
pantheon_fields_subtitle.append(u"The most memorable people born within the present day boundries of {} include {}.".format(country_name, memorable_people_as_links_str))
# raise Exception(u"The most memorable people born within the present day boundries of {} include {}.".format(country_name, memorable_people_as_links_str))
pantheon_fields_subtitle.append(u"<a target='_blank' class='viz_link' href='https://pantheon.world/explore/viz?viz=treemap&show=occupations&years=-3501,2015&place={}'>{} <i class='fa fa-external-link'></i></a>".format(pantheon_id, _("Explore on Pantheon")))

pantheon_cities_iframe = "https://pantheon.world/explore/viz/embed?viz=treemap&show=places&years=-3501,2015&place={}".format(pantheon_id)
pantheon_cities_subtitle = [_(u"This treemap shows the cultural exports %(of_country)s by city, as proxied by the production of globally famous historical characters.", of_country=attr.get_name(article="of"))]
pantheon_cities_subtitle.append(u"<a target='_blank' href='https://pantheon.world/explore/viz?viz=treemap&show=places&years=-3501,2015&place={0}'>{1} <i class='fa fa-external-link'></i></a>".format(pantheon_id, _("Explore on Pantheon")))
if(memorable_places):
memorable_places_as_links = [format_pantheon_link(p, "place") for p in memorable_places]
memorable_places_as_links_str = u", ".join(memorable_places_as_links[:-2] + [u" and ".join(memorable_places_as_links[-2:])])
pantheon_cities_subtitle.append(u"The most common birth places of memorable people born within the present day boundries of {} include {}.".format(country_name, memorable_places_as_links_str))
pantheon_cities_subtitle.append(u"<a target='_blank' class='viz_link' href='https://pantheon.world/explore/viz?viz=treemap&show=places&years=-3501,2015&place={0}'>{1} <i class='fa fa-external-link'></i></a>".format(pantheon_id, _("Explore on Pantheon")))

pantheon_section = {
"title": "<a target='_blank' href='https://pantheon.world'><img src='https://pantheon.world/images/logos/logo_pantheon.svg' />",
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ Flask-Assets==0.12
# SCSS compiler
Flask-Scss==0.5

# requests for server-side data fetch
requests==2.22.0

# Cache helper scripts
# selenium
# click
Expand Down

0 comments on commit 36ab727

Please sign in to comment.