app/django/contrib/sitemaps/__init__.py
changeset 323 ff1a9aa48cfd
parent 54 03e267d67478
--- a/app/django/contrib/sitemaps/__init__.py	Tue Oct 14 12:36:55 2008 +0000
+++ b/app/django/contrib/sitemaps/__init__.py	Tue Oct 14 16:00:59 2008 +0000
@@ -1,4 +1,4 @@
-from django.core import urlresolvers
+from django.core import urlresolvers, paginator
 import urllib
 
 PING_URL = "http://www.google.com/webmasters/tools/ping"
@@ -33,7 +33,11 @@
     params = urllib.urlencode({'sitemap':url})
     urllib.urlopen("%s?%s" % (ping_url, params))
 
-class Sitemap:
+class Sitemap(object):
+    # This limit is defined by Google. See the index documentation at
+    # http://sitemaps.org/protocol.php#index.
+    limit = 50000
+
     def __get(self, name, obj, default=None):
         try:
             attr = getattr(self, name)
@@ -49,11 +53,17 @@
     def location(self, obj):
         return obj.get_absolute_url()
 
-    def get_urls(self):
+    def _get_paginator(self):
+        if not hasattr(self, "_paginator"):
+            self._paginator = paginator.Paginator(self.items(), self.limit)
+        return self._paginator
+    paginator = property(_get_paginator)
+
+    def get_urls(self, page=1):
         from django.contrib.sites.models import Site
         current_site = Site.objects.get_current()
         urls = []
-        for item in self.items():
+        for item in self.paginator.page(page).object_list:
             loc = "http://%s%s" % (current_site.domain, self.__get('location', item))
             url_info = {
                 'location':   loc,