B
    CVvg                 @   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   D/tmp/pip-install-o3oxmrkh/Django/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 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 d}|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  D }|S   S )Nc                s"   g | ]}   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|p| | d|S Q R X | 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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   |  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 drBt d}y|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"   |  |}| |}| |||S )N)r9   r;   _urls)r%   pager:   r8   r   r   r   r   get_urls   s    

zSitemap.get_urlsc          	   C   sl  g }d }d}| j |}x:|jD ].}| d| | | }	| d|}
| d|}|r||d k	}|r||d ksx||kr||}||	|| d|t|
d k	r|
ndg d}| jrH| jrHx>|  D ]2}| d| | || }	|d 	|	|d	 qW | j
rHtj}| d| | || }	|	d
| d
d
d}	|d 	|	dd	 |	| q"W |rh|rh|| _|S )NTz://prioritylastmod
changefreq )r'   r3   rA   rB   r@   
alternatesrD   )r3   r*   /r<   z	x-default)r   r>   Zobject_listr6   r+   strr$   rD   r0   append	x_defaultr   ZLANGUAGE_CODEreplacelatest_lastmod)r%   r>   r8   r   urlsrJ   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   rH   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 | _ |d| _| jp|| _| jp*|| _| jp6|| _d S )Nqueryset
date_field)rO   getrP   r@   rB   r8   )r%   Z	info_dictr@   rB   r8   r   r   r   __init__   s
    
zGenericSitemap.__init__c             C   s
   | j  S )N)rO   filter)r%   r   r   r   r1      s    zGenericSitemap.itemsc             C   s   | j d k	rt|| j S d S )N)rP   r!   )r%   r'   r   r   r   rA      s    
zGenericSitemap.lastmod)NNN)r   r   r   r@   rB   rR   r1   rA   r   r   r   r   rN      s
   
rN   )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    rN   r   r   r   r   <module>   s   
 