Skip to content

Commit

Permalink
Merge pull request #76 from acdh-oeaw/commentary-author
Browse files Browse the repository at this point in the history
Show author of object
  • Loading branch information
gythaogg authored Jun 20, 2024
2 parents 48c0ba7 + 8d225a8 commit 4ef8588
Showing 1 changed file with 40 additions and 11 deletions.
51 changes: 40 additions & 11 deletions apis_ontology/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,21 +215,27 @@ def __init__(self, *args, **kwargs):
self.transform = etree.XSLT(xslt)

def render_name(self, record):
if self.context["object"].pk == record.subj.pk:
return record.name
elif self.context["object"].pk == record.obj.pk:
return record.reverse_name
else:
return ""
rel_name = record.name
try:
if self.context["object"].pk == record.obj.pk:
rel_name = record.reverse_name
except Exception as e:
logger.error("Bad relation %s\Error: %s", record, repr(e))

return rel_name

def render_obj(self, record):
# return str(record) + str(self.context["object"].pk)
if self.context["object"].pk == record.obj.pk:
# return str(RootObject.objects_inheritance.get_subclass(pk=record.subj.pk))
actual_obj = RootObject.objects_inheritance.get_subclass(pk=record.subj.pk)
actual_obj = RootObject.objects_inheritance.get_subclass(pk=record.obj.pk)

else:
actual_obj = RootObject.objects_inheritance.get_subclass(pk=record.obj.pk)
try:
if self.context["object"].pk == record.obj.pk:
# return str(RootObject.objects_inheritance.get_subclass(pk=record.subj.pk))
actual_obj = RootObject.objects_inheritance.get_subclass(
pk=record.subj.pk
)
except Exception as e:
logger.error("Bad relation %s\Error: %s", record, repr(e))

return mark_safe(
"<a href='"
Expand Down Expand Up @@ -280,3 +286,26 @@ class Meta(GenericTable.Meta):
"tei_refs",
]
exclude = ["view", "edit", "desc", "delete", "subj"]


class WorkCommentaryOnWorkTable(TibScholRelationMixinTable):
class Meta(TibScholRelationMixinTable.Meta):
fields = [
"subj",
"obj",
"commentary_author",
"edit",
"delete",
]

subj = tables.Column()
obj = tables.Column()
commentary_author = tables.Column(
verbose_name="Author (obj)", orderable=True, accessor="obj"
)

def render_commentary_author(self, value):
obj_work = Work.objects.get(pk=value.pk)
if obj_work.author_id:
return f"{obj_work.author_name} ({obj_work.author_id})"
return ""

0 comments on commit 4ef8588

Please sign in to comment.