diff --git a/src/eoaauthors2/templates/eoaauthors2/authordetail.html b/src/eoaauthors2/templates/eoaauthors2/authordetail.html
index 339b748..9b68513 100644
--- a/src/eoaauthors2/templates/eoaauthors2/authordetail.html
+++ b/src/eoaauthors2/templates/eoaauthors2/authordetail.html
@@ -1,4 +1,5 @@
{% extends "base.html" %}
+{% load convert_tei %}
{% block title %}{{ request.site.name }} | {% if Currentcreator.reverse_names %}{{ Currentcreator.authorlastname }} {{ Currentcreator.authorfirstname }}{% else %}{{ Currentcreator.authorfirstname }} {{ Currentcreator.authorlastname }}{% endif %}{% endblock %}
@@ -36,14 +37,12 @@
-

+
-
{{ Publication.get_Serie_display }} {{ Publication.Number }}
-
{{ Publication.Title|safe }}
- {% if Publication.Descriptionshort %}
-
{{ Publication.Descriptionshort}}
- {% endif %}
+
{{ Publication.Serie|title }} {{ Publication.Number }}
+
{{ Publication.Title|convert_tei }}
+
{{ Publication.Descriptionshort|convert_tei }}
@@ -59,8 +58,8 @@
Further Contributions
{% for Chapter in Listofchapters %}
-
-
In: {{ Chapter.Publication.Title }}
+
+
In: {{ Chapter.Partofpublication.Title|convert_tei }}
{% endfor %}
diff --git a/src/eoaauthors2/views.py b/src/eoaauthors2/views.py
index 2ff647e..1e8d658 100644
--- a/src/eoaauthors2/views.py
+++ b/src/eoaauthors2/views.py
@@ -1,14 +1,88 @@
from django.http import HttpResponse
from django.shortcuts import get_object_or_404, render
-from pyexistdb import db as pyedb
+from lxml import etree
from .models import Author
-# NSMAP = { "tei" : "http://www.tei-c.org/ns/1.0" }
+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
@@ -17,16 +91,25 @@ def author(request, authorslug):
ao = get_object_or_404(Author, slugfield=authorslug)
- Content = {'Currentcreator' : ao}
+ 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("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):
- # connection = pyedb.ExistDB()
- # series_query = connection.getDoc("xquery/series.xq").decode("utf-8")
- # translations = connection.getDoc("aux/translations.xml").decode("utf-8")
- # books = evaluate_xml(series_query, translations)
+ """View for the list of authors"""
creators = Author.objects.all().order_by('authorlastname')
Content = {
@@ -34,23 +117,3 @@ def index(request):
}
return render(request, 'eoaauthors2/index.html', Content)
# def index ends here
-
-
-# def get_title():
-# title = "well mann"
-
-# return title
-
- # index_template = f'''
- #
- #
- #
{ get_title() }
- #
- #
- #
About { get_title() }
- #
This Website was developed by { authorslug }.
- #
- #
- # '''
-
- # return HttpResponse(index_template)