3
(h                 @   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|d< |S )Nznoindex, noodp, noarchivezX-Robots-Tag )requestargskwargsresponse)funcr   A/tmp/pip-install-q3hcpn_q/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|j D ]\}}	t|	r2|	 }	|	jd kr@|n|	j}
t|d|id}d|
|j|f }|j| x,td|	j	j
d D ]}|j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   sX  | j }t| }|d k	r6||kr*td| || g}n|j }| jjdd}d }	d}
g }x|D ]}yxt|rr| }|j|j|||d |
rt	|dd }|d k	rt
|tjr|j n|j }|	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}|
rT|	d k	rTtt|	|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%   mapsr(   ZlastmodZall_sites_lastmodurlsr'   Zsite_lastmodr   r   r   r   sitemap-   sB    

r8   )r   r   r   )Nr*   r   )r2   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)   r8   r   r   r   r   <module>   s   	  