1
from django.db import models
2
from Groups.models import Group
3
from django.contrib.auth.models import User
5
class CommsOfficerManager(models.Manager):
6
''' Handles logic on sending mailings to CommsOfficers '''
8
def send(self, template, officers):
10
for entry in officers:
11
template.add_recipient(entry.contact, alternate_email = entry.position_email)
12
# Don't actually send straight away
15
def send_all(self, template):
16
''' Send to all comms officers '''
17
officers = CommsOfficer.objects.all()
18
self.send(template, officers)
20
def send_undergrad(self, template):
21
''' Send to undergrad SU comms officers '''
22
officers = CommsOfficer.objects.filter(body_grad = False)
23
self.send(template, officers)
25
def send_postgrad(self, template):
26
''' Send to postgrad SU comms officers '''
27
officers = CommsOfficer.objects.filter(body_grad = True)
28
self.send(template, officers)
31
class CommsOfficer(models.Model):
32
''' A comms / publicity officer / secretary of a college student union. '''
34
objects = CommsOfficerManager()
36
college = models.ForeignKey(
38
related_name = "union_comms_officer",
39
help_text = "The college that this student union is part of.")
41
body = models.ForeignKey(
43
verbose_name = "student union",
44
related_name = "comms_officer",
45
help_text = "The student union for which this user is an officer.")
47
body_grad = models.BooleanField(
48
"Type of student union",
50
help_text = "Is this a Graduate student union?")
52
position_name = models.CharField(
55
default = "relevant officer")
57
position_email = models.EmailField(
58
"position's email address",
60
help_text = "An email address for the position, not the person.")
62
contact = models.ForeignKey(
64
verbose_name = "current officer")
66
def __unicode__(self):
67
return u'%s - %s %s' % (self.contact.get_full_name(), self.body, self.position_name)