models.py 1.71 KB
Newer Older
1
from django.db import models
2 3
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
okhin's avatar
okhin committed
4
from ckeditor.fields import RichTextField
5

6 7
from picampaign.organization.models import Organization
from picampaign.contact.models import Contact
8 9 10 11 12 13


class Campaign(models.Model):
    """Campaign model, describe what have to be achieved"""
    id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=255)
okhin's avatar
okhin committed
14
    description = RichTextField(null=True)
15
    organization = models.ForeignKey(Organization, related_name='campaigns')
16 17
    start_date = models.DateField()
    end_date = models.DateField()
18
    phone_filter = models.CharField(max_length=20, null=True, blank=True)
19

20
    def __str__(self):
21
        return self.title
22 23

class Argumentary(models.Model):
24
    """Argumentary for a campaign"""
25
    id = models.AutoField(primary_key=True)
26
    campaign = models.ForeignKey(Campaign)
okhin's avatar
okhin committed
27
    title = RichTextField(max_length=255, verbose_name=_('title'), null=True, blank=True)
Aymeric Barantal's avatar
Aymeric Barantal committed
28
    text = models.TextField(null=True)
29

30
    def __str__(self):
31 32
        args = {'title': self.campaign.title}
        return _('Argumentary for %(title)s') % args
33

34 35 36
class CampaignContact(models.Model):
    """List contact related to a campaign with a given weight"""
    id = models.AutoField(primary_key=True)
37 38
    campaign = models.ForeignKey(Campaign)
    contact = models.ForeignKey(Contact)
39
    weight = models.IntegerField(default=0)
40

okhin's avatar
okhin committed
41 42 43
    class Meta:
        unique_together = (("campaign", "contact"),)

44
    def __str__(self):
Aymeric Barantal's avatar
Aymeric Barantal committed
45 46
        args = {'contact': self.contact, 'title': self.campaign.title}
        return _('Contact %(contact)s on %(title)s') % args
47 48 49

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