diff --git a/castellum/contacts/templates/contacts/__contact.html b/castellum/contacts/templates/contacts/__contact.html index 89e6e0960e4e5eb3e2a103eaa911a6e6c0a2f753..283add301fc4656a6d0d51e6472618c01a38ee32 100644 --- a/castellum/contacts/templates/contacts/__contact.html +++ b/castellum/contacts/templates/contacts/__contact.html @@ -1,4 +1,4 @@ -{% load i18n auth utils subjects reliability %} +{% load i18n auth utils subjects %}
{{ subject|verbose_name:'privacy_level' }}
@@ -8,12 +8,7 @@
{% translate "Reliability" %}
-
- - {% with summary=subject|reliability_summary %} - {% if summary %}({{ summary }}){% endif %} - {% endwith %} -
+
{{ subject|display:'reliability' }}
{# also show not_available_until if it should have been set on legal representatives #} {% if not subject.is_available and subject.contact.has_legal_representative %} diff --git a/castellum/execution/templates/execution/participation_list.html b/castellum/execution/templates/execution/participation_list.html index 207e3fd7b0fa32c6a73ca881008927d679ea3969..03a141135f7a7cbc755642b2d2b09c41bf100ca6 100644 --- a/castellum/execution/templates/execution/participation_list.html +++ b/castellum/execution/templates/execution/participation_list.html @@ -1,5 +1,5 @@ {% extends "execution/study_base.html" %} -{% load i18n reliability auth utils %} +{% load i18n auth utils %} {% block content %} {% if sort_options|length > 1 %} @@ -31,9 +31,6 @@
{{ participation.subject.contact.full_name }} - {% with summary=participation.subject|reliability_summary %} - - {% endwith %} {% if session_count > 0 %} {% icon 'calendar' label=_('Appointments') %} diff --git a/castellum/subjects/models.py b/castellum/subjects/models.py index 5d8577defe05ec5465125e071ae9fa02e81fb6c6..275db8ebffdea64d56e88fd04a89bd99ec0c0918 100644 --- a/castellum/subjects/models.py +++ b/castellum/subjects/models.py @@ -224,13 +224,18 @@ class Subject(TimeStampedModel): now = timezone.localtime() return not self.not_available_until or self.not_available_until <= now - def annotate_reliability(self): - if hasattr(self, 'reliability_issues'): - return - - annotated = Subject.objects.annotate_reliability().get(pk=self.pk) - self.reliability_total = annotated.reliability_total - self.reliability_issues = annotated.reliability_issues + def get_reliability_display(self): + if not hasattr(self, 'reliability_issues'): + annotated = Subject.objects.annotate_reliability().get(pk=self.pk) + self.reliability_total = annotated.reliability_total + self.reliability_issues = annotated.reliability_issues + + if self.reliability_total == 0: + return _('no data so far') + else: + return _('{issues} issues in {total} studies').format( + issues=self.reliability_issues, total=self.reliability_total + ) def get_data(self): from castellum.recruitment.models import AttributeDescription diff --git a/castellum/subjects/templates/subjects/maintenance_reliability.html b/castellum/subjects/templates/subjects/maintenance_reliability.html index a64a7dbe516d2632bfa7323bf20f706636bc54fe..eb1adc1066618f332cfc19679865bbb0c9e746ba 100644 --- a/castellum/subjects/templates/subjects/maintenance_reliability.html +++ b/castellum/subjects/templates/subjects/maintenance_reliability.html @@ -1,5 +1,5 @@ {% extends "subjects/maintenance_base.html" %} -{% load i18n django_bootstrap5 auth reliability %} +{% load i18n django_bootstrap5 auth utils %} {% block title %}{% translate "Reliability" %} · {{ block.super }}{% endblock %} @@ -12,12 +12,7 @@
  • -
    - - {% with summary=subject|reliability_summary %} - {% if summary %}({{ summary }}){% endif %} - {% endwith %} -
    +
    {{ subject|display:'reliability' }}
    {% translate 'Last contacted on' %}: {{ subject.updated_at|date }}
    diff --git a/castellum/subjects/templates/subjects/subject_detail.html b/castellum/subjects/templates/subjects/subject_detail.html index 811f83e51350ec6f0667fab276ffcce55dd6c2bd..e83fe67763e7d75d83855724894d40b347869b51 100644 --- a/castellum/subjects/templates/subjects/subject_detail.html +++ b/castellum/subjects/templates/subjects/subject_detail.html @@ -1,5 +1,5 @@ {% extends "subjects/subject_base.html" %} -{% load i18n django_bootstrap5 utils auth subjects reliability %} +{% load i18n django_bootstrap5 utils auth subjects %} {% block title %}{% translate "Subject details" %} · {{ block.super }}{% endblock %} @@ -55,12 +55,7 @@
    {% translate "Reliability" %}
    -
    - - {% with summary=subject|reliability_summary %} - {% if summary %}({{ summary }}){% endif %} - {% endwith %} -
    +
    {{ subject|display:'reliability' }}
    {% translate "Drop out rate" %}
    {{ dropout_rate }}
    diff --git a/castellum/subjects/templatetags/reliability.py b/castellum/subjects/templatetags/reliability.py deleted file mode 100644 index c1a8a794e217f85e3ade3f88cbc0658a8f42949a..0000000000000000000000000000000000000000 --- a/castellum/subjects/templatetags/reliability.py +++ /dev/null @@ -1,53 +0,0 @@ -# (c) 2018-2022 MPIB , -# 2018-2019 MPI-CBS , -# 2018-2019 MPIP -# -# This file is part of Castellum. -# -# Castellum is free software; you can redistribute it and/or modify it -# under the terms of the GNU Affero General Public License as published -# by the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# Castellum is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public -# License along with Castellum. If not, see -# . - -from django import template -from django.utils.translation import gettext_lazy as _ - -register = template.Library() - - -@register.filter -def reliability_level(subject): - subject.annotate_reliability() - - if subject.reliability_total == 0: - ratio = 0 - else: - ratio = subject.reliability_issues / subject.reliability_total - - if ratio >= 0.5 and subject.reliability_issues > 1: - return 'danger' - elif ratio >= 0.25: - return 'warning' - else: - return 'success' - - -@register.filter -def reliability_summary(subject): - subject.annotate_reliability() - - if subject.reliability_total == 0: - return _('no data so far') - else: - return _('{issues} issues in {total} studies').format( - issues=subject.reliability_issues, total=subject.reliability_total - )