Skip to content

Commit

Permalink
Move central information parts to new app eoapublictions2
Browse files Browse the repository at this point in the history
  • Loading branch information
kthoden committed Aug 21, 2020
1 parent 353473a commit 2221eba
Show file tree
Hide file tree
Showing 10 changed files with 257 additions and 39 deletions.
4 changes: 4 additions & 0 deletions src/eoaauthors2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
from .models import Author

# NSMAP = { "tei" : "http://www.tei-c.org/ns/1.0" }
from eoapublications2.views import Publication
from eoapublications2.views import Chapter
from eoapublications2 import xquery_templates


def author(request, authorslug):
"""View for detail page of an author
Expand Down
Empty file.
3 changes: 3 additions & 0 deletions src/eoapublications2/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions src/eoapublications2/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class Eoapublications2Config(AppConfig):
name = 'eoapublications2'
Empty file.
3 changes: 3 additions & 0 deletions src/eoapublications2/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
3 changes: 3 additions & 0 deletions src/eoapublications2/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
58 changes: 58 additions & 0 deletions src/eoapublications2/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from django.shortcuts import render
from django.template.defaultfilters import slugify

# Create your views here.

class Publication():
"Publication class"

def __init__(self, title, serie, number, coverpath, abstract_short, mainlanguage, creators, creator_suffix, translated_and):
self.Title = title
self.Serie = serie
self.Number = number
self.Cover = coverpath
self.Descriptionshort = abstract_short
self.Mainlanguage = mainlanguage
self.Creators = creators
self.Creatorsuffix = creator_suffix
self.Conjunction = translated_and
# def __init__ ends here


def __str__(self):
return self.Title
# def __str__ ends here
# class Publication ends here


class Chapter():
"Chapter class"

def __init__(self, long_title, short_title, abstract, mainlanguage, creators, order, appears_in):
self.Longtitle = long_title
self.Shorttitle = short_title
self.Mainlanguage = mainlanguage
self.Order = order
self.Creators = creators
self.Chapterabstract = abstract
self.Partofpublication = appears_in
# def __init__ ends here

def __str__(self):
return self.Longtitle
# def __str__ ends here
# class Chapter ends here


class Author():
"Author class"

def __init__(self, name):
self.Name = name
self.Sortname = slugify(name)
# def __init__ ends here

def __str__(self):
return self.Name
# def __str__ ends here
# class Author ends here
178 changes: 178 additions & 0 deletions src/eoapublications2/xquery_templates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
def author_is_creator_of_which_publications(firstname, lastname):
"""Building a personalized xquery string
For debugging purposes, this is authorpublication.xq
"""

pubquiz_string = """
xquery version "3.1";
declare namespace tei = "http://www.tei-c.org/ns/1.0";
<publications>
{
let $firstname := '%s'
let $lastname := '%s'
for $book in collection('/db/xml_files/publications')
let $authorid :=
concat('#',
$book//tei:respStmt/tei:persName[./tei:forename = $firstname and ./tei:surname = $lastname]/../@xml:id)
let $series := $book//tei:seriesStmt/tei:title/text()
let $number := xs:int($book//tei:seriesStmt/tei:idno/text())
let $abstract := $book//tei:profileDesc/tei:abstract[@n = 'brief']/tei:p
let $title := $book//tei:titleStmt/tei:title[@type = 'main']/node()
let $coverimage := $book//tei:text/tei:front/tei:figure[@type = 'cover']/tei:graphic/@url
return
<pub>{
if ($book//tei:fileDesc/tei:titleStmt/(tei:editor[@role = 'volumeeditor'] | tei:author)/@ref = $authorid)
then (
<title>{$title}</title>,
<series>{$series}</series>,
<number>{$number}</number>,
<abstract>{$abstract}</abstract>,
<coverpath>{ concat("/", lower-case($series), "/", $number, "/", $coverimage) }</coverpath>
)
else
""
}
</pub>
}
</publications>
""" % (firstname, lastname)

return pubquiz_string
# def author_is_creator_of_which_publications ends here


def author_is_creator_of_which_chapters(firstname, lastname):
"""Return all chapters with author involved.
For debugging purposes, this is chapterauthor.xq
"""

pubquiz_string = """
xquery version "3.1";
declare namespace tei = "http://www.tei-c.org/ns/1.0";
<publications>
{
let $firstname := '%s'
let $lastname := '%s'
for $book in collection('/db/xml_files/publications')
let $authorid :=
$book//tei:respStmt/tei:persName[./tei:forename = $firstname and ./tei:surname = $lastname]/../@xml:id
let $series := $book//tei:seriesStmt/tei:title/text()
let $number := xs:int($book//tei:seriesStmt/tei:idno/text())
let $title := $book//tei:titleStmt/tei:title[@type = 'main']/node()
let $chapter := $book//tei:text//tei:div[@type = 'chapter']
for $bit in $chapter
let $chaptertitle := $bit/tei:head/node()
let $chapterlanguage := xs:string($bit/@xml:lang)
let $chapterabstract := $bit/ab[@type='chapterabstract']
let $resp := xs:string($bit/@resp)
let $resplist := tokenize($resp, " ")
return
<pub>{
if ($resplist = concat('#', $authorid)) then
(<title>{ $chaptertitle }</title>, <booktitle>{ $title }</booktitle>, <series>{ $series }</series>,
<number>{ $number }</number>, <order>{ index-of($chapter, $bit) }</order>, <chapterlanguage>{$chapterlanguage}</chapterlanguage>, <chapterabstract>{$chapterabstract}</chapterabstract>,<creators>{$resplist}</creators>)
else
""
}
</pub>
}
</publications>
""" % (firstname, lastname)

return pubquiz_string
# def author_is_creator_of_which_chapters ends here


def author_is_creator_of_which_other_chapters(firstname, lastname):
"""Return all chapters with author involved except where she or he is
author or volume editor.
For debugging purposes, this is chapterauthor_notinownbook.xq
"""

pubquiz_string = """
xquery version "3.1";
declare namespace tei = "http://www.tei-c.org/ns/1.0";
<chapters>
{
let $firstname := '%s'
let $lastname := '%s'
for $book in collection('/db/xml_files/publications')
let $authorid :=
$book//tei:respStmt/tei:persName[./tei:forename = $firstname and ./tei:surname = $lastname]/../@xml:id
let $authorrefs := $book//tei:fileDesc/tei:titleStmt/(tei:editor[@role = 'volumeeditor'] | tei:author)/@ref
let $listofcreators := string-join($authorrefs, " ")
let $series := $book//tei:seriesStmt/tei:title/text()
let $number := xs:int($book//tei:seriesStmt/tei:idno/text())
let $title := $book//tei:titleStmt/tei:title[@type = 'main']/node()
let $chapter := $book//tei:text//tei:div[@type = 'chapter']
for $bit in $chapter
let $chaptertitle := $bit/tei:head/node()
let $chapterlanguage := xs:string($bit/@xml:lang)
let $chapterabstract := $bit/ab[@type = 'chapterabstract']
let $resp := xs:string($bit/@resp)
let $resplist := tokenize($resp, " ")
return
<chapter>
{
if (empty($authorid)) then
""
else
(if (tokenize($listofcreators, " ") = '#' || $authorid) then
("")
else
(if ($resplist = concat('#', $authorid)) then
(<title>{ $chaptertitle }</title>, <booktitle>{ $title }</booktitle>,
<series>{ $series }</series>,
<number>{ $number }</number>, <order>{ index-of($chapter, $bit) }</order>,
<chapterlanguage>{ $chapterlanguage }</chapterlanguage>, <chapterabstract>{ $chapterabstract }</chapterabstract>,
<authors>
{
for $pp in $resplist
let $localname := xs:string($book/*//tei:respStmt[@xml:id = substring-after($pp, "#")]/tei:persName/@xml:lang)
let $inbookid := xs:string($book/*//tei:respStmt[@xml:id = substring-after($pp, "#")]/@xml:id)
let $firstname :=
$book/*//tei:respStmt[@xml:id = substring-after($pp,
"#")]/tei:persName/tei:forename/node()
let $lastname :=
$book/*//tei:respStmt[@xml:id = substring-after($pp,
"#")]/tei:persName/tei:surname/node()
return
<author><fullname>{
if ($localname = "zh") then
(concat($lastname, ' ', $firstname))
else
(concat($firstname, ' ', $lastname))
}</fullname>
<firstname>{ $firstname }</firstname>
<lastname>{ $lastname }</lastname>
<inbookid>{ $inbookid }</inbookid>
</author>
}
</authors>)
else
""
)
)
}
</chapter>
}
</chapters>
""" % (firstname, lastname)

return pubquiz_string
# def author_is_creator_of_which_other_chapters ends here
42 changes: 3 additions & 39 deletions src/eoaseries2/views.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,15 @@
from django.http import HttpResponse
from django.shortcuts import get_object_or_404, render
from django.template.defaultfilters import slugify
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" }

class Author():
"Author class"

def __init__(self, name):
self.Name = name
self.Sortname = slugify(name)
# def __init__ ends here

def __str__(self):
return self.Name
# def __str__ ends here

pass
# class Author ends here


class Publication():
"Publication class"

def __init__(self, title, serie, number, coverpath, abstract_short, mainlanguage, creators, creator_suffix, translated_and):
self.Title = title
self.Serie = serie
self.Number = number
self.Cover = coverpath
self.Descriptionshort = abstract_short
self.Mainlanguage = mainlanguage
self.Creators = creators
self.Creatorsuffix = creator_suffix
self.Conjunction = translated_and
# def __init__ ends here


def __str__(self):
return self.Title
# def __str__ ends here
# class Publication ends here


def evaluate_xml(series_query, translations):
"""Get data from XML"""

Expand Down

0 comments on commit 2221eba

Please sign in to comment.