Pārlūkot izejas kodu

added 'country' to random and search

solr_update
Simon Bowie pirms 2 gadiem
vecāks
revīzija
79c10532be
3 mainītis faili ar 26 papildinājumiem un 0 dzēšanām
  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 Parādīt failu

@@ -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 Parādīt failu

@@ -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 Parādīt failu

@@ -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>

Notiek ielāde…
Atcelt
Saglabāt