U
    8ÄT_k  ã                   @   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
mZmZ G dd„ de
ƒZG dd	„ d	eeƒZG d
d„ deƒZG dd„ deeƒZdS )é    )ÚImproperlyConfigured)Úmodels)ÚHttp404)Úgettext)ÚContextMixinÚTemplateResponseMixinÚViewc                       s^   e Zd Zd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„ Z‡ fdd„Z‡  ZS )ÚSingleObjectMixinzS
    Provide the ability to retrieve a single object for further manipulation.
    NÚslugÚpkFc                 C   sÒ   |dkr|   ¡ }| j | j¡}| j | j¡}|dk	r@|j|d�}|dk	rn|dksV| jrn|  ¡ }|jf ||iŽ}|dkrŽ|dkrŽtd| j	j
 ƒ‚z| ¡ }W n2 |jjk
rÌ   ttdƒd|jjji ƒ‚Y nX |S )zÅ
        Return the object the view is displaying.

        Require `self.queryset` and a `pk` or `slug` argument in the URLconf.
        Subclasses can override this to return any object.
        N)r   zXGeneric detail view %s must be called with either an object pk or a slug in the URLconf.z,No %(verbose_name)s found matching the queryÚverbose_name)Úget_querysetÚkwargsÚgetÚpk_url_kwargÚslug_url_kwargÚfilterÚquery_pk_and_slugÚget_slug_fieldÚAttributeErrorÚ	__class__Ú__name__ÚmodelZDoesNotExistr   Ú_Ú_metar   )ÚselfÚquerysetr   r
   Ú
slug_fieldÚobj© r   ú?/tmp/pip-unpacked-wheel-dv63caxw/django/views/generic/detail.pyÚ
get_object   s,    	ÿÿÿzSingleObjectMixin.get_objectc                 C   s:   | j dkr0| jr| jj ¡ S tdd| jji ƒ‚| j  ¡ S )zÚ
        Return the `QuerySet` that will be used to look up the object.

        This method is called by the default implementation of get_object() and
        may not be called if get_object() is overridden.
        Nzj%(cls)s is missing a QuerySet. Define %(cls)s.model, %(cls)s.queryset, or override %(cls)s.get_queryset().Úcls)r   r   Z_default_managerÚallr   r   r   ©r   r   r   r    r   :   s    
 ÿþÿzSingleObjectMixin.get_querysetc                 C   s   | j S )z;Get the name of a slug field to be used to look up by slug.)r   r$   r   r   r    r   N   s    z SingleObjectMixin.get_slug_fieldc                 C   s(   | j r| j S t|tjƒr |jjS dS dS )z#Get the name to use for the object.N)Úcontext_object_nameÚ
isinstancer   ÚModelr   Ú
model_name)r   r   r   r   r    Úget_context_object_nameR   s
    z)SingleObjectMixin.get_context_object_namec                    sF   i }| j r.| j |d< |  | j ¡}|r.| j ||< | |¡ tƒ jf |ŽS )z/Insert the single object into the context dict.Úobject)r*   r)   ÚupdateÚsuperÚget_context_data)r   r   Úcontextr%   ©r   r   r    r-   [   s    


z"SingleObjectMixin.get_context_data)N)r   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r%   r   r   r   r!   r   r   r)   r-   Ú__classcell__r   r   r/   r    r	      s   
&	r	   c                   @   s   e Zd ZdZdd„ ZdS )ÚBaseDetailViewz+A base view for displaying a single object.c                 O   s"   |   ¡ | _| j| jd�}|  |¡S )N)r*   )r!   r*   r-   Zrender_to_response)r   ÚrequestÚargsr   r.   r   r   r    r   i   s    
zBaseDetailView.getN)r   r0   r1   r2   r   r   r   r   r    r4   g   s   r4   c                       s$   e Zd ZdZdZ‡ fdd„Z‡  ZS )Ú!SingleObjectTemplateResponseMixinNZ_detailc              	      sÐ   zt ƒ  ¡ }W n¼ tk
rÊ   g }| jrN| jrNt| j| jdƒ}|rN| d|¡ t| jtj	ƒr€| jj
}| d|j|j| jf ¡ n@t| ddƒdk	rÀt| jtj	ƒrÀ| d| jj
j| jj
j| jf ¡ |sÆ‚ Y nX |S )a»  
        Return a list of template names to be used for the request. May not be
        called if render_to_response() is overridden. Return the following list:

        * the value of ``template_name`` on the view (if provided)
        * the contents of the ``template_name_field`` field on the
          object instance that the view is operating upon (if available)
        * ``<app_label>/<model_name><template_name_suffix>.html``
        Nr   z%s/%s%s.htmlr   )r,   Úget_template_namesr   r*   Útemplate_name_fieldÚgetattrÚinsertr&   r   r'   r   ÚappendZ	app_labelr(   Útemplate_name_suffixÚ
issubclassr   )r   ÚnamesÚnameZobject_metar/   r   r    r8   s   s0    
ý
ýz4SingleObjectTemplateResponseMixin.get_template_names)r   r0   r1   r9   r=   r8   r3   r   r   r/   r    r7   o   s   r7   c                   @   s   e Zd ZdZdS )Ú
DetailViewzÐ
    Render a "detail" view of an object.

    By default this is a model instance looked up from `self.queryset`, but the
    view will support display of *any* object by overriding `self.get_object()`.
    N)r   r0   r1   r2   r   r   r   r    rA   ¤   s   rA   N)Zdjango.core.exceptionsr   Z	django.dbr   Zdjango.httpr   Zdjango.utils.translationr   r   Zdjango.views.generic.baser   r   r   r	   r4   r7   rA   r   r   r   r    Ú<module>   s   _5