o
    Ti                     @   s   d dl Z 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 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)RemovedInDjango50Warning)	http_datec                   @   s*   e Zd ZU eed< dZeed< dd ZdS )SitemapIndexItemlocationNlast_modc                 C   s   d}t j|tdd | jS )NzZCalling `__str__` on SitemapIndexItem is deprecated, use the `location` attribute instead.   )
stacklevel)warningswarnr   r   )selfmsg r   ]/var/www/html/evchargy.com/venv/lib/python3.10/site-packages/django/contrib/sitemaps/views.py__str__   s   zSitemapIndexItem.__str__)__name__
__module____qualname__str__annotations__r   boolr   r   r   r   r   r      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
   
r0   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%sFr      z%s?p=%sLast-Modifiedsitemapscontent_typer    )schemer   itemscallableprotocolr
   domainZget_latest_lastmodr0   appendr   rangeZ	paginatorZ	num_pagesr   	timestampr	   )r!   r7   template_namer9   Zsitemap_url_namereq_protocolreq_sitesitesZall_indexes_lastmodlatest_lastmodr4   siter=   Zsitemap_urlZabsolute_urlsite_lastmodpager    r   r   r   index5   s@   rJ   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pr5   T)rI   rG   r=   rF   FzPage %s emptyzNo page '%s'r6   Zurlsetr8   )r:   r   r   valuesGETgetr<   extendZget_urlsgetattrr0   r   r   r   rA   r	   )r!   r7   r4   rB   r9   rC   rD   mapsrI   ZlastmodZall_sites_lastmodurlsrG   rH   r    r   r   r   sitemapf   sJ   rT   )r1   r2   r3   )NrK   r2   )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.deprecationr   Zdjango.utils.httpr   r   r(   r0   rJ   rT   r   r   r   r   <module>   s4    
0