Explorar el Código

added 'country' to random and search

solr_update
Simon Bowie hace 2 años
padre
commit
79c10532be
Se han modificado 3 ficheros con 26 adiciones y 0 borrados
  1. +10
    -0
      web/app/solr.py
  2. +8
    -0
      web/app/templates/record.html
  3. +8
    -0
      web/app/templates/search.html

+ 10
- 0
web/app/solr.py Ver fichero

@@ -10,6 +10,7 @@ import requests
import re
import urllib
import random
import pycountry
from . import ops

# get config variables from OS environment variables: set in env file passed through Docker Compose
@@ -93,6 +94,15 @@ def parse_result(id, input):
year = re.search('=D[^\s]*\s[^\s]*\s[^\s]*\s[^\s]*\s(\d{4})', input)
if year is not None:
output['year'] = year.group(1)

# search for the country in the content element and display it
country_code = re.search('FT=D[^\s]*\s(\w{2})', input)
country = pycountry.countries.get(alpha_2=country_code.group(1))
if country is None:
country = pycountry.historic_countries.get(alpha_2=country_code.group(1))
if country is not None:
output['country'] = country

return output

def get_random_record(core):

+ 8
- 0
web/app/templates/record.html Ver fichero

@@ -25,6 +25,14 @@
</p>
{% endif %}

{% if result['country'] is defined %}
<p class="mb-2">
Country:
{{ result['country'].name }}
{{ result['country'].flag }}
</p>
{% endif %}

{% if result['original_title'] is defined %}
<p class="mb-2">
Original language title:

+ 8
- 0
web/app/templates/search.html Ver fichero

@@ -51,6 +51,14 @@
</p>
{% endif %}

{% if result['country'] is defined %}
<p class="mb-2">
<span class="emphasis">Country:</span>
{{ result['country'].name }}
{{ result['country'].flag }}
</p>
{% endif %}

{% if result['abstract'] is defined %}
<p class="mb-2">
<span class="emphasis">Abstract:</span>

Cargando…
Cancelar
Guardar