Merge "Implement Notification Framework with Initial Email Support"
[laas.git] / src / notifier / models.py
1 ##############################################################################
2 # Copyright (c) 2016 Max Breitenfeldt 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 jira import JIRA, JIRAError
12 from dashboard.models import Resource
13 from booking.models import Booking
14 from django.contrib.auth.models import User
15 from account.models import UserProfile
16 from django.contrib import messages
17 from django.db.models.signals import pre_save
18 from fernet_fields import EncryptedTextField
19
20 class Notifier(models.Model):
21     id = models.AutoField(primary_key=True)
22     title = models.CharField(max_length=240)
23     content = EncryptedTextField()
24     user = models.ForeignKey(UserProfile, on_delete=models.CASCADE, null=True, blank=True)
25     sender = models.CharField(max_length=240, default='unknown')
26     message_type = models.CharField(max_length=240, default='email', choices=(
27         ('email','Email'), 
28         ('webnotification', 'Web Notification')))
29     msg_sent = ''
30
31     import notifier.dispatchers
32
33     def __str__(self):
34         return self.title
35
36     def getEmail(self):
37         return self.user.email_addr
38