| 117 | return self.lastmod |
| 118 | |
| 119 | def _urls(self, page, protocol, domain): |
| 120 | urls = [] |
| 121 | latest_lastmod = None |
| 122 | all_items_lastmod = True # track if all items have a lastmod |
| 123 | |
| 124 | paginator_page = self.paginator.page(page) |
| 125 | for item in paginator_page.object_list: |
| 126 | loc = f"{protocol}://{domain}{self._location(item)}" |
| 127 | priority = self._get("priority", item) |
| 128 | lastmod = self._get("lastmod", item) |
| 129 | |
| 130 | if all_items_lastmod: |
| 131 | all_items_lastmod = lastmod is not None |
| 132 | if all_items_lastmod and ( |
| 133 | latest_lastmod is None or lastmod > latest_lastmod |
| 134 | ): |
| 135 | latest_lastmod = lastmod |
| 136 | |
| 137 | url_info = { |
| 138 | "item": item, |
| 139 | "location": loc, |
| 140 | "lastmod": lastmod, |
| 141 | "changefreq": self._get("changefreq", item), |
| 142 | "priority": str(priority if priority is not None else ""), |
| 143 | "alternates": [], |
| 144 | } |
| 145 | |
| 146 | if self.i18n and self.alternates: |
| 147 | item_languages = self.get_languages_for_item(item[0]) |
| 148 | for lang_code in item_languages: |
| 149 | loc = f"{protocol}://{domain}{self._location(item, lang_code)}" |
| 150 | url_info["alternates"].append( |
| 151 | { |
| 152 | "location": loc, |
| 153 | "lang_code": lang_code, |
| 154 | } |
| 155 | ) |
| 156 | if self.x_default and settings.LANGUAGE_CODE in item_languages: |
| 157 | lang_code = settings.LANGUAGE_CODE |
| 158 | loc = f"{protocol}://{domain}{self._location(item, lang_code)}" |
| 159 | loc = loc.replace(f"/{lang_code}/", "/", 1) |
| 160 | url_info["alternates"].append( |
| 161 | { |
| 162 | "location": loc, |
| 163 | "lang_code": "x-default", |
| 164 | } |
| 165 | ) |
| 166 | |
| 167 | urls.append(url_info) |
| 168 | |
| 169 | if all_items_lastmod and latest_lastmod: |
| 170 | self.latest_lastmod = latest_lastmod |
| 171 | |
| 172 | return urls |
| 173 | |
| 174 | |
| 175 | class GenericSitemap(Sitemap): |