class PoliticianAlert(models.Model): email = models.EmailField('Your e-mail') politician = models.ForeignKey(Politician) active = models.BooleanField(default=False) created = models.DateTimeField(default=datetime.datetime.now) objects = models.Manager() public = ActiveManager() def get_key(self): h = hashlib.sha1() h.update(str(self.id)) h.update(self.email) h.update(settings.SECRET_KEY) return base64.urlsafe_b64encode(h.digest()).replace('=', '') @models.permalink def get_unsubscribe_url(self): return ('parliament.alerts.views.unsubscribe_old', [], { 'alert_id': self.id, 'key': self.get_key() }) def __unicode__(self): return u"%s for %s (%s)" % \ (self.email, self.politician.name, 'active' if self.active else 'inactive')
class SiteNews(models.Model): """Entries for the semi-blog on the openparliament homepage.""" date = models.DateTimeField(default=datetime.datetime.now) title = models.CharField(max_length=200) text = models.TextField() active = models.BooleanField(default=True) objects = models.Manager() public = ActiveManager() class Meta: ordering = ('-date', )
class PoliticianAlert(models.Model): email = models.EmailField('Your e-mail') politician = models.ForeignKey(Politician, on_delete=models.CASCADE) active = models.BooleanField(default=False) created = models.DateTimeField(default=datetime.datetime.now) objects = models.Manager() public = ActiveManager() def get_key(self): h = hashlib.sha1() h.update(str(self.id)) h.update(self.email) h.update(settings.SECRET_KEY) return base64.urlsafe_b64encode(h.digest()).replace('=', '') def __unicode__(self): return "%s for %s (%s)" % \ (self.email, self.politician.name, 'active' if self.active else 'inactive')
class Activity(models.Model): date = models.DateField(db_index=True) variety = models.CharField(max_length=15) politician = models.ForeignKey(Politician) payload = models.TextField() guid = models.CharField(max_length=50, db_index=True, unique=True) active = models.BooleanField(default=True, db_index=True) objects = models.Manager() public = ActiveManager() class Meta: ordering = ('-date','-id') verbose_name_plural = 'Activities' def payload_wrapped(self): return u'<p class="activity_item" data-id="%s">%s</p>' % (self.pk, self.payload)