B
    CVvg                 @   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-install-o3oxmrkh/Django/django/contrib/sitemaps/views.pyinner   s    
zx_robots_tag.<locals>.inner)r   )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 }x| D ]\}}	t|	r2|	 }	|	jd kr@|n|	j}
t|d|id}d|
|j|f }|| x,td|	j	j
d D ]}|d||f  qW qW 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   sZ  | j }t| }|d k	r6||kr*td| || g}n| }| jdd}d }	d}
g }x|D ]}yxt|rr| }||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^W t| |d
|i|d}|
rV|	d k	rVt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urlset)r   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   sB    

r9   )r   r   r   )Nr+   r   )r3   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*   r9   r   r   r   r   <module>   s   	  