Files
postgres-web/pgweb/news/models.py
Magnus Hagander f92709d2a6 Implement basic varnish purging
This allows all models inherited from PgModel to specify which
URLs to purge by either setting a field or defining a function
called purge_urls, at which point they will be purged whenever
the save signal is fired.

Also implements a form under /admin/purge/ that allows for manual
purging. This should probably be extended in the future to show
the status of the pgq slaves, but that will come later.

Includes a SQL function that posts the expires to a pgq queue. For
a local deployment, this can be replaced with a simple void function
to turn off varnish purging.
2011-06-14 19:48:48 +02:00

36 lines
1008 B
Python

from django.db import models
from datetime import date
from pgweb.core.models import Organisation
from pgweb.util.bases import PgModel
class NewsArticle(PgModel, models.Model):
org = models.ForeignKey(Organisation, null=False, blank=False)
approved = models.BooleanField(null=False, blank=False, default=False)
date = models.DateField(null=False, blank=False, default=date.today)
title = models.CharField(max_length=200, null=False, blank=False)
content = models.TextField(null=False, blank=False)
send_notification = True
markdown_fields = ('content',)
def purge_urls(self):
yield '/about/news/%s/' % self.pk
yield '/about/newsarchive/'
yield 'news.rss'
# FIXME: when to expire the front page?
yield '/$'
def __unicode__(self):
return "%s: %s" % (self.date, self.title)
def verify_submitter(self, user):
return (len(self.org.managers.filter(pk=user.pk)) == 1)
def is_migrated(self):
if self.org.pk == 0:
return True
return False
class Meta:
ordering = ('-date',)