models.py 1.76 KB
Newer Older
Aymeric Barantal's avatar
Aymeric Barantal committed
1
from django.db import models
2
3
4
from django.utils.translation import ugettext_lazy as _
from django.conf import settings

5
6
from picampaign.organization.models import Organization
from picampaign.contact.models import Contact
Aymeric Barantal's avatar
Aymeric Barantal committed
7
8


9
LANGUAGES = map(lambda (k, v): (k, _(v)), settings.LANGUAGES)
Aymeric Barantal's avatar
Aymeric Barantal committed
10
11
12
13
14
15


class Campaign(models.Model):
    """Campaign model, describe what have to be achieved"""
    id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=255)
16
    description = models.CharField(max_length=512, blank=True)
17
    organization = models.ForeignKey(Organization)
18
19
    start_date = models.DateField()
    end_date = models.DateField()
20
21
22
    default_lang = models.CharField(max_length=5,
                                    choices=LANGUAGES,
                                    verbose_name=_('language'))
Aymeric Barantal's avatar
Aymeric Barantal committed
23

24
25
26
    def __unicode__(self):
        return self.title

Aymeric Barantal's avatar
Aymeric Barantal committed
27
28

class Argumentary(models.Model):
29
    """Argumentary in a given language for a campaign"""
Aymeric Barantal's avatar
Aymeric Barantal committed
30
    id = models.AutoField(primary_key=True)
Aymeric Barantal's avatar
Aymeric Barantal committed
31
    campaign = models.ForeignKey(Campaign)
32
33
34
    lang = models.CharField(max_length=5,
                            choices=LANGUAGES,
                            verbose_name=_('language'))
Aymeric Barantal's avatar
Aymeric Barantal committed
35
    text = models.TextField(null=True)
Aymeric Barantal's avatar
Aymeric Barantal committed
36

37
38
39
    def __unicode__(self):
        return 'Argumentary in %s for %s' % (self.lang, self.campaign.title)

Aymeric Barantal's avatar
Aymeric Barantal committed
40
41
42
43

class CampaignContact(models.Model):
    """List contact related to a campaign with a given weight"""
    id = models.AutoField(primary_key=True)
Aymeric Barantal's avatar
Aymeric Barantal committed
44
45
    campaign = models.ForeignKey(Campaign)
    contact = models.ForeignKey(Contact)
Aymeric Barantal's avatar
Aymeric Barantal committed
46
    weight = models.IntegerField(default=0)
Aymeric Barantal's avatar
Aymeric Barantal committed
47
48
49

    def __unicode__(self):
        return 'Contact %s on %s' % (self.contact, self.campaign.title)
50
51
52

    def all_groups(self):
        return [x.name for x in self.contact.groups.all()]