Skip to content

Commit

Permalink
Add citation line after pagenumber
Browse files Browse the repository at this point in the history
  • Loading branch information
gythaogg committed May 21, 2024
1 parent a8d5f13 commit e9ff6f8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
10 changes: 5 additions & 5 deletions apis_ontology/management/commands/fetch_citation_from_zotero.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
GROUP = "4394244"


QUERY_URL = f"https://api.zotero.org/groups/{GROUP}/items/"
QUERY_URL = f"https://api.zotero.org/groups/{GROUP}/items"
HEADERS = {"Authorization": f"Bearer {KEY}"}
PARAMS = {
"v": 3,
Expand All @@ -30,11 +30,11 @@ class Command(BaseCommand):
def handle(self, *args, **kwargs):
destination = "apis_ontology/static/citations.json"
citations = {}
for k in KEYS:
res = requests.get(QUERY_URL, headers=HEADERS, params=PARAMS)
for i, k in enumerate(KEYS):
res = requests.get(f"{QUERY_URL}/{k}", headers=HEADERS, params=PARAMS)
res.raise_for_status()
citations[k] = res.json()
citations[f"Set {i + 1}"] = res.json()

with open(destination, "w") as f:
f.write(json.dumps(citations))
self.stdout.write(self.style.SUCCESS(f"Processed {df.shape[0]} excerpts."))
self.stdout.write(self.style.SUCCESS(f"Imported citations"))
2 changes: 1 addition & 1 deletion apis_ontology/static/citations.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions apis_ontology/templates/generic/partials/object_table.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{% load apisgeneric %}
{% load filter_utils %}
{% load parse_comment %}
{% load citation %}

<table class="table table-hover">
{% modeldict object as d %}

{% for key, value in d.items %}
{% if not key|endswith:'.rootobject_ptr' %}
{% if value %}
Expand All @@ -29,6 +31,12 @@
{% endif %}
</td>
</tr>
{% if key|endswith:'.pp_kdsb' %}
<tr>
<th> Citation</th>
<td>{{object|cite}}</td>
</tr>
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
Expand Down
31 changes: 31 additions & 0 deletions apis_ontology/templatetags/citation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import json
import logging
from django import template
from django.utils.safestring import mark_safe

register = template.Library()

logger = logging.getLogger(__name__)


with open("apis_ontology/static/citations.json", "r") as f:
citations = json.loads(f.read())


@register.filter
def cite(object):
print(object.set_num, object.pp_kdsb, object.volume)
print(citations[object.set_num])
zotero_info = citations[object.set_num]

title = zotero_info["data"]["title"]
key = zotero_info["key"]
creator = zotero_info["data"]["creators"][0]["lastName"]
constant = "[dPe sgrig 'gan 'khur ba: dByang can lha mo et al.], Chengdu"
place = zotero_info["data"]["place"]
publisher = zotero_info["data"]["publisher"]
date = zotero_info["data"]["date"]
link = f"""<a target="_BLANK" href="https://www.zotero.org/groups/4394244/tibschol/items/{key}/item-details#">{title}</a>"""
return mark_safe(
f"""{link}, vol. {object.volume}, {creator} {constant} [{place}]: {publisher}, {date}, pp. {object.pp_kdsb}"""
)

0 comments on commit e9ff6f8

Please sign in to comment.