Permalink
Browse files

added sitemaps

  • Loading branch information...
1 parent beb14c4 commit 003fc6840364f01e05e792f4d03e6fd812309996 @dduan committed Jun 10, 2010
Showing with 37 additions and 1 deletion.
  1. +1 −1 sophie/__init__.py
  2. +4 −0 sophie/models.py
  3. +18 −0 sophie/sitemaps.py
  4. +14 −0 sophie/urls.py
View
@@ -1 +1 @@
-VERSION = (0, 0, 3)
+VERSION = (0, 0, 4)
View
@@ -19,6 +19,10 @@ class Meta:
def __unicode__(self):
return self.title
+ @models.permalink
+ def get_aboslute_url(self):
+ return ('index_view', (), { 'blog_slug': self.slug })
+
class Category(models.Model):
title = models.CharField(max_length = 200)
description = models.TextField(blank = True)
View
@@ -0,0 +1,18 @@
+from django.contrib.sitemaps import Sitemap
+from sophie.models import Entry
+
+class BlogSitemap(Sitemap):
+ " sitemap section for a blog "
+ changefreq = "weekly"
+ priority = 1.0
+
+ def __init__(self, blog):
+ " here blog is a Sophie.Blog instance "
+ this.blog = blog
+ super(BlogSitemap, self).__init__()
+
+ def items(self):
+ return Entry.live.filter( blog = self.blog )
+
+ def lastmod(self, obj):
+ return obj.last_updated
View
@@ -1,4 +1,5 @@
from django.conf.urls.defaults import *
+from sophie.models import Blog
# Page urls
urlpatterns = patterns('sophie.views',
@@ -24,3 +25,16 @@
url(r'^((?P<blog_slug>)/)?category/(?P<category_slug>\w+)/feed/$',
'CategoryFeed', name='blog_feed'),
)
+
+# Sitemap urls
+
+sitemaps = {}
+
+blogs = Blog.objects.all()
+
+for blog in blogs:
+ sitemaps[blog.slug] = BlogSitemap(blog)
+
+urlpatterns += patterns(''
+ (r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap',
+ { 'sitemaps': sitemaps } )

0 comments on commit 003fc68

Please sign in to comment.