Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# (c) 2018-2020
2# MPIB <https://www.mpib-berlin.mpg.de/>,
3# MPI-CBS <https://www.cbs.mpg.de/>,
4# MPIP <http://www.psych.mpg.de/>
5#
6# This file is part of Castellum.
7#
8# Castellum is free software; you can redistribute it and/or modify it
9# under the terms of the GNU Affero General Public License as published
10# by the Free Software Foundation; either version 3 of the License, or
11# (at your option) any later version.
12#
13# Castellum is distributed in the hope that it will be useful, but
14# WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16# Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public
19# License along with Castellum. If not, see
20# <http://www.gnu.org/licenses/>.
22from django.core.exceptions import PermissionDenied
23from django.shortcuts import get_object_or_404
25from castellum.studies.models import Study
27from .mixins import BaseAppointmentFeed
28from .mixins import BaseFollowUpFeed
29from .models import ParticipationRequest
32class FollowUpFeedForStudy(BaseFollowUpFeed):
33 def get_object(self, request, *args, **kwargs):
34 study = get_object_or_404(Study, pk=kwargs.get('study_pk'), status=Study.EXECUTION)
35 perms = ('recruitment.add_participationrequest', 'studies.access_study')
36 if not self.request.user.has_perms(perms, obj=study): 36 ↛ 37line 36 didn't jump to line 37, because the condition on line 36 was never true
37 raise PermissionDenied
38 return study
40 def items(self, study):
41 return ParticipationRequest.objects\
42 .filter(study=study, followup_date__isnull=False)\
43 .order_by('-followup_date', '-followup_time')
46class FollowUpFeedForUser(BaseFollowUpFeed):
47 def get_object(self, request, *args, **kwargs):
48 return self.request.user
50 def items(self, user):
51 perms = ('recruitment.add_participationrequest', 'studies.access_study')
52 for study in Study.objects.filter(status=Study.EXECUTION):
53 if not user.has_perms(perms, obj=study):
54 continue
55 qs = ParticipationRequest.objects\
56 .filter(study=study, followup_date__isnull=False)\
57 .order_by('-followup_date', '-followup_time')
58 for participation_request in qs:
59 yield participation_request
62class AppointmentFeed(BaseAppointmentFeed):
63 def get_object(self, request, *args, **kwargs):
64 study = get_object_or_404(Study, pk=kwargs['pk'], status=Study.EXECUTION)
65 perms = ('recruitment.view_participationrequest', 'studies.access_study')
66 if not self.request.user.has_perms(perms, obj=study):
67 raise PermissionDenied
68 return study
70 def items(self, study):
71 return super().items(study).filter(session__study=study)
73 def item_link(self, item):
74 # This is not really a usable link, but it is unique
75 return '/appointments/%i/' % item.pk