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


LANGUAGES = map(lambda (k, v): (k, _(v)), settings.LANGUAGES)
Aymeric Barantal's avatar
Aymeric Barantal committed
7 8 9


class Contact(models.Model):
10
    """Contact model. Person to be called by users"""
Aymeric Barantal's avatar
Aymeric Barantal committed
11 12 13 14
    id = models.AutoField(primary_key=True)
    first_name = models.CharField(max_length=64)
    last_name = models.CharField(max_length=64)
    phone = models.CharField(max_length=32)
15 16 17 18 19
    twitter = models.CharField(max_length=64, blank=True)
    mail = models.CharField(max_length=255, blank=True)

    def __unicode__(self):
        return '%s %s' % (self.first_name, self.last_name)
Aymeric Barantal's avatar
Aymeric Barantal committed
20 21 22 23 24 25


class Campaign(models.Model):
    """Campaign model, describe what have to be achieved"""
    id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=255)
26
    description = models.CharField(max_length=512, blank=True)
27 28
    start_date = models.DateField()
    end_date = models.DateField()
29 30 31
    default_lang = models.CharField(max_length=5,
                                    choices=LANGUAGES,
                                    verbose_name=_('language'))
Aymeric Barantal's avatar
Aymeric Barantal committed
32

33 34 35
    def __unicode__(self):
        return self.title

Aymeric Barantal's avatar
Aymeric Barantal committed
36 37

class Argumentary(models.Model):
38
    """Argumentary in a given language for a campaign"""
Aymeric Barantal's avatar
Aymeric Barantal committed
39
    id = models.AutoField(primary_key=True)
Aymeric Barantal's avatar
Aymeric Barantal committed
40
    campaign = models.ForeignKey(Campaign)
41 42 43
    lang = models.CharField(max_length=5,
                            choices=LANGUAGES,
                            verbose_name=_('language'))
Aymeric Barantal's avatar
Aymeric Barantal committed
44
    text = models.TextField(null=True)
Aymeric Barantal's avatar
Aymeric Barantal committed
45

46 47 48
    def __unicode__(self):
        return 'Argumentary in %s for %s' % (self.lang, self.campaign.title)

Aymeric Barantal's avatar
Aymeric Barantal committed
49 50 51 52

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
53 54
    campaign = models.ForeignKey(Campaign)
    contact = models.ForeignKey(Contact)
Aymeric Barantal's avatar
Aymeric Barantal committed
55
    weight = models.IntegerField(default=0)
Aymeric Barantal's avatar
Aymeric Barantal committed
56 57 58

    def __unicode__(self):
        return 'Contact %s on %s' % (self.contact, self.campaign.title)
59 60 61

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