o
    ˷e                     @   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   T/var/www/ideatree/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   is_naive
make_awareutcmax)current_lastmodnew_lastmodr   r   r   _get_latest_lastmod)   s
   
r4   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
   domainget_latest_lastmodr4   appendr   range	paginator	num_pagesr   	timestampr	   )r!   r;   template_namer=   sitemap_url_namereq_protocolreq_sitesitesall_indexes_lastmodlatest_lastmodr8   siterA   sitemap_urlabsolute_urlsite_lastmodpager    r   r   r   index5   s@   	rU   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pr9   T)rT   rP   rA   rO   FzPage %s emptyzNo page '%s'r:   urlsetr<   )r>   r   r   valuesGETgetr@   extendget_urlsgetattrr4   r   r   r   rH   r	   )r!   r;   r8   rI   r=   rK   rL   mapsrT   lastmodall_sites_lastmodurlsrP   rS   r    r   r   r   sitemapg   sJ   	rc   )r5   r6   r7   )NrV   r6   )r*   r   dataclassesr   	functoolsr   django.contrib.sites.shortcutsr   django.core.paginatorr   r   django.httpr   django.template.responser	   django.urlsr
   django.utilsr   django.utils.deprecationr   django.utils.httpr   r   r(   r4   rU   rc   r   r   r   r   <module>   s4    
1