B
    ª0H[y  ã               @   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
 ƒ‚y| ¡ }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   zIGeneric detail view %s must be called with either an object pk or a slug.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   ú_C:\Users\HIRONO~1\AppData\Local\Temp\pip-install-6bm3nxem\django\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   9   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   M   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_nameQ   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,   Z   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   h   s    
zBaseDetailView.getN)r   r.   r/   r0   r   r   r   r   r    r2   f   s   r2   c                   s$   e Zd ZdZdZ‡ fdd„Z‡  ZS )Ú!SingleObjectTemplateResponseMixinNZ_detailc          	      sÔ   y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 ¡ nDt| dƒrÄ| j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Úhasattrr   Ú
issubclass)r   ÚnamesÚnameZobject_meta)r   r   r    r6   r   s,    
"z4SingleObjectTemplateResponseMixin.get_template_names)r   r.   r/   r7   r;   r6   r1   r   r   )r   r    r5   n   s   r5   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   r.   r/   r0   r   r   r   r    r@   £   s   r@   N)Zdjango.core.exceptionsr   Z	django.dbr   Zdjango.httpr   Zdjango.utils.translationr   r   Zdjango.views.generic.baser   r   r   r	   r2   r5   r@   r   r   r   r    Ú<module>   s   ^5