Ticket #25989: views.py.diff

File views.py.diff, 1.6 KB (added by allixx, 9 years ago)

django/contrib/sitemaps/views.py

  • views.py

    old new  
    5858        maps = sitemaps.values()
    5959    page = request.GET.get("p", 1)
    6060
     61    lastmod = None
     62
    6163    urls = []
    6264    for site in maps:
    6365        try:
     
    6567                site = site()
    6668            urls.extend(site.get_urls(page=page, site=req_site,
    6769                                      protocol=req_protocol))
     70
     71            if hasattr(site, 'latest_lastmod'):
     72                site_lastmod = site.latest_lastmod
     73
     74                if type(site_lastmod) is datetime.date:
     75                    site_lastmod = datetime.datetime(site_lastmod.year,
     76                                                        site_lastmod.month,
     77                                                        site_lastmod.day)
     78
     79                if lastmod is None or lastmod < site_lastmod:
     80                    lastmod = site_lastmod
     81
    6882        except EmptyPage:
    6983            raise Http404("Page %s empty" % page)
    7084        except PageNotAnInteger:
    7185            raise Http404("No page '%s'" % page)
    7286    response = TemplateResponse(request, template_name, {'urlset': urls},
    7387                                content_type=content_type)
    74     if hasattr(site, 'latest_lastmod'):
    75         # if latest_lastmod is defined for site, set header so as
     88    if lastmod is not None:
     89        # if lastmod is defined for at least one site, set header so as
    7690        # ConditionalGetMiddleware is able to send 304 NOT MODIFIED
    77         lastmod = site.latest_lastmod
    7891        response['Last-Modified'] = http_date(
    7992            timegm(
    8093                lastmod.utctimetuple() if isinstance(lastmod, datetime.datetime)
Back to Top