Hide keyboard shortcuts

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 

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/>. 

21 

22import datetime 

23 

24from django.db import models 

25from django.forms import ValidationError 

26from django.utils.formats import date_format 

27from django.utils.formats import time_format 

28from django.utils.translation import gettext_lazy as _ 

29 

30from castellum.studies.models import StudySession 

31from castellum.utils.fields import DateTimeField 

32 

33from .recruitment import ParticipationRequest 

34 

35MINUTE = datetime.timedelta(seconds=60) 

36 

37 

38class Appointment(models.Model): 

39 session = models.ForeignKey(StudySession, verbose_name=_('Session'), on_delete=models.CASCADE) 

40 start = DateTimeField(_('Start')) 

41 participant = models.ForeignKey( 

42 ParticipationRequest, 

43 on_delete=models.CASCADE, 

44 verbose_name=_('Participant'), 

45 ) 

46 

47 class Meta: 

48 ordering = ('start',) 

49 unique_together = ['session', 'participant'] 

50 

51 def __str__(self): 

52 return '%s %s' % (date_format(self.start), time_format(self.start)) 

53 

54 def clean(self): 

55 if self.session.study != self.participant.study: 

56 raise ValidationError( 

57 _('Session and participant do not belong to the same study'), code='study' 

58 ) 

59 

60 @property 

61 def end(self): 

62 return self.start + MINUTE * self.session.duration