Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add author detail page
This replicates the view of the EOA1.5 platform with the important
exception that all information is directly queried from the
publications. There is no need to assign the author or editor a number
and use that for referencing.  Querying is done through first and last
name of author, applies even to the list of contributions which lists
authorship of chapters in other publications automatically.
  • Loading branch information
kthoden committed Aug 21, 2020
1 parent 2221eba commit 24cda9d
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 35 deletions.
15 changes: 7 additions & 8 deletions 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 %}

Expand Down Expand Up @@ -36,14 +37,12 @@ <h1>List of Publications</h1>
{% for Publication in Listofpublications %}
<div class="project-teaser">
<div class="project-teaser__image">
<a href="/{{ Publication.Serie }}/{{ Publication.Number }}/index.html"><img src="/media/{{Publication.Coversmall}}" data-object-fit="cover"/></a>
<a href="/{{ Publication.Serie }}/{{ Publication.Number }}/index.html"><img src="/static{{ Publication.Cover }}" data-object-fit="cover"/></a>
</div>
<div class="project-teaser-info">
<div class="project-teaser-info__category">{{ Publication.get_Serie_display }} {{ Publication.Number }}</div>
<h2 class="project-teaser-info__title">{{ Publication.Title|safe }}</h2>
{% if Publication.Descriptionshort %}
<div class="project-teaser-info__description">{{ Publication.Descriptionshort}}</div>
{% endif %}
<div class="project-teaser-info__category">{{ Publication.Serie|title }} {{ Publication.Number }}</div>
<h2 class="project-teaser-info__title">{{ Publication.Title|convert_tei }}</h2>
<div class="project-teaser-info__description">{{ Publication.Descriptionshort|convert_tei }}</div>
<div class="project-teaser-info__buttons"><a class="link" href="/{{ Publication.Serie }}/{{ Publication.Number }}/index.html"><span class="link__label">More</span></a>
</div>
</div>
Expand All @@ -59,8 +58,8 @@ <h1>Further Contributions</h1>
{% for Chapter in Listofchapters %}
<div class="project-teaser">
<div class="project-teaser-info">
<h2><a href="/{{ Chapter.Publication.Serie }}/{{ Chapter.Publication.Number }}/{{ Chapter.Order }}/index.html">{{ Chapter.Number }} {{ Chapter.Title|safe }}</a></h2>
<div class="project-teaser-info__description">In: <em>{{ Chapter.Publication.Title }}</em></div>
<h2><a href="/{{ Chapter.Partofpublication.Serie }}/{{ Chapter.Partofpublication.Number }}/{{ Chapter.Order }}/index.html">{{ Chapter.Number }} {{ Chapter.Longtitle|convert_tei }}</a></h2>
<div class="project-teaser-info__description">In: <em>{{ Chapter.Partofpublication.Title|convert_tei }}</em></div>
</div>
</div>
{% endfor %}
Expand Down
117 changes: 90 additions & 27 deletions 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
Expand All @@ -17,40 +91,29 @@ 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 = {
'Creators' : creators,
}
return render(request, 'eoaauthors2/index.html', Content)
# def index ends here


# def get_title():
# title = "well mann"

# return title

# index_template = f'''<!DOCTYPE html>
# <html>
# <head>
# <title>{ get_title() }</title>
# </head>
# <body>
# <h1>About { get_title() }</h1>
# <p>This Website was developed by { authorslug }.</p>
# </body>
# </html>
# '''

# return HttpResponse(index_template)

0 comments on commit 24cda9d

Please sign in to comment.