Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
eoa2-xmldb/src/eoaseries2/views.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
69 lines (54 sloc)
2.79 KB
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
from django.http import HttpResponse | |
from django.shortcuts import get_object_or_404, render | |
from lxml import etree | |
import re | |
from .models import Series | |
from xsl import xsl_lib | |
from eoapublications2.views import Publication | |
from eoapublications2.views import Chapter | |
from eoapublications2.views import Author | |
NSMAP = { "tei" : "http://www.tei-c.org/ns/1.0" } | |
def evaluate_xml(series_query, translations): | |
"""Get data from XML""" | |
series_xml = etree.fromstring(series_query) | |
translation_xml = etree.fromstring(translations) | |
list_of_publications = list() | |
found_publications = series_xml.xpath("pub", namespaces = NSMAP) | |
for publication in found_publications: | |
list_of_creators = list() | |
book_series = publication.xpath("series", namespaces = NSMAP)[0].text.lower() | |
book_title = publication.xpath("title", namespaces = NSMAP)[0] | |
book_number = publication.xpath("number", namespaces = NSMAP)[0].text | |
book_cover = publication.xpath("coverpath", namespaces = NSMAP)[0].text | |
abstract_short = publication.xpath("abstract/tei:p", namespaces = NSMAP)[0] | |
mainlanguage = publication.xpath("mainlanguage", namespaces = NSMAP)[0].text | |
translated_and = translation_xml.xpath(f"/translations/entry[@name='and']/@{mainlanguage}")[0] | |
creators_element = publication.xpath("authors", namespaces = NSMAP)[0] | |
creator_type = creators_element.get("type") | |
creators = creators_element.xpath("author/fullname", namespaces = NSMAP) | |
for creator in creators: | |
creative_person = Author(creator.text) | |
list_of_creators.append(creative_person) | |
if creator_type == "editor": | |
if len(creators) == 1: | |
editor_suffix = translation_xml.xpath(f"/translations/entry[@name='editor-abbr']/@{mainlanguage}")[0] | |
else: | |
editor_suffix = translation_xml.xpath(f"/translations/entry[@name='editors-abbr']/@{mainlanguage}")[0] | |
else: | |
editor_suffix = None | |
book = Publication(book_title, book_series, book_number, book_cover, abstract_short, mainlanguage, list_of_creators, editor_suffix, translated_and) | |
list_of_publications.append(book) | |
return list_of_publications | |
# def evaluate_xml ends here | |
def index(request): | |
"""Return the publications overview""" | |
series_query = xsl_lib.get_document("apps/eoa/xml/xquery/series.xq").decode("utf-8") | |
translations = xsl_lib.get_document("apps/eoa/xml/aux/translations.xml").decode("utf-8") | |
books = evaluate_xml(series_query, translations) | |
registered_series = Series.objects.all().order_by('name') | |
Content = { | |
'Listofpublications' : books, | |
'Series' : sorted(registered_series), | |
} | |
return render(request, 'eoaseries2/index.html', Content) | |
# def index ends here |