Add sitemap
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Tue, 18 Dec 2012 12:30:13 +0000 (13:30 +0100)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Tue, 18 Dec 2012 12:30:13 +0000 (13:30 +0100)
migdal/sitemap.py [new file with mode: 0755]
migdal/urls.py

diff --git a/migdal/sitemap.py b/migdal/sitemap.py
new file mode 100755 (executable)
index 0000000..7da7c38
--- /dev/null
@@ -0,0 +1,26 @@
+from django.contrib.sitemaps import Sitemap
+from django.utils.translation import override
+from .models import Entry
+from django.conf import settings
+
+class MigdalSitemap(Sitemap):
+    changefreq = "never"
+    priority = 0.5
+
+    def __init__(self, lang):
+        self.lang = lang
+
+    def items(self):
+        return Entry.objects.filter(**{"published_%s" % self.lang: True})
+
+    def lastmod(self, obj):
+        return obj.changed_at
+
+    def location(self, obj):
+        with override(self.lang):
+            return obj.get_absolute_url()
+
+
+sitemaps = {}
+for lc, ln in settings.LANGUAGES:
+    sitemaps['entry_%s' % lc] = MigdalSitemap(lc)
index 49a4346..dbf144b 100644 (file)
@@ -2,6 +2,7 @@
 # This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later.
 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
 #
+from django.conf import settings
 from django.conf.urls import patterns, include, url, handler404
 from django.utils.translation import ugettext_lazy as _
 from django.utils.translation import string_concat
@@ -42,3 +43,13 @@ urlpatterns = i18n_patterns('',
     # type-specific views
     *pats
 )
+
+
+if 'django.contrib.sitemaps' in settings.INSTALLED_APPS:
+    from .sitemap import sitemaps
+    urlpatterns += patterns('',
+        url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {
+            'sitemaps': sitemaps
+        }),
+    )
+