Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/rard/research/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def get_work_display_name(self):

def get_work_display_name_full(self):
# to also show the antiquarian link as well as the work link
return "%s [= %s]" % (self.get_work_display_name(), self.get_display_name())
return f"{self.get_work_display_name()} [= {self.get_display_name()}]"

def display_work_order_one_indexed(self):
try:
Expand Down Expand Up @@ -649,8 +649,12 @@ def get_display_name_option_c(self):
names = self.get_link_names(show_certainty=False)
return self._render_display_name(names, add_also=False)

def get_link_names(self, show_certainty=True):
def get_link_names(self, show_certainty=True, first_work=None):
links = self.get_all_links().order_by("work", "antiquarian", "order")
if first_work:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose you could order by "work == first_work" (descending) (however you write that), which would at least pretend that it might at some point be SQL.
Still this is fine.

first_links = links.filter(work=first_work)
other_links = links.exclude(work=first_work)
links = list(first_links) + list(other_links)
names = []
for link in links:
if link.work and not link.work.unknown:
Expand All @@ -670,3 +674,8 @@ def get_display_name_option_b(self):
# option b currently default
names = self.get_link_names(show_certainty=False)
return self._render_display_name(names)

def get_display_name_for_work(self, work):
# put the link to the antiquarian first if it exists and then the others
names = self.get_link_names(show_certainty=False, first_work=work)
return self._render_display_name(names)
6 changes: 5 additions & 1 deletion src/rard/research/models/testimonium.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,14 @@ def get_absolute_url(self):
def get_all_names(self):
return [link.get_display_name() for link in self.get_all_links()]

def get_link_names(self, show_certainty=True):
def get_link_names(self, show_certainty=True, first_work=None):
links = self.get_all_links().order_by(
"-work__unknown", "work", "antiquarian", "order"
)
if first_work:
first_links = links.filter(work=first_work)
other_links = links.exclude(work=first_work)
links = list(first_links) + list(other_links)
names = []
for link in links:
if link.work and not link.work.unknown:
Expand Down
8 changes: 8 additions & 0 deletions src/rard/research/templatetags/name_in_context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django import template

register = template.Library()


@register.filter
def name_in_context(obj, work):
return obj.get_display_name_for_work(work)
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{# Assumes a context object named 'link' and 'link_text'. Optional disable_link_controls to display but disable the link controls #}

{% load i18n %}
{% load i18n name_in_context %}

{% with fragment=link.linked %}
<div class='drop-target' data-pos='{{ forloop.counter0 }}' data-objecttype='anonymous_fragment'>
</div>
<div id='anonymous_fragmentlink_{{ link.pk }}' data-link='{{ link.pk }}' data-antiquarian='{{ link.antiquarian.pk }}' draggable='false' data-objecttype='anonymous_fragment' data-pos='{{ forloop.counter0 }}' class='drag-item ordered-list-item rard-list-item d-flex justify-content-between'>
<div>
<li class="unstyled">
{% with fragment.get_display_name as link_text %}
{% with link_text=fragment|name_in_context:work %}
{% if perms.research.view_fragment %}

{% include 'research/partials/render_definite_indicators.html' with link=link %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{# Assumes a context object named 'link' and 'link_text'. Optional disable_link_controls to display but disable the link controls #}

{% load i18n %}
{% load i18n name_in_context %}

{% with fragment=link.linked %}
<div class='drop-target' data-pos='{{ forloop.counter0 }}' data-objecttype='fragment'>
</div>
<div id='fragmentlink_{{ link.pk }}' data-link='{{ link.pk }}' data-antiquarian='{{ link.antiquarian.pk }}' draggable='false' data-objecttype='fragment' data-pos='{{ forloop.counter0 }}' class='drag-item ordered-list-item rard-list-item d-flex justify-content-between'>
<div>
<li class="unstyled">
{% with fragment.get_display_name as link_text %}
{% with link_text=fragment|name_in_context:work %}
{% if perms.research.view_fragment %}

{% include 'research/partials/render_definite_indicators.html' with link=link %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{# Assumes context objects named 'link' and 'link_text'. Optional disable_link_controls to display but disable the link controls #}

{% load i18n %}
{% load i18n name_in_context %}

{% with testimonium=link.linked %}

Expand All @@ -10,7 +10,7 @@
<div id='testimoniumlink_{{ link.pk }}' data-link='{{ link.pk }}' data-antiquarian='{{ link.antiquarian.pk }}' draggable='false' data-objecttype='testimonium' data-pos='{{ forloop.counter0 }}' class='drag-item ordered-list-item rard-list-item d-flex justify-content-between'>
<div>
<li class="unstyled">
{% with testimonium.get_display_name as link_text %}
{% with link_text=testimonium|name_in_context:work %}
{% if perms.research.view_testimonium %}

{% include 'research/partials/render_definite_indicators.html' with link=link %}
Expand Down
Loading