Skip to content

Commit

Permalink
fix(failingreferences): check even more special cases
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rger committed Aug 22, 2024
1 parent 04a475e commit 66c8eff
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions apis_ontology/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
DATEPATTERN = re.compile(r"(?P<year>\d\d\d\d)-(?P<month>\d\d)-(?P<day>\d\d)")
FOLIOPATTERN = re.compile(r"^(?P<cleanfolio>\d{1,3}[r|v]).*$")
ROMANPATTERN = re.compile(r"^(?P<romanfirst>[C|X|L|I|V]{1,9})(?P<rectoverso>[r|v])")
PAGEPATTERN = re.compile(r"^(?P<page>\d{1,3}).*$")


@cache
Expand All @@ -24,6 +25,19 @@ def iiif_titles():

def get_folio(obj):
folio = obj.folio
# some references use pages
if page := obj.pages_start:
if page % 2 == 0:
# 7 (H) uses pages, but they files are named using recto/verso
if "7 (H)" in obj.bibtexjson["title"]:
return f"{page:03d}v-{page+1:03d}r"
else:
return f"{page:03d}-{page+1:03d}"
else:
if "7 (H)" in obj.bibtexjson["title"]:
return f"{page-1:03d}v-{page:03d}r"
else:
return f"{page-1:03d}-{page:03d}"
if obj.folio:
if match := ROMANPATTERN.match(obj.folio):
romanfirst = match["romanfirst"]
Expand All @@ -41,6 +55,14 @@ def get_folio(obj):
folio = f"{nr-1:03d}v-{nr:03d}r"
if cleanfolio.endswith("v"):
folio = f"{nr:03d}v-{nr+1:03d}r"
return folio
if match := PAGEPATTERN.match(obj.folio):
page = int(match["page"])
if page % 2 == 0:
folio = f"{page:03d}-{page+1:03d}"
else:
folio = f"{page-1:03d}-{page:03d}"
return folio
return folio


Expand Down

0 comments on commit 66c8eff

Please sign in to comment.