Skip to content

Commit

Permalink
Merge pull request #22 from acdh-oeaw/feature/linked-comments
Browse files Browse the repository at this point in the history
Feature/linked comments
  • Loading branch information
gythaogg authored May 16, 2024
2 parents df99d3e + 1565d3c commit c3b875f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 4 additions & 2 deletions apis_ontology/management/commands/fetch_zotero_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,20 @@ def handle(self, *args, **kwargs):
res = requests.get(QUERY_URL, headers=HEADERS, params=PARAMS)
res.raise_for_status()
num_records = res.headers["Total-Results"]

print(f"Found {len(num_records)} records")
all_items = []
for start in tqdm(range(0, int(num_records), 25)):
PARAMS["start"] = start
res = requests.get(QUERY_URL, headers=HEADERS, params=PARAMS)

res.raise_for_status()
items = res.json()
print(f"Fetched {len(items)}.")
all_items.extend(items)

df = pd.json_normalize(all_items)

print(f"Fetched {df.shape[0]} items in total")
print(f"... of which there are {len(df['data.key'].unique())} are unique keys.")
for i, row in tqdm(df.iterrows(), total=df.shape[0]):
if "apis" in [tag["tag"].lower() for tag in row["data.tags"]]:
zotero_entry, _ = ZoteroEntry.objects.get_or_create(
Expand Down
8 changes: 6 additions & 2 deletions apis_ontology/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
from django_tables2.utils import A

from .models import Instance, Person, Place, TibScholRelationMixin, Work
from .templatetags.filter_utils import render_coordinate, render_links
from .templatetags.filter_utils import (
render_coordinate,
render_links,
render_list_field,
)
from .templatetags.parse_comment import parse_comment

import django_tables2 as tables
Expand Down Expand Up @@ -118,7 +122,7 @@ def render_support_notes(self, value):
return mark_safe(parse_comment(value))

def render_zotero_refs(self, value):
return mark_safe(parse_comment(value))
return mark_safe(parse_comment(render_list_field(value)))

def render_obj(self, record):
# return str(record) + str(self.context["object"].pk)
Expand Down
6 changes: 4 additions & 2 deletions apis_ontology/templatetags/parse_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ def custom_replace(match):
try:
root_obj = RootObject.objects_inheritance.get_subclass(pk=entity_id)
ct = ContentType.objects.get_for_model(root_obj)
return f'<a target="_BLANK" href="/apis/apis_ontology.{ct.name}/{root_obj.pk}">{entity_id}</a>'
return f'<a target="_BLANK" href="/apis/apis_ontology.{ct.name}/{root_obj.pk}">({entity_id})</a>'

except Exception as e:
logger.error("Error finding entity #%s", entity_id)
logger.error(repr(e))
return f'<a target="_BLANK" href="/entity/{entity_id}">{entity_id}</a>'
return (
f'<a target="_BLANK" href="/entity/{entity_id}">({entity_id})</a>'
)
else:
# If no specific group is matched, return the original match
replacement = match.group(0)
Expand Down

0 comments on commit c3b875f

Please sign in to comment.