diff --git a/django/contrib/sitemaps/__init__.py b/django/contrib/sitemaps/__init__.py
index 747cd1d..c14473a 100644
|
a
|
b
|
from django.contrib.sites.models import Site
|
| 2 | 2 | from django.core import urlresolvers, paginator |
| 3 | 3 | from django.core.exceptions import ImproperlyConfigured |
| 4 | 4 | import urllib |
| | 5 | from datetime import timedelta |
| | 6 | from django.utils.timezone import now |
| 5 | 7 | |
| 6 | 8 | PING_URL = "http://www.google.com/webmasters/tools/ping" |
| 7 | 9 | |
| … |
… |
class Sitemap(object):
|
| 39 | 41 | # This limit is defined by Google. See the index documentation at |
| 40 | 42 | # http://sitemaps.org/protocol.php#index. |
| 41 | 43 | limit = 50000 |
| | 44 | counter_delta = timedelta(seconds = 60) |
| | 45 | reload_delta = timedelta(seconds = 600) |
| 42 | 46 | |
| 43 | 47 | # If protocol is None, the URLs in the sitemap will use the protocol |
| 44 | 48 | # with which the sitemap was requested. |
| … |
… |
class Sitemap(object):
|
| 59 | 63 | def location(self, obj): |
| 60 | 64 | return obj.get_absolute_url() |
| 61 | 65 | |
| | 66 | def _paginator_reload(self, __now): |
| | 67 | """ |
| | 68 | Determines whether to recreate paginator. Called from _get_paginator, |
| | 69 | can be overriden in child classes. |
| | 70 | |
| | 71 | Arguments: |
| | 72 | __now -- current timestamp |
| | 73 | """ |
| | 74 | return ( |
| | 75 | # paginator very old or |
| | 76 | (self.__paginator_validate_timestamp > __now) or |
| | 77 | # paginator not so new and items count in DB changed |
| | 78 | (self.__counter_validate_timestamp > __now and self.__counter != len(self.items()))) |
| | 79 | |
| 62 | 80 | def _get_paginator(self): |
| 63 | | if not hasattr(self, "_paginator"): |
| | 81 | __now = now() |
| | 82 | if not hasattr(self, "_paginator") or self._paginator_reload(__now): |
| | 83 | self.__counter_validate_timestamp = __now + self.counter_delta |
| | 84 | self.__paginator_validate_timestamp = __now + self.reload_delta |
| | 85 | self.__counter = len(self.items()) |
| 64 | 86 | self._paginator = paginator.Paginator(self.items(), self.limit) |
| 65 | 87 | return self._paginator |
| 66 | 88 | paginator = property(_get_paginator) |
diff --git a/docs/ref/contrib/sitemaps.txt b/docs/ref/contrib/sitemaps.txt
index ac9f8ab..d9b99c6 100644
|
a
|
b
|
Sitemap class reference
|
| 131 | 131 | |
| 132 | 132 | A ``Sitemap`` class can define the following methods/attributes: |
| 133 | 133 | |
| | 134 | .. attribute:: Sitemap.reload_delta |
| | 135 | |
| | 136 | Timedelta between recreation paginator storing objects from database. |
| | 137 | Default 600 seconds. |
| | 138 | |
| | 139 | .. attribute:: Sitemap.counter_delta |
| | 140 | |
| | 141 | Timedelta between checks whether number of database objects stored |
| | 142 | in paginator differs from number in database. Difference means |
| | 143 | paginator recreation. Default 60 seconds. |
| | 144 | |
| | 145 | .. attribute:: Sitemap._paginator_reload |
| | 146 | |
| | 147 | Function governing whether to create new paginator replacing existing one. |
| | 148 | Can be overridden in child classes. |
| | 149 | |
| 134 | 150 | .. attribute:: Sitemap.items |
| 135 | 151 | |
| 136 | 152 | **Required.** A method that returns a list of objects. The framework |