03e23b3c3c9739b55e3dd56a7250cfed271c6756
[laas.git] / src / notifier / models.py
1 ##############################################################################
2 # Copyright (c) 2018 Sawyer Bergeron, Parker Berberian, and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 from django.db import models
11 from account.models import UserProfile
12 from booking.models import Booking
13
14
15 class Notification(models.Model):
16     title = models.CharField(max_length=150)
17     content = models.TextField()
18     recipients = models.ManyToManyField(UserProfile, related_name='notifications')
19     is_html = models.BooleanField(default=True)
20     read_by = models.ManyToManyField(UserProfile, related_name='read_notifications')
21
22     def __str__(self):
23         return self.title
24
25     def to_preview_html(self):
26         return "<h3>" + self.title + "</h3>"  # TODO - template?
27
28
29 class Emailed(models.Model):
30     """A simple record to remember who has already gotten an email to avoid resending."""
31
32     begin_booking = models.OneToOneField(
33         Booking,
34         null=True,
35         on_delete=models.CASCADE,
36         related_name="begin_mail"
37     )
38     almost_end_booking = models.OneToOneField(
39         Booking,
40         null=True,
41         on_delete=models.CASCADE,
42         related_name="warning_mail"
43     )
44     end_booking = models.OneToOneField(
45         Booking,
46         null=True,
47         on_delete=models.CASCADE,
48         related_name="over_mail"
49     )
50
51
52 class Email(models.Model):
53     sent = models.BooleanField(default=False)
54     title = models.CharField(max_length=150)
55     message = models.TextField()
56     recipient = models.CharField(max_length=150)