
v^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 Gd d   d e
  Z Gd d	   d	 e e  Z Gd
 d   d e  Z Gd 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   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  } |  j j |  j  } | d k	 r` | j d |  } | d k	 r | d k s |  j r |  j   } | j | | i   } | d k r | d k r t d |  j	 j
   y | j   } Wn= | j j k
 rt t d  d | j j j i   Yn 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.
        Nr   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-build-8lau8j11/django/django/views/generic/detail.py
get_object   s&    	!zSingleObjectMixin.get_objectc             C   sQ   |  j  d k rD |  j r( |  j j j   St d d |  j j i   |  j  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   s4   |  j  r |  j  St | t j  r, | j j Sd Sd 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                s^   i  } |  j  rA |  j  | d <|  j |  j   } | rA |  j  | | <| j |  t   j |   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)r   
__module____qualname____doc__r   r   r   r$   r   r   r   r!   r   r   r(   r,   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   s1   |  j    |  _ |  j d |  j  } |  j |  S)Nr)   )r!   r)   r,   Zrender_to_response)r   requestargsr   r-   r   r   r    r   i   s    zBaseDetailView.getN)r   r.   r/   r0   r   r   r   r   r    r1   g   s   r1   c                   s.   e  Z d  Z d Z d Z   f d d   Z   S)!SingleObjectTemplateResponseMixinNZ_detailc                s  y t    j   } Wnt k
 rg  } |  j ri |  j ri t |  j |  j d  } | ri | j d |  t |  j t j	  r |  j j
 } | j d | j | j |  j f  n\ t |  d d  d k	 rt |  j t j	  r| j d |  j j
 j |  j j
 j |  j f  | s  Yn 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_meta)r   r   r    r5   s   s,    
	-	z4SingleObjectTemplateResponseMixin.get_template_names)r   r.   r/   r6   r:   r5   r   r   )r   r    r4   o   s   r4   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	   r1   r4   r>   r   r   r   r    <module>   s   _5