diff --git a/apis_ontology/management/commands/fetch_citation_from_zotero.py b/apis_ontology/management/commands/fetch_citation_from_zotero.py new file mode 100644 index 0000000..aba2cb2 --- /dev/null +++ b/apis_ontology/management/commands/fetch_citation_from_zotero.py @@ -0,0 +1,40 @@ +import json +import logging +import os + +import pandas as pd +import requests +from apis_ontology.models import ZoteroEntry +from django.core.management.base import BaseCommand +from tqdm.auto import tqdm + +USER = os.environ.get("APIS_BIBSONOMY_USER") +KEY = os.environ.get("APIS_BIBSONOMY_PASSWORD") +GROUP = "4394244" + + +QUERY_URL = f"https://api.zotero.org/groups/{GROUP}/items" +HEADERS = {"Authorization": f"Bearer {KEY}"} +PARAMS = { + "v": 3, + "format": "json", + # "itemKey": "Z5AUD7GQ,UJDXNMGD,KUYBGM7V,5DSBYG9K" +} + +logger = logging.getLogger(__name__) + +KEYS = ["Z5AUD7GQ", "UJDXNMGD", "KUYBGM7V", "5DSBYG9K"] + + +class Command(BaseCommand): + def handle(self, *args, **kwargs): + destination = "apis_ontology/static/citations.json" + citations = {} + for i, k in enumerate(KEYS): + res = requests.get(f"{QUERY_URL}/{k}", headers=HEADERS, params=PARAMS) + res.raise_for_status() + 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"Imported citations")) diff --git a/apis_ontology/static/citations.json b/apis_ontology/static/citations.json new file mode 100644 index 0000000..79e5d2b --- /dev/null +++ b/apis_ontology/static/citations.json @@ -0,0 +1 @@ +{"Set 1": {"key": "Z5AUD7GQ", "version": 1488, "library": {"type": "group", "id": 4394244, "name": "TibSchol", "links": {"alternate": {"href": "https://www.zotero.org/groups/tibschol", "type": "text/html"}}}, "links": {"self": {"href": "https://api.zotero.org/groups/4394244/items/Z5AUD7GQ", "type": "application/json"}, "alternate": {"href": "https://www.zotero.org/groups/tibschol/items/Z5AUD7GQ", "type": "text/html"}}, "meta": {"createdByUser": {"id": 8397006, "username": "PascaleHugon", "name": "", "links": {"alternate": {"href": "https://www.zotero.org/pascalehugon", "type": "text/html"}}}, "creatorSummary": "dpal brtsegs bod yig dpe rnying zhib 'jug khang", "parsedDate": "2006", "numChildren": 1}, "data": {"key": "Z5AUD7GQ", "version": 1488, "itemType": "book", "title": "bKa\u02bc gdams gsung \u02bcbum phyogs bsgrigs thengs dang po", "creators": [{"creatorType": "editor", "firstName": "", "lastName": "dpal brtsegs bod yig dpe rnying zhib 'jug khang"}], "abstractNote": "", "series": "", "seriesNumber": "", "volume": "1-30", "numberOfVolumes": "30", "edition": "", "place": "Khreng tu'u", "publisher": "Si khron mi rigs dpe skrun khang", "date": "2006", "numPages": "", "language": "tib", "ISBN": "978-7-5409-32-49-X", "shortTitle": "", "url": "", "accessDate": "", "archive": "", "archiveLocation": "", "libraryCatalog": "", "callNumber": "", "rights": "", "extra": "", "tags": [{"tag": "APIS"}], "collections": ["IEP4UFSV"], "relations": {"dc:relation": "http://zotero.org/groups/4394244/items/S8ND2M27"}, "dateAdded": "2023-09-26T09:30:46Z", "dateModified": "2023-09-26T09:30:59Z"}}, "Set 2": {"key": "UJDXNMGD", "version": 1587, "library": {"type": "group", "id": 4394244, "name": "TibSchol", "links": {"alternate": {"href": "https://www.zotero.org/groups/tibschol", "type": "text/html"}}}, "links": {"self": {"href": "https://api.zotero.org/groups/4394244/items/UJDXNMGD", "type": "application/json"}, "alternate": {"href": "https://www.zotero.org/groups/tibschol/items/UJDXNMGD", "type": "text/html"}}, "meta": {"createdByUser": {"id": 8397006, "username": "PascaleHugon", "name": "", "links": {"alternate": {"href": "https://www.zotero.org/pascalehugon", "type": "text/html"}}}, "creatorSummary": "dpal brtsegs bod yig dpe rnying zhib 'jug khang", "parsedDate": "2007", "numChildren": 0}, "data": {"key": "UJDXNMGD", "version": 1587, "itemType": "book", "title": "bKa\u02bc gdams gsung \u02bcbum phyogs bsgrigs thengs gnyis pa", "creators": [{"creatorType": "editor", "firstName": "", "lastName": "dpal brtsegs bod yig dpe rnying zhib 'jug khang"}], "abstractNote": "", "series": "", "seriesNumber": "", "volume": "31-60", "numberOfVolumes": "30", "edition": "", "place": "Khreng tu'u", "publisher": "Si khron mi rigs dpe skrun khang", "date": "2007", "numPages": "", "language": "tib", "ISBN": "978-7-5409-3431-6 978-7-5409-4283-0", "shortTitle": "", "url": "", "accessDate": "", "archive": "", "archiveLocation": "", "libraryCatalog": "K10plus ISBN", "callNumber": "", "rights": "", "extra": "", "tags": [{"tag": "APIS"}], "collections": ["IEP4UFSV"], "relations": {"dc:relation": "http://zotero.org/groups/4394244/items/AEAX7W8D"}, "dateAdded": "2023-09-26T09:30:46Z", "dateModified": "2023-09-26T09:31:03Z"}}, "Set 3": {"key": "KUYBGM7V", "version": 1453, "library": {"type": "group", "id": 4394244, "name": "TibSchol", "links": {"alternate": {"href": "https://www.zotero.org/groups/tibschol", "type": "text/html"}}}, "links": {"self": {"href": "https://api.zotero.org/groups/4394244/items/KUYBGM7V", "type": "application/json"}, "alternate": {"href": "https://www.zotero.org/groups/tibschol/items/KUYBGM7V", "type": "text/html"}}, "meta": {"createdByUser": {"id": 8397006, "username": "PascaleHugon", "name": "", "links": {"alternate": {"href": "https://www.zotero.org/pascalehugon", "type": "text/html"}}}, "creatorSummary": "dpal brtsegs bod yig dpe rnying zhib 'jug khang", "parsedDate": "2009", "numChildren": 0}, "data": {"key": "KUYBGM7V", "version": 1453, "itemType": "book", "title": "bKa\u02bc gdams gsung \u02bcbum phyogs bsgrigs thengs gsum pa", "creators": [{"creatorType": "editor", "firstName": "", "lastName": "dpal brtsegs bod yig dpe rnying zhib 'jug khang"}], "abstractNote": "", "series": "", "seriesNumber": "", "volume": "61-90", "numberOfVolumes": "30", "edition": "", "place": "Khreng tu'u", "publisher": "Si khron mi rigs dpe skrun khang", "date": "2009", "numPages": "", "language": "tib", "ISBN": "978-7-5409-4283-0", "shortTitle": "", "url": "", "accessDate": "", "archive": "", "archiveLocation": "", "libraryCatalog": "", "callNumber": "", "rights": "", "extra": "", "tags": [{"tag": "APIS"}], "collections": ["IEP4UFSV"], "relations": {}, "dateAdded": "2023-09-26T09:30:46Z", "dateModified": "2023-09-26T09:31:09Z"}}, "Set 4": {"key": "5DSBYG9K", "version": 1450, "library": {"type": "group", "id": 4394244, "name": "TibSchol", "links": {"alternate": {"href": "https://www.zotero.org/groups/tibschol", "type": "text/html"}}}, "links": {"self": {"href": "https://api.zotero.org/groups/4394244/items/5DSBYG9K", "type": "application/json"}, "alternate": {"href": "https://www.zotero.org/groups/tibschol/items/5DSBYG9K", "type": "text/html"}}, "meta": {"createdByUser": {"id": 8397006, "username": "PascaleHugon", "name": "", "links": {"alternate": {"href": "https://www.zotero.org/pascalehugon", "type": "text/html"}}}, "creatorSummary": "dpal brtsegs bod yig dpe rnying zhib 'jug khang", "parsedDate": "2015", "numChildren": 0}, "data": {"key": "5DSBYG9K", "version": 1450, "itemType": "book", "title": "bKa\u02bc gdams gsung \u02bcbum phyogs bsgrigs thengs bzhi pa", "creators": [{"creatorType": "editor", "firstName": "", "lastName": "dpal brtsegs bod yig dpe rnying zhib 'jug khang"}], "abstractNote": "", "series": "", "seriesNumber": "", "volume": "91-120", "numberOfVolumes": "30", "edition": "", "place": "Khreng tu'u", "publisher": "Si khron mi rigs dpe skrun khang", "date": "2015", "numPages": "", "language": "tib", "ISBN": "978-7-5409-6135-0", "shortTitle": "", "url": "", "accessDate": "", "archive": "", "archiveLocation": "", "libraryCatalog": "", "callNumber": "", "rights": "", "extra": "", "tags": [{"tag": "APIS"}], "collections": ["IEP4UFSV"], "relations": {}, "dateAdded": "2023-09-26T09:30:46Z", "dateModified": "2023-09-26T09:30:54Z"}}} \ No newline at end of file diff --git a/apis_ontology/templates/generic/partials/object_table.html b/apis_ontology/templates/generic/partials/object_table.html index 1b7092b..21b8a7d 100644 --- a/apis_ontology/templates/generic/partials/object_table.html +++ b/apis_ontology/templates/generic/partials/object_table.html @@ -1,11 +1,15 @@ {% load apisgeneric %} {% load filter_utils %} {% load parse_comment %} +{% load citation %} {% modeldict object as d %} + {% for key, value in d.items %} {% if not key|endswith:'.rootobject_ptr' %} + {% if value %} + + {% if key|endswith:'.pp_kdsb' %} + + + + + {% endif %} + {% endif %} {% endif %} {% endfor %}
{{ key.verbose_name | title}} @@ -27,6 +31,13 @@ {% endif %}
Citation{{object|cite}}
diff --git a/apis_ontology/templatetags/citation.py b/apis_ontology/templatetags/citation.py new file mode 100644 index 0000000..726a670 --- /dev/null +++ b/apis_ontology/templatetags/citation.py @@ -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"""{title}""" + return mark_safe( + f"""{link}, vol. {object.volume}, {creator} {constant} [{place}]: {publisher}, {date}, pp. {object.pp_kdsb}""" + )