#NEWLINE# @ x_robots_tag #NEWLINE# def sitemap( request , sitemaps , section = None , template_name = 'sitemap.xml' , content_type = 'application/xml' ) : #NEWLINE# #INDENT# req_protocol = request . scheme #NEWLINE# req_site = get_current_site ( request ) #NEWLINE# if ( section is not None ) : #NEWLINE# #INDENT# if ( section not in sitemaps ) : #NEWLINE# #INDENT# raise Http404 ( ( 'No sitemap available for section: %r' % section ) ) #NEWLINE# #UNINDENT# maps = [ sitemaps [ section ] ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# maps = sitemaps . values ( ) #NEWLINE# #UNINDENT# page = request . GET . get ( 'p' , 1 ) #NEWLINE# lastmod = None #NEWLINE# all_sites_lastmod = True #NEWLINE# urls = [ ] #NEWLINE# for site in maps : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# if callable ( site ) : #NEWLINE# #INDENT# site = site ( ) #NEWLINE# #UNINDENT# urls . extend ( site . get_urls ( page = page , site = req_site , protocol = req_protocol ) ) #NEWLINE# if all_sites_lastmod : #NEWLINE# #INDENT# site_lastmod = getattr ( site , 'latest_lastmod' , None ) #NEWLINE# if ( site_lastmod is not None ) : #NEWLINE# #INDENT# site_lastmod = ( site_lastmod . utctimetuple ( ) if isinstance ( site_lastmod , datetime . datetime ) else site_lastmod . timetuple ( ) ) #NEWLINE# lastmod = ( site_lastmod if ( lastmod is None ) else max ( lastmod , site_lastmod ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# all_sites_lastmod = False #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except EmptyPage : #NEWLINE# #INDENT# raise Http404 ( ( 'Page %s empty' % page ) ) #NEWLINE# #UNINDENT# except PageNotAnInteger : #NEWLINE# #INDENT# raise Http404 ( ( "No page '%s'" % page ) ) #NEWLINE# #UNINDENT# #UNINDENT# response = TemplateResponse ( request , template_name , { #NEWLINE# #INDENT# 'urlset' : urls , #NEWLINE# #UNINDENT# } , content_type = content_type ) #NEWLINE# if ( all_sites_lastmod and ( lastmod is not None ) ) : #NEWLINE# #INDENT# response [ 'Last-Modified' ] = http_date ( timegm ( lastmod ) ) #NEWLINE# #UNINDENT# return response