# HG changeset patch
# User Brian Neal
# Date 1245715860 0
# Node ID e249b5f9d180dbd9e3548699449f9bfb63d463b2
# Parent f882ac8ce255641c1805a8798747db6f039df0c3
#3, #4: clear caches when saving profile, bulletins, and news. Broke up the stuff on the home page for finer control of caching.
diff -r f882ac8ce255 -r e249b5f9d180 gpp/bio/models.py
--- a/gpp/bio/models.py Sun Jun 21 22:41:58 2009 +0000
+++ b/gpp/bio/models.py Tue Jun 23 00:11:00 2009 +0000
@@ -9,6 +9,7 @@
from django.contrib import auth
from django.conf import settings
from django.template.loader import render_to_string
+from django.core.cache import cache
def avatar_file_path_for_user(username, filename):
@@ -46,4 +47,5 @@
html = render_to_string('bio/markdown.html', {'data': self.signature})
self.signature_html = html.strip()
super(UserProfile, self).save(*args, **kwargs)
+ cache.delete('avatar_' + self.user.username)
diff -r f882ac8ce255 -r e249b5f9d180 gpp/bulletins/models.py
--- a/gpp/bulletins/models.py Sun Jun 21 22:41:58 2009 +0000
+++ b/gpp/bulletins/models.py Tue Jun 23 00:11:00 2009 +0000
@@ -5,34 +5,41 @@
import datetime
from django.db import models
from django.db.models import Q
+from django.core.cache import cache
class BulletinManager(models.Manager):
- """Manager for the Bulletin model."""
+ """Manager for the Bulletin model."""
- def get_current(self):
- now = datetime.datetime.now()
- return self.filter(
- Q(is_enabled=True),
- Q(start_date__lte=now),
- Q(end_date__isnull=True) | Q(end_date__gte=now))
+ def get_current(self):
+ now = datetime.datetime.now()
+ return self.filter(
+ Q(is_enabled=True),
+ Q(start_date__lte=now),
+ Q(end_date__isnull=True) | Q(end_date__gte=now))
class Bulletin(models.Model):
- """Model to represent site bulletins."""
- title = models.CharField(max_length=200)
- text = models.TextField()
- start_date = models.DateTimeField(db_index=True,
- help_text='Start date for when the bulletin will be active.',)
- end_date = models.DateTimeField(blank=True, null=True, db_index=True,
- help_text='End date for the bulletin. Leave blank to keep it open-ended.')
- is_enabled = models.BooleanField(default=True, db_index=True,
- help_text='Check to allow the bulletin to be viewed on the site.')
+ """Model to represent site bulletins."""
+ title = models.CharField(max_length=200)
+ text = models.TextField()
+ start_date = models.DateTimeField(db_index=True,
+ help_text='Start date for when the bulletin will be active.',)
+ end_date = models.DateTimeField(blank=True, null=True, db_index=True,
+ help_text='End date for the bulletin. Leave blank to keep it open-ended.')
+ is_enabled = models.BooleanField(default=True, db_index=True,
+ help_text='Check to allow the bulletin to be viewed on the site.')
- objects = BulletinManager()
+ objects = BulletinManager()
- def __unicode__(self):
- return self.title
+ class Meta:
+ ordering = ('-start_date', )
- class Meta:
- ordering = ('-start_date', )
+ def __unicode__(self):
+ return self.title
+
+ def save(self, force_insert=False, force_update=False):
+ super(Bulletin, self).save(force_insert, force_update)
+ cache.delete('home_bulletins')
+
+
diff -r f882ac8ce255 -r e249b5f9d180 gpp/news/models.py
--- a/gpp/news/models.py Sun Jun 21 22:41:58 2009 +0000
+++ b/gpp/news/models.py Tue Jun 23 00:11:00 2009 +0000
@@ -5,83 +5,89 @@
import datetime
from django.db import models
from django.contrib.auth.models import User
+from django.core.cache import cache
from tagging.fields import TagField
class Category(models.Model):
- """News stories belong to categories"""
- title = models.CharField(max_length = 64)
- icon = models.ImageField(upload_to='news/categories/', blank=True)
+ """News stories belong to categories"""
+ title = models.CharField(max_length = 64)
+ icon = models.ImageField(upload_to='news/categories/', blank=True)
- def __unicode__(self):
- return self.title
+ def __unicode__(self):
+ return self.title
- def num_stories(self):
- return News.objects.filter(category = self.pk).count()
+ def num_stories(self):
+ return News.objects.filter(category = self.pk).count()
- class Meta:
- verbose_name_plural = 'Categories'
- ordering = ('title', )
+ class Meta:
+ verbose_name_plural = 'Categories'
+ ordering = ('title', )
class PendingStory(models.Model):
- """Stories submitted by users are held pending admin approval"""
- title = models.CharField(max_length=255)
- submitter = models.ForeignKey(User)
- category = models.ForeignKey(Category)
- short_text = models.TextField()
- long_text = models.TextField(blank=True)
- date_submitted = models.DateTimeField(auto_now_add=True, db_index=True)
- allow_comments = models.BooleanField(default=True)
- approved = models.BooleanField(default=False)
- tags = TagField()
+ """Stories submitted by users are held pending admin approval"""
+ title = models.CharField(max_length=255)
+ submitter = models.ForeignKey(User)
+ category = models.ForeignKey(Category)
+ short_text = models.TextField()
+ long_text = models.TextField(blank=True)
+ date_submitted = models.DateTimeField(auto_now_add=True, db_index=True)
+ allow_comments = models.BooleanField(default=True)
+ approved = models.BooleanField(default=False)
+ tags = TagField()
- def save(self, force_insert = False, force_update = False):
- if self.approved:
- Story.objects.create(title=self.title,
- submitter=self.submitter,
- category=self.category,
- short_text=self.short_text,
- long_text=self.long_text,
- allow_comments=self.allow_comments,
- date_published=datetime.datetime.now(),
- tags=self.tags)
- self.delete()
- else:
- super(PendingStory, self).save(force_insert, force_update)
+ def save(self, force_insert = False, force_update = False):
+ if self.approved:
+ Story.objects.create(title=self.title,
+ submitter=self.submitter,
+ category=self.category,
+ short_text=self.short_text,
+ long_text=self.long_text,
+ allow_comments=self.allow_comments,
+ date_published=datetime.datetime.now(),
+ tags=self.tags)
+ self.delete()
+ cache.delete('home_news')
+ else:
+ super(PendingStory, self).save(force_insert, force_update)
- def __unicode__(self):
- return self.title
+ def __unicode__(self):
+ return self.title
- class Meta:
- ordering = ('-date_submitted', )
- verbose_name_plural = 'Pending Stories'
+ class Meta:
+ ordering = ('-date_submitted', )
+ verbose_name_plural = 'Pending Stories'
class Story(models.Model):
- """Model for news stories"""
- title = models.CharField(max_length=255)
- submitter = models.ForeignKey(User)
- category = models.ForeignKey(Category)
- short_text = models.TextField()
- long_text = models.TextField(blank=True)
- allow_comments = models.BooleanField(default=True)
- date_published = models.DateTimeField(db_index=True)
- tags = TagField()
+ """Model for news stories"""
+ title = models.CharField(max_length=255)
+ submitter = models.ForeignKey(User)
+ category = models.ForeignKey(Category)
+ short_text = models.TextField()
+ long_text = models.TextField(blank=True)
+ allow_comments = models.BooleanField(default=True)
+ date_published = models.DateTimeField(db_index=True)
+ tags = TagField()
- @models.permalink
- def get_absolute_url(self):
- return ('news.views.story', [str(self.id)])
+ @models.permalink
+ def get_absolute_url(self):
+ return ('news.views.story', [str(self.id)])
- def __unicode__(self):
- return self.title
+ def __unicode__(self):
+ return self.title
- class Meta:
- ordering = ('-date_published', )
- verbose_name_plural = 'Stories'
+ class Meta:
+ ordering = ('-date_published', )
+ verbose_name_plural = 'Stories'
- def can_comment_on(self):
- now = datetime.datetime.now()
- delta = now - self.date_published
- return delta.days < 30
+ def can_comment_on(self):
+ now = datetime.datetime.now()
+ delta = now - self.date_published
+ return delta.days < 30
+ def save(self, force_insert=False, force_update=False):
+ super(Story, self).save(force_insert, force_update)
+ cache.delete('home_news')
+
diff -r f882ac8ce255 -r e249b5f9d180 gpp/templates/home.html
--- a/gpp/templates/home.html Sun Jun 21 22:41:58 2009 +0000
+++ b/gpp/templates/home.html Tue Jun 23 00:11:00 2009 +0000
@@ -36,9 +36,13 @@
permanent. The site (content, user accounts, etc.) may be wiped at any time while we fix bugs and add features.
Also, I hope that the look and feel of this site can be greatly improved to something really cool! I'll need
lots of help for this aspect, as I'm more of a coder than a designer.
-{% cache 600 home_content %}
-{% current_bulletins %}
-{% current_news %}
+{% cache 3600 home_bulletins %}
+ {% current_bulletins %}
+{% endcache %}
+{% cache 3600 home_news %}
+ {% current_news %}
+{% endcache %}
+{% cache 3600 home_new_stuff %}
{% latest_weblinks %}