(
request,
sitemaps,
template_name="sitemap_index.xml",
content_type="application/xml",
sitemap_url_name="django.contrib.sitemaps.views.sitemap",
)
| 41 | |
| 42 | @x_robots_tag |
| 43 | def index( |
| 44 | request, |
| 45 | sitemaps, |
| 46 | template_name="sitemap_index.xml", |
| 47 | content_type="application/xml", |
| 48 | sitemap_url_name="django.contrib.sitemaps.views.sitemap", |
| 49 | ): |
| 50 | req_protocol = request.scheme |
| 51 | req_site = get_current_site(request) |
| 52 | |
| 53 | sites = [] # all sections' sitemap URLs |
| 54 | all_indexes_lastmod = True |
| 55 | latest_lastmod = None |
| 56 | for section, site in sitemaps.items(): |
| 57 | # For each section label, add links of all pages of its sitemap |
| 58 | # (usually generated by the `sitemap` view). |
| 59 | if callable(site): |
| 60 | site = site() |
| 61 | protocol = req_protocol if site.protocol is None else site.protocol |
| 62 | sitemap_url = reverse(sitemap_url_name, kwargs={"section": section}) |
| 63 | absolute_url = "%s://%s%s" % (protocol, req_site.domain, sitemap_url) |
| 64 | site_lastmod = site.get_latest_lastmod() |
| 65 | if all_indexes_lastmod: |
| 66 | if site_lastmod is not None: |
| 67 | latest_lastmod = _get_latest_lastmod(latest_lastmod, site_lastmod) |
| 68 | else: |
| 69 | all_indexes_lastmod = False |
| 70 | sites.append(SitemapIndexItem(absolute_url, site_lastmod)) |
| 71 | # Add links to all pages of the sitemap. |
| 72 | for page in range(2, site.paginator.num_pages + 1): |
| 73 | sites.append( |
| 74 | SitemapIndexItem("%s?p=%s" % (absolute_url, page), site_lastmod) |
| 75 | ) |
| 76 | # If lastmod is defined for all sites, set header so as |
| 77 | # ConditionalGetMiddleware is able to send 304 NOT MODIFIED |
| 78 | if all_indexes_lastmod and latest_lastmod: |
| 79 | headers = {"Last-Modified": http_date(latest_lastmod.timestamp())} |
| 80 | else: |
| 81 | headers = None |
| 82 | return TemplateResponse( |
| 83 | request, |
| 84 | template_name, |
| 85 | {"sitemaps": sites}, |
| 86 | content_type=content_type, |
| 87 | headers=headers, |
| 88 | ) |
| 89 | |
| 90 | |
| 91 | @x_robots_tag |
nothing calls this directly
no test coverage detected