o
    [h1                     @   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
lmZ eG dd dZdd Zdd Ze			dddZe			dddZdS )    N)	dataclasswraps)get_current_site)	EmptyPagePageNotAnInteger)Http404)TemplateResponse)reverse)timezone)	http_datec                   @   s"   e Zd ZU eed< dZeed< dS )SitemapIndexItemlocationNlast_mod)__name__
__module____qualname__str__annotations__r   bool r   r   /home/ubuntu/experiments/live_experiments/Pythonexperiments/Otree/venv/lib/python3.10/site-packages/django/contrib/sitemaps/views.pyr      s   
 r   c                    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funcr   r   inner   s   
zx_robots_tag.<locals>.innerr   )r   r   r   r   r   x_robots_tag   s   r    c                 C   sN   t |tjstj|tjj}t|rt|tjj}| du r"|S t	| |S )z^
    Returns the latest `lastmod` where `lastmod` can be either a date or a
    datetime.
    N)

isinstancedatetimecombinetimeminr   Zis_naiveZ
make_awareutcmax)Zcurrent_lastmodZnew_lastmodr   r   r   _get_latest_lastmod   s
   
r(   sitemap_index.xmlapplication/xml%django.contrib.sitemaps.views.sitemapc                 C   s  | j }t| }g }d}d }	| D ]W\}
}t|r| }|jd u r#|n|j}t|d|
id}d||j|f }| }|rH|d urFt|	|}	nd}|	t
|| td|jjd D ]}|	t
d||f | qYq|rv|	rvd	t|	 i}nd }t| |d
|i||dS )NTsection)r   z	%s://%s%sF      z%s?p=%sLast-Modifiedsitemapscontent_typer   )schemer   itemscallableprotocolr
   domainZget_latest_lastmodr(   appendr   rangeZ	paginatorZ	num_pagesr   	timestampr	   )r   r0   template_namer2   Zsitemap_url_namereq_protocolreq_sitesitesZall_indexes_lastmodlatest_lastmodr,   siter6   Zsitemap_urlZabsolute_urlsite_lastmodpager   r   r   r   index*   s@   rC   sitemap.xmlc              	   C   s  | j }t| }|d ur||vrtd| || g}n| }| jdd}d }	d}
g }|D ]C}z(t|r8| }||j|||d |
rWt	|dd }|d urUt
|	|}	nd}
W q. tye   td|  tyq   td	| w |
r|	r~d
t|	 ind }nd }t| |d|i||dS )Nz$No sitemap available for section: %rpr.   T)rB   r@   r6   r?   FzPage %s emptyzNo page '%s'r/   Zurlsetr1   )r3   r   r   valuesGETgetr5   extendZget_urlsgetattrr(   r   r   r   r:   r	   )r   r0   r,   r;   r2   r<   r=   mapsrB   ZlastmodZall_sites_lastmodurlsr@   rA   r   r   r   r   sitemap[   sJ   rM   )r)   r*   r+   )NrD   r*   )r"   dataclassesr   	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(   rC   rM   r   r   r   r   <module>   s0    
0