~pidgeon690/pidge-events/trunk

« back to all changes in this revision

Viewing changes to Apps/Publicity/models.py

  • Committer: Fergus Ross Ferrier
  • Date: 2009-05-26 15:09:25 UTC
  • Revision ID: hello@fergusrossferrier.co.uk-20090526150925-695q8cy20mahagdw
Split events to separate app and repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from django.db import models
2
 
from Groups.models import Group
3
 
from django.contrib.auth.models import User
4
 
 
5
 
class CommsOfficerManager(models.Manager):
6
 
    ''' Handles logic on sending mailings to CommsOfficers '''
7
 
    
8
 
    def send(self, template, officers):
9
 
        ''' Send email '''
10
 
        for entry in officers:
11
 
            template.add_recipient(entry.contact, alternate_email = entry.position_email)
12
 
        # Don't actually send straight away
13
 
        # template.send()
14
 
    
15
 
    def send_all(self, template):
16
 
        ''' Send to all comms officers '''
17
 
        officers = CommsOfficer.objects.all()
18
 
        self.send(template, officers)
19
 
 
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)
24
 
 
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)
29
 
        
30
 
 
31
 
class CommsOfficer(models.Model):
32
 
    ''' A comms / publicity officer / secretary of a college student union. '''
33
 
    
34
 
    objects = CommsOfficerManager()
35
 
    
36
 
    college = models.ForeignKey(
37
 
        Group,
38
 
        related_name = "union_comms_officer",
39
 
        help_text = "The college that this student union is part of.")
40
 
    
41
 
    body = models.ForeignKey(
42
 
        Group,
43
 
        verbose_name = "student union",
44
 
        related_name = "comms_officer",
45
 
        help_text = "The student union for which this user is an officer.")
46
 
    
47
 
    body_grad = models.BooleanField(
48
 
        "Type of student union",
49
 
        default = False,
50
 
        help_text = "Is this a Graduate student union?")
51
 
    
52
 
    position_name = models.CharField(
53
 
        "official title",
54
 
        max_length = 100,
55
 
        default = "relevant officer")
56
 
    
57
 
    position_email = models.EmailField(
58
 
        "position's email address",
59
 
        blank = True,
60
 
        help_text = "An email address for the position, not the person.")  
61
 
    
62
 
    contact = models.ForeignKey(
63
 
        User,
64
 
        verbose_name = "current officer")
65
 
    
66
 
    def __unicode__(self):
67
 
        return u'%s - %s %s' % (self.contact.get_full_name(), self.body, self.position_name)