Skip to content
Permalink
c2f21bcaef
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
119 lines (82 sloc) 4.52 KB
from django.http import HttpResponse
from django.shortcuts import get_object_or_404, render
from lxml import etree
from .models import Author
from xsl import xsl_lib
from eoapublications2.views import Publication
from eoapublications2.views import Chapter
from eoapublications2 import xquery_templates
NSMAP = { "tei" : "http://www.tei-c.org/ns/1.0",
"xml" : "http://www.w3.org/XML/1998/namespace"}
def evaluate_publications_xml(query_result):
"""Create list of publications"""
list_of_publications = list()
pubinfo = etree.fromstring(query_result)
publications = pubinfo.xpath(f"//pub[*]", namespaces = NSMAP)
for publication in publications:
book_series = publication.xpath("series", namespaces = NSMAP)[0].text.lower()
book_number = publication.xpath("number", namespaces = NSMAP)[0].text
book_title = publication.xpath("title", namespaces = NSMAP)[0]
book_cover = publication.xpath("coverpath", namespaces = NSMAP)[0].text
abstract_short = publication.xpath("abstract/tei:p", namespaces = NSMAP)[0]
book = Publication(book_title, book_series, book_number, book_cover, abstract_short, None, None, None, None)
list_of_publications.append(book)
return list_of_publications
# def evaluate_publications_xml ends here
def evaluate_chapters_xml(query_result, list_of_publications):
"""Create list of chapters"""
def get_chapter_title(title_element):
"""Get long and short version of chapter title
There might be only one version, without choice element"""
title_children = title_element.getchildren()
if title_children and title_children[0].tag == f"{{{NSMAP['tei']}}}choice":
choice_tag = title_children[0]
longtitle = choice_tag.xpath("tei:expan", namespaces = NSMAP)[0]
shorttitle = choice_tag.xpath("tei:abbr", namespaces = NSMAP)[0]
else:
longtitle = shorttitle = title_element
return longtitle, shorttitle
# def get_chapter_title ends here
list_of_chapters = list()
pubinfo = etree.fromstring(query_result)
chapters = pubinfo.xpath(f"//chapter[*]", namespaces = NSMAP)
for chapter in chapters:
creators = chapter.xpath("authors", namespaces = NSMAP)[0].text
chapterlanguage = chapter.xpath("chapterlanguage", namespaces = NSMAP)[0].text
order = chapter.xpath("order", namespaces = NSMAP)[0].text
series = chapter.xpath("series", namespaces = NSMAP)[0].text
number = chapter.xpath("number", namespaces = NSMAP)[0].text
abstract = chapter.xpath("chapterabstract", namespaces = NSMAP)[0]
long_title, short_title = get_chapter_title(chapter.xpath("title", namespaces = NSMAP)[0])
appears_in = None
for publication in list_of_publications:
if publication.Serie == series.lower() and publication.Number == number:
appears_in = publication
chapter = Chapter(long_title, short_title, None, None, None, order, appears_in)
list_of_chapters.append(chapter)
return list_of_chapters
# def evaluate_chapters_xml ends here
def author(request, authorslug):
"""View for detail page of an author
Return an error if author is not in database"""
ao = get_object_or_404(Author, slugfield=authorslug)
xquery_string_publications = xquery_templates.author_is_creator_of_which_publications(ao.authorfirstname, ao.authorlastname)
pubs = xsl_lib.xquery(xquery_string_publications).data.decode("utf-8")
publications_with_current_author = evaluate_publications_xml(pubs)
# Removing chapters that are part of above publications!
all_publications_query = xsl_lib.get_document("apps/eoa/xml/xquery/allpublications.xq").decode("utf-8")
all_publications = evaluate_publications_xml(all_publications_query)
xquery_string_chapters = xquery_templates.author_is_creator_of_which_other_chapters(ao.authorfirstname, ao.authorlastname)
chaps = xsl_lib.xquery(xquery_string_chapters).data.decode("utf-8")
chapters = evaluate_chapters_xml(chaps, all_publications)
Content = {'Currentcreator' : ao, 'Listofpublications' : publications_with_current_author, 'Listofchapters' : chapters}
return render(request, 'eoaauthors2/authordetail.html', Content)
# def author ends here
def index(request):
"""View for the list of authors"""
creators = Author.objects.all().order_by('authorlastname')
Content = {
'Creators' : creators,
}
return render(request, 'eoaauthors2/index.html', Content)
# def index ends here