Skip to content

Commit

Permalink
refactor(templates): restructure templates
Browse files Browse the repository at this point in the history
use inheritance and inclusion
  • Loading branch information
b1rger committed Jan 13, 2025
1 parent b7bfb70 commit 29f21a0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pfp_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def root():

@app.get("/persons")
def persons(query_parameters: Annotated[PersonParams, Query()]) -> Page[Person]:
template = env.get_template("persons.j2")
template = env.get_template("persons.rq")
adapter = SPARQLModelAdapter(
target="https://pfp-ts-backend.acdh-ch-dev.oeaw.ac.at/",
query=template.render(dict(query_parameters)),
Expand All @@ -36,7 +36,7 @@ def persons(query_parameters: Annotated[PersonParams, Query()]) -> Page[Person]:

@app.get("/person/{person_id}")
def person(person_id: str):
template = env.get_template("person.j2")
template = env.get_template("person.rq")
try:
person_id = urlsafe_b64decode(person_id).decode()
except binascii.Error:
Expand Down
3 changes: 3 additions & 0 deletions pfp_api/templates/base.rq
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% include "partials/prefixes.rq" %}
{% block query %}
{% endblock query %}
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX pfp: <https://www.oeaw.ac.at/acdh/pfp/>
SELECT ?subject
WHERE {
?subject pfp:proxy_for <{{ person_id }}> .
}
7 changes: 7 additions & 0 deletions pfp_api/templates/person.rq
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "base.rq" %}
{% block query %}
SELECT ?subject
WHERE {
?subject pfp:proxy_for <{{ person_id }}> .
}
{% endblock query %}
5 changes: 3 additions & 2 deletions pfp_api/templates/persons.j2 → pfp_api/templates/persons.rq
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
{% extends "base.rq" %}
{% block query %}
SELECT ?person ?label ?graph
WHERE {
GRAPH ?graph {
Expand All @@ -10,3 +10,4 @@ WHERE {
{% endif %}
}
}
{% endblock query %}

0 comments on commit 29f21a0

Please sign in to comment.