Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

First stab at sitemap for djangoproject.com

git-svn-id: http://code.djangoproject.com/svn/djangoproject.com@3700 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6799abe38847a0d25ce245c24a55b96da6aa3834 1 parent 93fea7c
adrian authored
Showing with 57 additions and 0 deletions.
  1. +49 −0 django_website/sitemaps.py
  2. +8 −0 django_website/urls.py
View
49 django_website/sitemaps.py
@@ -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
View
8 django_website/urls.py
@@ -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')),
)
Please sign in to comment.
Something went wrong with that request. Please try again.