From d77560162ebf4805bab5eaaf051467590f2b414f Mon Sep 17 00:00:00 2001 From: maxbr Date: Mon, 19 Sep 2016 10:13:26 +0200 Subject: Send notifications for booking start and end JIRA: PHAROS-265 Change-Id: I53a37ac31dda70935752afc6da3315e6dfcbc90f Signed-off-by: maxbr --- pharos-dashboard/notification/models.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 pharos-dashboard/notification/models.py (limited to 'pharos-dashboard/notification/models.py') diff --git a/pharos-dashboard/notification/models.py b/pharos-dashboard/notification/models.py new file mode 100644 index 0000000..80f65df --- /dev/null +++ b/pharos-dashboard/notification/models.py @@ -0,0 +1,22 @@ +from django.db import models + +class BookingNotification(models.Model): + id = models.AutoField(primary_key=True) + type = models.CharField(max_length=100) + booking = models.ForeignKey('booking.Booking', on_delete=models.CASCADE) + submit_time = models.DateTimeField() + submitted = models.BooleanField(default=False) + + def get_content(self): + return { + 'start': self.booking.start.isoformat(), + 'end': self.booking.end.isoformat(), + 'user': self.booking.user.username, + 'purpose': self.booking.purpose + } + + def save(self, *args, **kwargs): + notifications = self.booking.bookingnotification_set.filter(type=self.type) + if notifications.count() > 1: + raise ValueError('Doubled Notification') + return super(BookingNotification, self).save(*args, **kwargs) \ No newline at end of file -- cgit 1.2.3-korg