From f8b82602729d9ea134db2d81bd4d65a7910a3082 Mon Sep 17 00:00:00 2001 From: Taib Hayat Date: Wed, 14 Apr 2021 14:05:13 +0200 Subject: [PATCH 1/4] basic ProgressView --- castellum/execution/templates/execution/study_base.html | 3 +++ .../execution/templates/execution/study_progress.html | 7 +++++++ castellum/execution/urls.py | 2 ++ castellum/execution/views.py | 9 +++++++++ 4 files changed, 21 insertions(+) create mode 100644 castellum/execution/templates/execution/study_progress.html diff --git a/castellum/execution/templates/execution/study_base.html b/castellum/execution/templates/execution/study_base.html index 0d5088a02..5a0dad110 100644 --- a/castellum/execution/templates/execution/study_base.html +++ b/castellum/execution/templates/execution/study_base.html @@ -38,6 +38,9 @@ {% translate 'Criteria' %} {% endif %} + {% endblock %} diff --git a/castellum/execution/templates/execution/study_progress.html b/castellum/execution/templates/execution/study_progress.html new file mode 100644 index 000000000..9bd778676 --- /dev/null +++ b/castellum/execution/templates/execution/study_progress.html @@ -0,0 +1,7 @@ +{% extends "execution/study_base.html" %} +{% load i18n auth %} + +{% block title %}{% translate "Progress" %} · {{ block.super }}{% endblock %} + +{% block content %} +{% endblock %} diff --git a/castellum/execution/urls.py b/castellum/execution/urls.py index 0dc514386..1461643d5 100644 --- a/castellum/execution/urls.py +++ b/castellum/execution/urls.py @@ -37,6 +37,7 @@ from .views import ParticipationDetailView from .views import ParticipationNewsView from .views import ParticipationPseudonymsView from .views import ParticipationRemoveView +from .views import ProgressView from .views import ResolveView from .views import ShowUpUpdateView from .views import StudyDetailView @@ -51,6 +52,7 @@ urlpatterns = [ path('/calendar/feed/', AppointmentFeedForStudy(), name='calendar-feed'), path('/criteria/', ExclusionCriteriaView.as_view(), name='criteria'), path('/export/', ExportView.as_view(), name='export'), + path('/progress/', ProgressView.as_view(), name='progress'), path( '//', ParticipationDetailView.as_view(), diff --git a/castellum/execution/views.py b/castellum/execution/views.py index c787c7bae..35eb825e5 100644 --- a/castellum/execution/views.py +++ b/castellum/execution/views.py @@ -33,6 +33,7 @@ from django.urls import reverse from django.utils.translation import gettext_lazy as _ from django.views.generic import DetailView from django.views.generic import FormView +from django.views.generic import ListView from django.views.generic import UpdateView from castellum.appointments.forms import AppointmentsForm @@ -500,3 +501,11 @@ class CalendarView(StudyMixin, PermissionRequiredMixin, BaseCalendarView): def get_appointments(self): return super().get_appointments().filter(session__study=self.object) + + +class ProgressView(StudyMixin, PermissionRequiredMixin, ListView): + model = Study + template_name = 'execution/study_progress.html' + permission_required = 'recruitment.conduct_study' + study_status = [Study.EXECUTION] + tab = 'progress' -- GitLab From 6165ddcdc4d138f9ee6747de08576334dbdc8df3 Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Wed, 21 Apr 2021 17:47:25 +0200 Subject: [PATCH 2/4] define Appointment.SHOWUP_OK --- castellum/appointments/models.py | 2 ++ castellum/execution/views.py | 2 +- castellum/recruitment/models/participations.py | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/castellum/appointments/models.py b/castellum/appointments/models.py index 86e7c1070..7bcc61ab4 100644 --- a/castellum/appointments/models.py +++ b/castellum/appointments/models.py @@ -47,6 +47,8 @@ class Appointment(models.Model): (NOSHOW, _('no show')), ] + SHOWUP_OK = [SHOWUP, LATE] + session = models.ForeignKey(StudySession, verbose_name=_('Session'), on_delete=models.CASCADE) start = DateTimeField(_('Start')) reminded = models.BooleanField(_('Reminded'), default=False) diff --git a/castellum/execution/views.py b/castellum/execution/views.py index 35eb825e5..6118fb018 100644 --- a/castellum/execution/views.py +++ b/castellum/execution/views.py @@ -486,7 +486,7 @@ class CalendarView(StudyMixin, PermissionRequiredMixin, BaseCalendarView): title = '{} ({})'.format(title, appointment.get_show_up_display()) class_names = [] - if appointment.show_up not in [Appointment.SHOWUP, Appointment.LATE]: + if appointment.show_up not in Appointment.SHOWUP_OK: class_names.append('fullcalendar-muted') return { diff --git a/castellum/recruitment/models/participations.py b/castellum/recruitment/models/participations.py index 38d11374a..1004fd2ab 100644 --- a/castellum/recruitment/models/participations.py +++ b/castellum/recruitment/models/participations.py @@ -87,7 +87,7 @@ class ParticipationManager(models.Manager): return self.get_queryset().annotate( appointment_count=models.Count( 'appointment', - filter=models.Q(appointment__show_up__in=[Appointment.SHOWUP, Appointment.LATE]), + filter=models.Q(appointment__show_up__in=Appointment.SHOWUP_OK), distinct=True, ) ) -- GitLab From d03cb48c4c6546f03e1f4f4937e4beb753774698 Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Wed, 21 Apr 2021 18:02:54 +0200 Subject: [PATCH 3/4] display recruitment progress --- .../templates/execution/study_progress.html | 5 +++++ castellum/execution/views.py | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/castellum/execution/templates/execution/study_progress.html b/castellum/execution/templates/execution/study_progress.html index 9bd778676..b0b3106a2 100644 --- a/castellum/execution/templates/execution/study_progress.html +++ b/castellum/execution/templates/execution/study_progress.html @@ -4,4 +4,9 @@ {% block title %}{% translate "Progress" %} · {{ block.super }}{% endblock %} {% block content %} +

{% translate 'Participating' %}

+

+ {{ invited }}/{{ total }} + +

{% endblock %} diff --git a/castellum/execution/views.py b/castellum/execution/views.py index 6118fb018..b366026be 100644 --- a/castellum/execution/views.py +++ b/castellum/execution/views.py @@ -509,3 +509,15 @@ class ProgressView(StudyMixin, PermissionRequiredMixin, ListView): permission_required = 'recruitment.conduct_study' study_status = [Study.EXECUTION] tab = 'progress' + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + + context['invited'] = ( + self.study.participation_set + .filter(status=Participation.INVITED) + .count() + ) + context['total'] = max(self.study.min_subject_count, context['invited']) + + return context -- GitLab From 80938569cfabb7278e67594665cb678cb7d2d850 Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Wed, 21 Apr 2021 18:03:11 +0200 Subject: [PATCH 4/4] display appointment progress --- .../templates/execution/study_progress.html | 13 +++++++++++++ castellum/execution/views.py | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/castellum/execution/templates/execution/study_progress.html b/castellum/execution/templates/execution/study_progress.html index b0b3106a2..589901fe5 100644 --- a/castellum/execution/templates/execution/study_progress.html +++ b/castellum/execution/templates/execution/study_progress.html @@ -9,4 +9,17 @@ {{ invited }}/{{ total }}

+ + {% for session in sessions %} +

{{ session.name }}

+
+
{% translate 'took place' %}
+
{{ session.took_place }}/{{ total }}
+
+ +
{% translate 'scheduled' %}
+
{{ session.scheduled }}/{{ total }}
+
+
+ {% endfor %} {% endblock %} diff --git a/castellum/execution/views.py b/castellum/execution/views.py index b366026be..9f6945734 100644 --- a/castellum/execution/views.py +++ b/castellum/execution/views.py @@ -30,6 +30,7 @@ from django.http import HttpResponse from django.shortcuts import get_object_or_404 from django.shortcuts import redirect from django.urls import reverse +from django.utils import timezone from django.utils.translation import gettext_lazy as _ from django.views.generic import DetailView from django.views.generic import FormView @@ -519,5 +520,20 @@ class ProgressView(StudyMixin, PermissionRequiredMixin, ListView): .count() ) context['total'] = max(self.study.min_subject_count, context['invited']) + context['sessions'] = self.study.studysession_set.annotate( + scheduled=models.Count( + 'appointment', + filter=models.Q(appointment__show_up__in=Appointment.SHOWUP_OK), + distinct=True, + ), + took_place=models.Count( + 'appointment', + filter=models.Q( + appointment__show_up__in=Appointment.SHOWUP_OK, + appointment__start__lte=timezone.now(), + ), + distinct=True, + ), + ) return context -- GitLab