ó
®â0_c           @  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 m Z m Z d e f d „  ƒ  YZ d	 e e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   unicode_literals(   t   ImproperlyConfigured(   t   models(   t   Http404(   t   ugettext(   t   ContextMixint   TemplateResponseMixint   Viewt   SingleObjectMixinc           B  sh   e  Z d  Z d Z d Z d Z d Z d Z d Z	 e
 Z d d „ Z d „  Z d „  Z d „  Z d „  Z RS(	   uT   
    Provides the ability to retrieve a single object for further manipulation.
    u   slugu   pkc         C  s1  | d k r |  j ƒ  } n  |  j j |  j ƒ } |  j j |  j ƒ } | d k	 rf | j d | ƒ } n  | d k	 r¬ | d k s‡ |  j r¬ |  j ƒ  } | j i | | 6  } n  | d k rİ | d k rİ t	 d |  j
 j ƒ ‚ n  y | j ƒ  } Wn= | j j k
 r,t t d ƒ i | j j j d 6ƒ ‚ n X| S(   uÛ   
        Returns the object the view is displaying.

        By default this requires `self.queryset` and a `pk` or `slug` argument
        in the URLconf, but subclasses can override this to return any object.
        t   pkuI   Generic detail view %s must be called with either an object pk or a slug.u,   No %(verbose_name)s found matching the queryu   verbose_nameN(   t   Nonet   get_querysett   kwargst   gett   pk_url_kwargt   slug_url_kwargt   filtert   query_pk_and_slugt   get_slug_fieldt   AttributeErrort	   __class__t   __name__t   modelt   DoesNotExistR   t   _t   _metat   verbose_name(   t   selft   querysetR	   t   slugt
   slug_fieldt   obj(    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/views/generic/detail.pyt
   get_object   s$    	!c         C  sU   |  j  d k rH |  j r( |  j j j ƒ  St d i |  j j d 6ƒ ‚ n  |  j  j ƒ  S(   uä   
        Return the `QuerySet` that will be used to look up the object.

        Note that this method is called by the default implementation of
        `get_object` and may not be called if `get_object` is overridden.
        uj   %(cls)s is missing a QuerySet. Define %(cls)s.model, %(cls)s.queryset, or override %(cls)s.get_queryset().u   clsN(   R   R
   R   t   _default_managert   allR   R   R   (   R   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/views/generic/detail.pyR   ;   s    	c         C  s   |  j  S(   uM   
        Get the name of a slug field to be used to look up by slug.
        (   R   (   R   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/views/generic/detail.pyR   O   s    c         C  s4   |  j  r |  j  St | t j ƒ r, | j j Sd Sd S(   u5   
        Get the name to use for the object.
        N(   t   context_object_namet
   isinstanceR   t   ModelR   t
   model_nameR
   (   R   R   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/views/generic/detail.pyt   get_context_object_nameU   s
    	
c         K  sj   i  } |  j  rG |  j  | d <|  j |  j  ƒ } | rG |  j  | | <qG n  | j | ƒ t t |  ƒ j |   S(   uA   
        Insert the single object into the context dict.
        u   object(   t   objectR'   t   updatet   superR   t   get_context_data(   R   R   t   contextR#   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/views/generic/detail.pyR+   `   s    	N(   R   t
   __module__t   __doc__R
   R   R   R   R#   R   R   t   FalseR   R    R   R   R'   R+   (    (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/views/generic/detail.pyR   
   s   %			t   BaseDetailViewc           B  s   e  Z d  Z d „  Z RS(   u4   
    A base view for displaying a single object
    c         O  s1   |  j  ƒ  |  _ |  j d |  j ƒ } |  j | ƒ S(   NR(   (   R    R(   R+   t   render_to_response(   R   t   requestt   argsR   R,   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/views/generic/detail.pyR   r   s    (   R   R-   R.   R   (    (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/views/generic/detail.pyR0   n   s   t!   SingleObjectTemplateResponseMixinc           B  s   e  Z d Z d  Z d „  Z RS(   u   _detailc         C  s5  y t  t |  ƒ j ƒ  } Wnt k
 r0g  } |  j ru |  j ru t |  j |  j d ƒ } | ru | j d | ƒ qu n  t	 |  j t
 j ƒ r¼ |  j j } | j d | j | j |  j f ƒ ne t |  d ƒ r!|  j d k	 r!t |  j t
 j ƒ r!| j d |  j j j |  j j j |  j f ƒ n  | s1‚  q1n X| S(   uº  
        Return a list of template names to be used for the request. May not be
        called if render_to_response is overridden. Returns 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``
        i    u   %s/%s%s.htmlu   modelN(   R*   R4   t   get_template_namesR   R(   t   template_name_fieldt   getattrR
   t   insertR$   R   R%   R   t   appendt	   app_labelR&   t   template_name_suffixt   hasattrR   t
   issubclass(   R   t   namest   namet   object_meta(    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/views/generic/detail.pyR5   |   s,    
	3	
N(   R   R-   R
   R6   R;   R5   (    (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/views/generic/detail.pyR4   x   s   t
   DetailViewc           B  s   e  Z d  Z RS(   uĞ   
    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()`.
    (   R   R-   R.   (    (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/views/generic/detail.pyRA   ­   s   N(   t
   __future__R    t   django.core.exceptionsR   t	   django.dbR   t   django.httpR   t   django.utils.translationR   R   t   django.views.generic.baseR   R   R   R   R0   R4   RA   (    (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/views/generic/detail.pyt   <module>   s   d
5