Author: adrian
Date: 2006-08-31 18:50:31 -0500 (Thu, 31 Aug 2006)
New Revision: 3700

Added:
   djangoproject.com/django_website/sitemaps.py
Modified:
   djangoproject.com/django_website/urls.py
Log:
First stab at sitemap for djangoproject.com

Added: djangoproject.com/django_website/sitemaps.py
===================================================================
--- djangoproject.com/django_website/sitemaps.py                                
(rev 0)
+++ djangoproject.com/django_website/sitemaps.py        2006-08-31 23:50:31 UTC 
(rev 3700)
@@ -0,0 +1,49 @@
+from django.contrib.sitemaps import Sitemap
+from django_website.apps.blog.models import Entry
+from django_website.apps.docs.models import Document
+from django.contrib.sites.models import Site
+import datetime
+
+class FlatPageSitemap(Sitemap):
+    """
+    We're not using the built-in django.contrib.sitemaps.FlatPageSitemap,
+    because we're doing something different. Also, we only have one Site,
+    so there's no need to check the site is current.
+    """
+    def changefreq(self, obj):
+        if obj.url.startswith('/documentation/0_90/') or 
obj.url.startswith('/documentation/0_91/'):
+            return 'never' # Old documentation never changes.
+        else:
+            return 'weekly'
+
+    def priority(self, obj):
+        if obj.url.startswith('/documentation/0_90/') or 
obj.url.startswith('/documentation/0_91/'):
+            return 0.1 # Old documentation gets a low priority.
+        else:
+            return 0.5
+
+    def items(self):
+        return Site.objects.all()
+
+    # lastmod is not implemented, because we have no way of knowing
+    # when FlatPages were last updated.
+
+class WeblogSitemap(Sitemap):
+    changefreq = 'never'
+    priority = 0.4
+
+    def items(self):
+        return Entry.objects.filter(pub_date__lte=datetime.datetime.now())
+
+    def lastmod(self, obj):
+        return obj.pub_date
+
+class DocumentationSitemap(Sitemap):
+    changefreq = 'weekly'
+    priority = 0.8
+
+    def items(self):
+        return Document.objects.all()
+
+    def lastmod(self, obj):
+        return obj.last_updated

Modified: djangoproject.com/django_website/urls.py
===================================================================
--- djangoproject.com/django_website/urls.py    2006-08-31 23:44:26 UTC (rev 
3699)
+++ djangoproject.com/django_website/urls.py    2006-08-31 23:50:31 UTC (rev 
3700)
@@ -4,6 +4,7 @@
 from django_website.apps.aggregator.feeds import CommunityAggregatorFeed
 from django_website.apps.aggregator.models import FeedItem
 from django_website.apps.blog.feeds import WeblogEntryFeed
+from django_website.sitemaps import FlatPageSitemap, WeblogSitemap, 
DocumentationSitemap
 
 comments_info_dict = {
     'queryset': FreeComment.objects.all(),
@@ -21,6 +22,12 @@
     'community': CommunityAggregatorFeed,
 }
 
+sitemaps = {
+    'weblog': WeblogSitemap,
+    'docs': DocumentationSitemap,
+    'flatpages': FlatPageSitemap,
+}
+
 urlpatterns = patterns('',
     (r'^weblog/', include('django_website.apps.blog.urls')),
     (r'^documentation/', include('django_website.apps.docs.urls')),
@@ -30,6 +37,7 @@
     (r'^rss/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', 
{'feed_dict': feeds}),
     (r'^password_reset/', include('django.conf.urls.admin_password_reset')),
     (r'^r/', include('django.conf.urls.shortcut')),
+    (r'^sitemap.xml$', 'django.contrib.sitemap.views.sitemap', {'sitemaps': 
sitemaps}),
     (r'^admin/', include('django.contrib.admin.urls')),
     (r'', include('django.contrib.flatpages.urls')),
 )


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates
-~----------~----~----~----~------~----~------~--~---

Reply via email to