U
    5i;                     @   s   d dl 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	lmZ d
d ZedddZedddZdS )    Nwraps)get_current_site)	EmptyPagePageNotAnInteger)Http404)TemplateResponse)reverse)timezone)	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-gcyiijx6/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   sr  | j }t| }|d k	r6||kr*td| || g}n| }| jdd}d }	d}
g }|D ]}zt|rp| }||j|||d |
rt	|dd }|d k	rt
|tjstj|tjj}t|rt|tj}|	d kr|nt|	|}	nd}
W q\ tk
r   td| Y q\ tk
r4   td	| Y q\X q\t| |d
|i|d}|
rn|	d k	rnt|	 |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combinetimeminr
   Zis_naiveZ
make_awareutcmaxr   r   r   r   	timestampr   )r   r   r   r'   r   r(   r)   mapsr,   ZlastmodZall_sites_lastmodurlsr+   Zsite_lastmodr   r   r   r   sitemap0   sJ    
r?   )r   r   r   )Nr.   r   )r6   	functoolsr   Zdjango.contrib.sites.shortcutsr   Zdjango.core.paginatorr   r   Zdjango.httpr   Zdjango.template.responser   Zdjango.urlsr	   Zdjango.utilsr
   Zdjango.utils.httpr   r   r-   r?   r   r   r   r   <module>   s&   	        