Skip to content

Commit

Permalink
making bib section view use related model + aligning templates with this
Browse files Browse the repository at this point in the history
  • Loading branch information
acholyn committed Dec 18, 2024
1 parent f7a6f93 commit f2e584b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/rard/research/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
path(
"<pk>/bibliography/",
views.BibliographySectionView.as_view(),
{"related_model": "antiquarian"},
name="bibliography",
),
path(
Expand Down Expand Up @@ -662,6 +663,7 @@
path(
"<pk>/bibliography/",
views.BibliographySectionView.as_view(),
{"related_model": "citing_author"},
name="bibliography",
),
path(
Expand Down
30 changes: 21 additions & 9 deletions src/rard/research/views/bibliography.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from rard.research.forms import BibliographyItemForm, BibliographyItemInlineForm
from rard.research.models import Antiquarian, BibliographyItem
from rard.research.models.citing_work import CitingAuthor
from rard.research.views.mixins import CanLockMixin, CheckLockMixin


Expand Down Expand Up @@ -159,23 +160,34 @@ class BibliographyDeleteView(

class BibliographySectionView(LoginRequiredMixin, PermissionRequiredMixin, ListView):
model = BibliographyItem
template_name = "research/partials/antiquarian_bibliography_list.html"
context_object_name = "bibliography_items"
permission_required = ("research.view_bibliographyitem",)

# todo: update this to dynamically work with authors and ants
def get_queryset(self) -> QuerySet[Any]:
if self.model is not None:
queryset = self.model._default_manager.all()
self.ant_pk = self.kwargs.get("pk")
if self.ant_pk:
queryset = queryset.filter(antiquarians__id=self.ant_pk)
self.owner_pk = self.kwargs.get("pk")
related_model = self.kwargs.get("related_model")
if self.owner_pk:
# use related_model to determine which model to filter on
if related_model == "antiquarian":
queryset = queryset.filter(antiquarians__id=self.owner_pk)
elif related_model == "citing_author":
queryset = queryset.filter(citing_authors__id=self.owner_pk)
return queryset

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
if self.ant_pk:
context["antiquarian"] = Antiquarian.objects.get(id=self.ant_pk)
if self.ant_pk:
context["antiquarian"] = Antiquarian.objects.get(id=self.ant_pk)
related_model = self.kwargs.get("related_model")

if self.owner_pk:
if related_model == "antiquarian":
context["antiquarian"] = Antiquarian.objects.get(id=self.owner_pk)
elif related_model == "citing_author":
context["citingauthor"] = CitingAuthor.objects.get(id=self.owner_pk)
return context

def get_template_names(self):
related_model = self.kwargs.get("related_model")
template_name = f"research/partials/{related_model}_bibliography_list.html"
return [template_name]
12 changes: 1 addition & 11 deletions src/rard/templates/research/citingauthor_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,7 @@ <h5>{% trans 'Bibliography' %}</h5>
{% endif %}
</div>
</div>
<div id="bib-list"
hx-trigger="refreshed-bibliography from:body, intro-updated from:body"
hx-get="{% url 'citingauthor:bibliography' pk=citingauthor.pk %}"
hx-swap="outerHTML">

{% for item in object.bibliography_items.all %}

{% include 'research/partials/bibliography_list_item.html' with can_edit=perms.research.change_citingauthor has_object_lock=has_object_lock %}

{% endfor %}
</div>
{% include 'research/partials/citing_author_bibliography_list.html' with bibliography_items=object.bibliography_items %}
</section>

{% endwith %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div id="bib-list"
hx-trigger="refreshed-bibliography from:body, intro-updated from:body"
hx-get="{% url 'citingauthor:bibliography' pk=citingauthor.pk %}"
hx-swap="outerHTML">

{% for item in bibliography_items.all %}

{% include 'research/partials/bibliography_list_item.html' with can_edit=perms.research.change_citingauthor has_object_lock=has_object_lock %}

{% endfor %}
</div>

0 comments on commit f2e584b

Please sign in to comment.