From 4a53384e29f61e20a6db18c9433230d7d3b17cb6 Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Mon, 27 Jun 2022 17:40:09 +0200 Subject: [PATCH 1/2] rm reliability from execution list items --- .../execution/templates/execution/participation_list.html | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/castellum/execution/templates/execution/participation_list.html b/castellum/execution/templates/execution/participation_list.html index 207e3fd7b..03a141135 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') %} -- GitLab From d6af8c05d3c5d0f906c53f4a998314e4ec1f70d4 Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Mon, 27 Jun 2022 17:40:37 +0200 Subject: [PATCH 2/2] rm reliability traffic lights --- .../templates/contacts/__contact.html | 9 +--- castellum/subjects/models.py | 19 ++++--- .../subjects/maintenance_reliability.html | 9 +--- .../templates/subjects/subject_detail.html | 9 +--- .../subjects/templatetags/reliability.py | 53 ------------------- 5 files changed, 18 insertions(+), 81 deletions(-) delete mode 100644 castellum/subjects/templatetags/reliability.py diff --git a/castellum/contacts/templates/contacts/__contact.html b/castellum/contacts/templates/contacts/__contact.html index 89e6e0960..283add301 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/subjects/models.py b/castellum/subjects/models.py index 5d8577def..275db8ebf 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 a64a7dbe5..eb1adc106 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 811f83e51..e83fe6776 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 c1a8a794e..000000000 --- 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 - ) -- GitLab