Newer
Older
# (c) 2020 MPIB <https://www.mpib-berlin.mpg.de/>,
#
# This file is part of castellum-scheduler.
#
# castellum-scheduler 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
# <http://www.gnu.org/licenses/>.
import datetime
from django.db import models
from django.utils import formats
from django.utils.translation import gettext_lazy as _
class Schedule(models.Model):
uuid = models.UUIDField(default=uuid.uuid4, unique=True, editable=False)
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
title = models.CharField(_('Title'), max_length=254)
def __str__(self):
return self.title
class Timeslot(models.Model):
schedule = models.ForeignKey(Schedule, verbose_name=_('Schedule'), on_delete=models.CASCADE)
# date and time fields are always naive -- which is what we want
# https://docs.djangoproject.com/en/3.0/topics/i18n/timezones/#naive-and-aware-datetime-objects
date = models.DateField(_('Date'))
time = models.TimeField(_('Time'))
class Meta:
unique_together = ['schedule', 'date', 'time']
ordering = ['date', 'time']
def __str__(self):
return '%s %s' % (formats.date_format(self.date), formats.time_format(self.time))
@property
def datetime(self):
return datetime.datetime.combine(self.date, self.time)
class Invitation(models.Model):
token = models.CharField(_('Token'), max_length=254)
schedule = models.ForeignKey(Schedule, verbose_name=_('Schedule'), on_delete=models.CASCADE)
timeslot = models.OneToOneField(
Timeslot,
verbose_name=_('Timeslot'),
blank=True,
null=True,
on_delete=models.SET_NULL,
)
class Meta:
unique_together = ['schedule', 'token']
def __str__(self):
return '%s:%s' % (self.schedule, self.token)