Skip to content

Commit

Permalink
improved call back list and added hide button
Browse files Browse the repository at this point in the history
  • Loading branch information
bbonf committed Oct 7, 2024
1 parent 39ea6e0 commit 4af7581
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 17 deletions.
18 changes: 18 additions & 0 deletions lab/experiments/migrations/0016_call_hidden.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.11 on 2024-10-07 10:05

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("experiments", "0015_timeslot_end_after_start"),
]

operations = [
migrations.AddField(
model_name="call",
name="hidden",
field=models.BooleanField(default=False),
),
]
3 changes: 3 additions & 0 deletions lab/experiments/models/invite_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ class CallStatus(models.TextChoices):

creation_date = models.DateTimeField(auto_now_add=True)
comment = models.TextField(null=True)

# currently used to silence CALLBACK calls, but keep them in the call log
hidden = models.BooleanField(default=False)
21 changes: 13 additions & 8 deletions lab/experiments/urls/call_urls.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
from django.urls import path

from ..views.call_views import CallHomeView, AppointmentConfirm, UpdateCall, AppointmentSendEmail
from ..views.call_views import (
AppointmentConfirm,
AppointmentSendEmail,
CallHomeView,
HideCall,
UpdateCall,
)

urlpatterns = [
path('<int:experiment>/call/<int:participant>', CallHomeView.as_view(), name='call'),


path('call/appointment/', AppointmentConfirm.as_view()),
path('call/appointment/email/<int:pk>/', AppointmentSendEmail.as_view()),
path('call/appointment/email/', AppointmentSendEmail.as_view()),
path('call/<int:pk>/', UpdateCall.as_view())
path("<int:experiment>/call/<int:participant>", CallHomeView.as_view(), name="call"),
path("call/appointment/", AppointmentConfirm.as_view()),
path("call/appointment/email/<int:pk>/", AppointmentSendEmail.as_view()),
path("call/appointment/email/", AppointmentSendEmail.as_view()),
path("call/<int:pk>/", UpdateCall.as_view()),
path("call/<int:pk>/hide/", HideCall.as_view(), name="call_hide"),
]
15 changes: 15 additions & 0 deletions lab/experiments/views/call_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.conf import settings
from django.core.exceptions import BadRequest, PermissionDenied
from django.http.response import JsonResponse
from django.shortcuts import redirect
from django.utils import timezone, translation
from django.utils.dateparse import parse_datetime
from django.utils.translation import gettext_lazy as _
Expand Down Expand Up @@ -189,3 +190,17 @@ def update(self, request, *args, **kwargs):
)
mail.send()
return JsonResponse(self.serializer_class(call).data)


class HideCall(views.APIView):
permission_classes = [IsExperimentLeader]

@property
def experiment(self):
return Call.objects.get(pk=self.kwargs["pk"]).experiment

def get(self, request, *args, **kwargs):
call = Call.objects.get(pk=kwargs["pk"])
call.hidden = True
call.save()
return redirect("/")
3 changes: 3 additions & 0 deletions lab/main/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,6 @@ msgstr "You are a leader of the following experiments:"

msgid "main:home:call_back"
msgstr "These participants should be called back:"

msgid "main:home:call_back:remove"
msgstr "X"
3 changes: 3 additions & 0 deletions lab/main/locale/nl/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ msgstr "Jij bent leider van de volgende experimenten:"
msgid "main:home:call_back"
msgstr "De volgende participanten moeten teruggebeld worden:"

msgid "main:home:call_back:remove"
msgstr "X"

msgid "users:leaders:header"
msgstr "Proefleiders"

Expand Down
8 changes: 5 additions & 3 deletions lab/main/templates/main/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ <h1>

</aside>
<div class="uu-sidebar-content">
<p>{% transformat 'main:home:hello' user.get_full_name %}</p>
<p>{% translate 'main:home:welcome' %}</p>

{% if missing_outcome %}
Expand All @@ -39,7 +38,7 @@ <h1>
</ul>
{% endif %}
{% if open_calls %}
<p>{% trans 'main:home:open_calls:text' %}</p>
<p class="mt-5">{% trans 'main:home:open_calls:text' %}</p>
<ul>
{% for call in open_calls %}
<li><a href="{% url 'experiments:call' call.experiment.pk call.participant.pk %}">{{ call.participant.name }}</a> ({{ call.creation_date | date:'Y-m-d H:i' }})</li>
Expand All @@ -48,11 +47,14 @@ <h1>
{% endif %}

{% if call_back %}
<p>{% translate "main:home:call_back" %}</p>
<p class="mt-5">{% translate "main:home:call_back" %}</p>
<ul>
{% for call in call_back %}
<li><a href="{% url 'experiments:call' call.experiment.pk call.participant.pk %}">{{ call.participant.name }}</a>
{% if call.comment %}({{ call.comment }}){% endif %}
<a class="text-danger m-5" href="{% url 'experiments:call_hide' call.pk %}">
[{% translate "main:home:call_back:remove" %}]
</a>
</li>
{% endfor %}
</ul>
Expand Down
18 changes: 12 additions & 6 deletions lab/main/views/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@
class HomeView(braces.LoginRequiredMixin, generic.TemplateView):
template_name = "main/index.html"

def get_callback_calls(self, user):
# participants should be called back when the last call logged for them has the status CALLBACK.
# to avoid complex queries, we do the grouping in python instead of ORM
calls = user.call_set.filter(hidden=False)
last_per_pp = dict()
for call in calls:
if call.participant not in last_per_pp or call.creation_date > last_per_pp[call.participant].creation_date:
last_per_pp[call.participant] = call

return [call for call in last_per_pp.values() if call.status == Call.CallStatus.CALLBACK]

def get_context_data(self, *args, **kwargs):
context = super().get_context_data(**kwargs)

user = self.request.user

if self.request.user.is_leader:
context["experiments"] = user.experiments.all()
call_back = user.call_set.filter(status=Call.CallStatus.CALLBACK)
last_per_pp = dict()
for call in call_back:
if call.participant not in last_per_pp or call.creation_date > last_per_pp[call.participant]:
last_per_pp[call.participant] = call

context["call_back"] = last_per_pp.values()
context["call_back"] = self.get_callback_calls(user)
context["open_calls"] = user.call_set.filter(status=Call.CallStatus.STARTED)
context["missing_outcome"] = (
user.appointment_set.filter(outcome=None)
Expand Down

0 comments on commit 4af7581

Please sign in to comment.