Skip to content

Commit

Permalink
Merge pull request #43 from acdh-oeaw/person-detail
Browse files Browse the repository at this point in the history
Person detail
  • Loading branch information
gythaogg authored Jun 4, 2024
2 parents 00d2196 + 77f19e8 commit f9c8ae6
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 27 deletions.
34 changes: 33 additions & 1 deletion apis_ontology/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
AbstractEntityFilterSet,
ABSTRACT_ENTITY_FILTERS_EXCLUDE,
)
from apis_ontology.forms import PlaceSearchForm
from apis_ontology.forms import PersonSearchForm, PlaceSearchForm
from django.db import models
import django_filters

Expand Down Expand Up @@ -91,3 +91,35 @@ def custom_name_search(self, queryset, name, value):
models.Q(label__icontains=value)
| models.Q(alternative_names__icontains=value)
)


class PersonFilterSet(TibScholEntityMixinFilterSet):
class Meta:
exclude = [
*ABSTRACT_ENTITY_FILTERS_EXCLUDE,
"notes",
"alternative_names",
]
form = PersonSearchForm
filter_overrides = {
models.CharField: {
"filter_class": django_filters.CharFilter,
"extra": lambda f: {
"lookup_expr": "icontains",
},
},
models.TextField: {
"filter_class": django_filters.CharFilter,
"extra": lambda f: {
"lookup_expr": "icontains",
},
},
}

name = django_filters.CharFilter(method="custom_name_search")

def custom_name_search(self, queryset, name, value):
return queryset.filter(
models.Q(name__icontains=value)
| models.Q(alternative_names__icontains=value)
)
14 changes: 14 additions & 0 deletions apis_ontology/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,17 @@ class PlaceSearchForm(GenericFilterSetForm):
"notes",
"external_links",
]


class PersonSearchForm(GenericFilterSetForm):
field_order = [
"columns",
"name",
"start_date_written",
"end_date_written",
"gender",
"nationality",
"comments",
"notes",
"external_links",
]
3 changes: 3 additions & 0 deletions apis_ontology/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class Meta:
def render_external_links(self, value):
return render_links(value)

def render_alternative_names(self, value):
return render_list_field(value)


class WorkTable(AbstractEntityTable):
class Meta:
Expand Down
89 changes: 63 additions & 26 deletions apis_ontology/templates/generic/partials/person_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,77 @@
{% 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 %}

<tr>
<th>
{{ key.verbose_name | title}}
Name
</th>
<td>
{{ object.name }}
</td>
</tr>
<tr>
<th>
Alternative names
</th>
<td>
{{ object.alternative_names | render_list_field }}
</td>
</tr>
<tr>
<th>
Life date start
</th>
<td>
{% if object.start_date_written %}
{{ object.start_date_written }}
{% else %}
Unknown
{% endif %}
</td>
</tr>
<tr>
<th>
Life date end
</th>

<td>
{% if key|endswith:'.comments' %}
{{ value | parse_comment | safe}}
{% elif key|endswith:'.external_links' %}
{{ value | render_links | safe}}
{% elif key|endswith:'.longitude' %}
{{ value | render_coordinate}}
{% elif key|endswith:'.latitude' %}
{{ value | render_coordinate}}
{% elif key|endswith:'.zotero_ref' %}
{{ value | render_zotero_links | safe}}
{% if object.end_date_written %}
{{ object.end_date_written }}
{% else %}
{{ value | render_list_field}}
Unknown
{% endif %}
</td>
</tr>
{% if key|endswith:'.pp_kdsb' %}
<tr>
<th> Citation</th>
<td>{{object|cite}}</td>
<th>
Gender
</th>
<td>
{{object.gender}}
</td>
</tr>

<tr>
<th>
Nationality
</th>
<td>
{{object.nationality}}
</td>
</tr>
<tr>
<th>
Comments
</th>
<td>
{{ object.comments | render_list_field }}
</td>
</tr>
<tr>
<th>
External links
</th>
<td>
{{ object.external_links | render_links | safe }}
</td>
</tr>
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
</table>

0 comments on commit f9c8ae6

Please sign in to comment.