U
    Ha                     @   s   d dl Z d dlmZ d dlmZ d dlmZ d dlmZm	Z	 d dl
mZ d dlmZ d dlmZ d d	lmZ d
d ZedddZedddZdS )    N)timegmwraps)get_current_site)	EmptyPagePageNotAnInteger)Http404)TemplateResponse)reverse)	http_datec                    s   t   fdd}|S )Nc                    s    | f||}d|j d< |S )Nznoindex, noodp, noarchivezX-Robots-Tag)headers)requestargskwargsresponsefunc A/tmp/pip-unpacked-wheel-3jxiddxt/django/contrib/sitemaps/views.pyinner   s    
zx_robots_tag.<locals>.innerr   )r   r   r   r   r   x_robots_tag   s    r   sitemap_index.xmlapplication/xml%django.contrib.sitemaps.views.sitemapc                 C   s   | j }t| }g }| D ]~\}}	t|	r0|	 }	|	jd kr>|n|	j}
t|d|id}d|
|j|f }|| td|	j	j
d D ]}|d||f  qqt| |d|i|dS )	Nsection)r   z	%s://%s%s      z%s?p=%ssitemapscontent_type)schemer   itemscallableprotocolr
   domainappendrangeZ	paginatorZ	num_pagesr	   )r   r   template_namer   Zsitemap_url_namereq_protocolreq_sitesitesr   siter#   Zsitemap_urlZabsolute_urlpager   r   r   index   s    
r-   sitemap.xmlc              	   C   sV  | j }t| }|d k	r6||kr*td| || g}n| }| jdd}d }	d}
g }|D ]}zxt|rp| }||j|||d |
rt	|dd }|d k	rt
|tjr| n| }|	d kr|nt|	|}	nd}
W q\ tk
r   td| Y q\ tk
r   td	| Y q\X q\t| |d
|i|d}|
rR|	d k	rRtt|	|jd< |S )Nz$No sitemap available for section: %rpr   T)r,   r+   r#   Zlatest_lastmodFzPage %s emptyzNo page '%s'Zurlsetr   zLast-Modified)r    r   r   valuesGETgetr"   extendZget_urlsgetattr
isinstancedatetimeutctimetuple	timetuplemaxr   r   r	   r   r   r   )r   r   r   r'   r   r(   r)   mapsr,   ZlastmodZall_sites_lastmodurlsr+   Zsite_lastmodr   r   r   r   sitemap0   sH    r<   )r   r   r   )Nr.   r   )r6   calendarr   	functoolsr   Zdjango.contrib.sites.shortcutsr   Zdjango.core.paginatorr   r   Zdjango.httpr   Zdjango.template.responser	   Zdjango.urlsr
   Zdjango.utils.httpr   r   r-   r<   r   r   r   r   <module>   s&   	        