from django.db import models from django.utils.translation import ugettext_lazy as _ from django.conf import settings from picampaign.organization.models import Organization from picampaign.contact.models import Contact LANGUAGES = map(lambda k, v: (k, _(v)), settings.LANGUAGES) class Campaign(models.Model): """Campaign model, describe what have to be achieved""" id = models.AutoField(primary_key=True) title = models.CharField(max_length=255) description = models.TextField(null=True) organization = models.ForeignKey(Organization, related_name='campaigns') start_date = models.DateField() end_date = models.DateField() default_lang = models.CharField(max_length=5, choices=LANGUAGES, verbose_name=_('language')) def __unicode__(self): return self.title.decode('utf-8') class Argumentary(models.Model): """Argumentary in a given language for a campaign""" id = models.AutoField(primary_key=True) campaign = models.ForeignKey(Campaign) lang = models.CharField(max_length=5, choices=LANGUAGES, verbose_name=_('language')) text = models.TextField(null=True) def __unicode__(self): args = {'lang': self.lang, 'title': self.campaign.title} return _('Argumentary in %(lang)s for %(title)s') % args class CampaignContact(models.Model): """List contact related to a campaign with a given weight""" id = models.AutoField(primary_key=True) campaign = models.ForeignKey(Campaign) contact = models.ForeignKey(Contact) weight = models.IntegerField(default=0) def __unicode__(self): args = {'contact': self.contact, 'title': self.campaign.title} return _('Contact %(contact)s on %(title)s') % args def all_groups(self): return [x.name for x in self.contact.groups.all()]