o
    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$    | g|R i |}d|j d< |S )Nznoindex, noodp, noarchivezX-Robots-Tag)headers)requestargskwargsresponsefunc e/var/www/html/magazine_api/magazine_env/lib/python3.10/site-packages/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|	r|	 }	|	jd u r|n|	j}
t|d|id}d|
|j|f }|| td|	j	j
d D ]}|d||f  q@q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   sB  | j }t| }|d ur||vrtd| || g}n| }| jdd}d }	d}
g }|D ]W}z<t|r8| }||j|||d |
rkt	|dd }|d urit
|tjrY| n| }|	d u rc|nt|	|}	nd}
W q. tyy   td|  ty   td	| w t| |d
|i|d}|
r|	d urt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   sL   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$    	