summaryrefslogtreecommitdiffstats
path: root/news/models.py
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-04-07 21:39:14 +0200
committerDan McGee <dan@archlinux.org>2011-04-08 00:01:16 +0200
commit9f4902f9c921b82f924fe0af106fa5480ca10ca9 (patch)
tree489df7db006f43f6ab74bb191fe220012073c539 /news/models.py
parent0504fbeb92e83e92e1f1bc6e003bdb3f93c4318f (diff)
downloadarchweb-9f4902f9c921b82f924fe0af106fa5480ca10ca9.tar.gz
archweb-9f4902f9c921b82f924fe0af106fa5480ca10ca9.tar.xz
Ensure feed GUIDs are unchanging and unique
Implement 'tag:' style URIs for the GUID field on our RSS feeds. This ensures new package updates show up as new, and we aren't jumping back and forth between generated GUIDs having 'http://' and 'https://' prefixes. Much of the work here is to attempt to keep old news GUIDs constant so we don't once again make everything show up as new in newsreaders. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'news/models.py')
-rw-r--r--news/models.py24
1 files changed, 20 insertions, 4 deletions
diff --git a/news/models.py b/news/models.py
index c2d644b..c4fb136 100644
--- a/news/models.py
+++ b/news/models.py
@@ -1,13 +1,16 @@
+from datetime import datetime
+
from django.db import models
from django.contrib.auth.models import User
+from django.contrib.sites.models import Site
class News(models.Model):
slug = models.SlugField(max_length=255, unique=True)
author = models.ForeignKey(User, related_name='news_author')
- postdate = models.DateTimeField("post date", auto_now_add=True, db_index=True)
- last_modified = models.DateTimeField(editable=False,
- auto_now=True, db_index=True)
+ postdate = models.DateTimeField("post date", db_index=True)
+ last_modified = models.DateTimeField(editable=False, db_index=True)
title = models.CharField(max_length=255)
+ guid = models.CharField(max_length=255, editable=False)
content = models.TextField()
def get_absolute_url(self):
@@ -22,10 +25,23 @@ class News(models.Model):
get_latest_by = 'postdate'
ordering = ['-postdate']
+def set_news_fields(sender, **kwargs):
+ news = kwargs['instance']
+ now = datetime.now()
+ news.last_modified = now
+ if not news.postdate:
+ news.postdate = now
+ # http://diveintomark.org/archives/2004/05/28/howto-atom-id
+ news.guid = 'tag:%s,%s:%s' % (Site.objects.get_current(),
+ now.strftime('%Y-%m-%d'), news.get_absolute_url())
+
# connect signals needed to keep cache in line with reality
from main.utils import refresh_news_latest
-from django.db.models.signals import post_save
+from django.db.models.signals import pre_save, post_save
+
post_save.connect(refresh_news_latest, sender=News,
dispatch_uid="news.models")
+pre_save.connect(set_news_fields, sender=News,
+ dispatch_uid="news.models")
# vim: set ts=4 sw=4 et: