测试gitnore

This commit is contained in:
ladeng07
2022-05-06 15:45:57 +08:00
parent 12f390949b
commit 51552904f9
2347 changed files with 120102 additions and 53549 deletions
@@ -1,4 +1,5 @@
import datetime
from calendar import timegm
from functools import wraps
from django.contrib.sites.shortcuts import get_current_site
@@ -6,7 +7,6 @@ from django.core.paginator import EmptyPage, PageNotAnInteger
from django.http import Http404
from django.template.response import TemplateResponse
from django.urls import reverse
from django.utils import timezone
from django.utils.http import http_date
@@ -14,20 +14,15 @@ def x_robots_tag(func):
@wraps(func)
def inner(request, *args, **kwargs):
response = func(request, *args, **kwargs)
response.headers["X-Robots-Tag"] = "noindex, noodp, noarchive"
response.headers['X-Robots-Tag'] = 'noindex, noodp, noarchive'
return response
return inner
@x_robots_tag
def index(
request,
sitemaps,
template_name="sitemap_index.xml",
content_type="application/xml",
sitemap_url_name="django.contrib.sitemaps.views.sitemap",
):
def index(request, sitemaps,
template_name='sitemap_index.xml', content_type='application/xml',
sitemap_url_name='django.contrib.sitemaps.views.sitemap'):
req_protocol = request.scheme
req_site = get_current_site(request)
@@ -39,26 +34,20 @@ def index(
if callable(site):
site = site()
protocol = req_protocol if site.protocol is None else site.protocol
sitemap_url = reverse(sitemap_url_name, kwargs={"section": section})
absolute_url = "%s://%s%s" % (protocol, req_site.domain, sitemap_url)
sitemap_url = reverse(sitemap_url_name, kwargs={'section': section})
absolute_url = '%s://%s%s' % (protocol, req_site.domain, sitemap_url)
sites.append(absolute_url)
# Add links to all pages of the sitemap.
for page in range(2, site.paginator.num_pages + 1):
sites.append("%s?p=%s" % (absolute_url, page))
sites.append('%s?p=%s' % (absolute_url, page))
return TemplateResponse(
request, template_name, {"sitemaps": sites}, content_type=content_type
)
return TemplateResponse(request, template_name, {'sitemaps': sites},
content_type=content_type)
@x_robots_tag
def sitemap(
request,
sitemaps,
section=None,
template_name="sitemap.xml",
content_type="application/xml",
):
def sitemap(request, sitemaps, section=None,
template_name='sitemap.xml', content_type='application/xml'):
req_protocol = request.scheme
req_site = get_current_site(request)
@@ -78,30 +67,26 @@ def sitemap(
try:
if callable(site):
site = site()
urls.extend(site.get_urls(page=page, site=req_site, protocol=req_protocol))
urls.extend(site.get_urls(page=page, site=req_site,
protocol=req_protocol))
if all_sites_lastmod:
site_lastmod = getattr(site, "latest_lastmod", None)
site_lastmod = getattr(site, 'latest_lastmod', None)
if site_lastmod is not None:
if not isinstance(site_lastmod, datetime.datetime):
site_lastmod = datetime.datetime.combine(
site_lastmod, datetime.time.min
)
if timezone.is_naive(site_lastmod):
site_lastmod = timezone.make_aware(site_lastmod, timezone.utc)
lastmod = (
site_lastmod if lastmod is None else max(lastmod, site_lastmod)
site_lastmod = (
site_lastmod.utctimetuple() if isinstance(site_lastmod, datetime.datetime)
else site_lastmod.timetuple()
)
lastmod = site_lastmod if lastmod is None else max(lastmod, site_lastmod)
else:
all_sites_lastmod = False
except EmptyPage:
raise Http404("Page %s empty" % page)
except PageNotAnInteger:
raise Http404("No page '%s'" % page)
response = TemplateResponse(
request, template_name, {"urlset": urls}, content_type=content_type
)
response = TemplateResponse(request, template_name, {'urlset': urls},
content_type=content_type)
if all_sites_lastmod and lastmod is not None:
# if lastmod is defined for all sites, set header so as
# ConditionalGetMiddleware is able to send 304 NOT MODIFIED
response.headers["Last-Modified"] = http_date(lastmod.timestamp())
response.headers['Last-Modified'] = http_date(timegm(lastmod))
return response