3
g                 @   s   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 d dlmZmZ d dlmZ d	ZG d
d deZdedfddZdddZG dd dZG dd deZdS )    )	urlencode)urlopen)apps)settings)	paginator)ImproperlyConfigured)NoReverseMatchreverse)translationz,https://www.google.com/webmasters/tools/pingc               @   s   e Zd ZdS )SitemapNotFoundN)__name__
__module____qualname__ r   r   ^/var/www/tester-filtro-web/env/lib/python3.6/site-packages/django/contrib/sitemaps/__init__.pyr      s   r   NTc             C   s*   t | |}td|i}td||f  dS )a+  
    Alert Google that the sitemap for the current site has been updated.
    If sitemap_url is provided, it should be an absolute path to the sitemap
    for this site -- e.g., '/sitemap.xml'. If sitemap_url is not provided, this
    function will attempt to deduce it by using urls.reverse().
    Zsitemapz%s?%sN)_get_sitemap_full_urlr   r   )sitemap_urlZping_urlsitemap_uses_httpsZsitemap_full_urlparamsr   r   r   ping_google   s    
r   c             C   s   t jdstd| d kr^ytd} W n6 tk
r\   ytd} W n tk
rV   Y nX Y nX | d krntdt jd}|jj }|rdnd}d	||j	| f S )
Nzdjango.contrib.siteszAping_google requires django.contrib.sites, which isn't installed.z#django.contrib.sitemaps.views.indexz%django.contrib.sitemaps.views.sitemapzPYou didn't provide a sitemap_url, and the sitemap URL couldn't be auto-detected.z
sites.Sitehttpshttpz	%s://%s%s)
django_appsis_installedr   r	   r   r   	get_modelobjectsget_currentdomain)r   r   SiteZcurrent_siteschemer   r   r   r      s     


r   c               @   s   e Zd ZdZdZdZdZdZdZdddZ	dd Z
dd	 Zdd
dZedd Zdd Zdd ZdddZdddZdddZdd ZdS ) SitemapiP  NFc             C   sF   yt | |}W n tk
r"   |S X t|rB| jr:|\}}||S |S )N)getattrAttributeErrorcallablei18n)selfnameitemdefaultattr	lang_coder   r   r   _getK   s    zSitemap._getc             C   s    | j d k	r| j S dd tjD S )Nc             S   s   g | ]\}}|qS r   r   ).0r*   _r   r   r   
<listcomp>[   s    z&Sitemap._languages.<locals>.<listcomp>)	languagesr   Z	LANGUAGES)r%   r   r   r   
_languagesX   s    
zSitemap._languagesc                s(    j r  fdd j D }|S  j S )Nc                s"   g | ]} j  D ]}||fqqS r   )items)r,   r*   r'   )r%   r   r   r.   b   s   z"Sitemap._items.<locals>.<listcomp>)r$   r0   r1   )r%   r1   r   )r%   r   _items]   s
    
zSitemap._itemsc          
   C   s<   | j r0|\}}tj|p| | jd|S Q R X | jd|S )Nlocation)r$   r
   overrider+   )r%   r'   Zforce_lang_codeobjr*   r   r   r   	_locationi   s
    zSitemap._locationc             C   s   t j| j | jS )N)r   Z	Paginatorr2   limit)r%   r   r   r   r   q   s    zSitemap.paginatorc             C   s   g S )Nr   )r%   r   r   r   r1   u   s    zSitemap.itemsc             C   s   |j  S )N)Zget_absolute_url)r%   r'   r   r   r   r3   x   s    zSitemap.locationc             C   s   | j p|pdS )Nr   )protocol)r%   r8   r   r   r   get_protocol{   s    zSitemap.get_protocolc             C   sX   |d krRt jdrBt jd}y|jj }W n |jk
r@   Y nX |d krRtd|jS )Nzdjango.contrib.sitesz
sites.SitezbTo use sitemaps, either enable the sites framework or pass a Site/RequestSite object in your view.)r   r   r   r   r   ZDoesNotExistr   r   )r%   siter   r   r   r   
get_domain   s    

zSitemap.get_domain   c             C   s"   | j |}| j|}| j|||S )N)r9   r;   _urls)r%   pager:   r8   r   r   r   r   get_urls   s    

zSitemap.get_urlsc             C   sj  g }d }d}| j j|}x8|jD ],}| d| | j| }	| jd|}
| jd|}|r||d k	}|r||d ksx||kr||}||	|| jd|t|
d k	r|
ndg d}| jo| jrFx>| j D ]2}| d| | j|| }	|d j	|	|d	 qW | j
rFtj}| d| | j|| }	|	jd
| d
d
d}	|d j	|	dd	 |j	| q"W |rf|rf|| _|S )NTz://prioritylastmod
changefreq )r'   r3   rA   rB   r@   
alternatesrD   )r3   r*   /r<   z	x-default)r   r>   object_listr6   r+   strr$   rD   r0   append	x_defaultr   ZLANGUAGE_CODEreplacelatest_lastmod)r%   r>   r8   r   urlsrK   Zall_items_lastmodZpaginator_pager'   locr@   rA   Zurl_infor*   r   r   r   r=      sH    

zSitemap._urls)N)N)N)N)r<   NN)r   r   r   r7   r8   r$   r/   rD   rI   r+   r0   r2   r6   propertyr   r1   r3   r9   r;   r?   r=   r   r   r   r   r    6   s"   




r    c               @   s.   e Zd ZdZdZdddZdd Zdd ZdS )	GenericSitemapNc             C   s>   |d | _ |jd| _| jp|| _| jp*|| _| jp6|| _d S )Nqueryset
date_field)rP   getrQ   r@   rB   r8   )r%   Z	info_dictr@   rB   r8   r   r   r   __init__   s
    
zGenericSitemap.__init__c             C   s
   | j j S )N)rP   filter)r%   r   r   r   r1      s    zGenericSitemap.itemsc             C   s   | j d k	rt|| j S d S )N)rQ   r!   )r%   r'   r   r   r   rA      s    
zGenericSitemap.lastmod)NNN)r   r   r   r@   rB   rS   r1   rA   r   r   r   r   rO      s
   
rO   )T)urllib.parser   urllib.requestr   Zdjango.appsr   r   Zdjango.confr   Zdjango.corer   Zdjango.core.exceptionsr   Zdjango.urlsr   r	   Zdjango.utilsr
   ZPING_URL	Exceptionr   r   r   r    rO   r   r   r   r   <module>   s   
 