ó
Ð7ec           @   sÙ   d  Z  d d l m Z m Z m Z m Z d d l m Z d d l m	 Z	 m
 Z
 d d l m Z d d l m Z d d l m Z d d d d d „ Z d d d d d	 „ Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d S(   sµ   
This module collects helper functions and classes that "span" multiple levels
of MVC. In other words, these functions/classes introduce controlled coupling
for convenience's sake.
iÿÿÿÿ(   t   Http404t   HttpResponset   HttpResponsePermanentRedirectt   HttpResponseRedirect(   t   loader(   t   NoReverseMatcht   reverse(   t   six(   t
   force_text(   t   Promisec         C   s(   t  j |  | d | ƒ} t | | | ƒ S(   sœ   
    Returns a HttpResponse whose content is filled with the result of calling
    django.template.loader.render_to_string() with the passed arguments.
    t   using(   R   t   render_to_stringR   (   t   template_namet   contextt   content_typet   statusR
   t   content(    (    s:   /usr/local/lib/python2.7/dist-packages/django/shortcuts.pyt   render_to_response   s    c         C   s+   t  j | | |  d | ƒ} t | | | ƒ S(   sœ   
    Returns a HttpResponse whose content is filled with the result of calling
    django.template.loader.render_to_string() with the passed arguments.
    R
   (   R   R   R   (   t   requestR   R   R   R   R
   R   (    (    s:   /usr/local/lib/python2.7/dist-packages/django/shortcuts.pyt   render   s    c         O   s7   | j  d t ƒ r t } n t } | t |  | | Ž ƒ S(   sè  
    Returns an HttpResponseRedirect to the appropriate URL for the arguments
    passed.

    The arguments could be:

        * A model: the model's `get_absolute_url()` function will be called.

        * A view name, possibly with arguments: `urls.reverse()` will be used
          to reverse-resolve the name.

        * A URL, which will be used as-is for the redirect location.

    By default issues a temporary redirect; pass permanent=True to issue a
    permanent redirect
    t	   permanent(   t   popt   FalseR   R   t   resolve_url(   t   tot   argst   kwargst   redirect_class(    (    s:   /usr/local/lib/python2.7/dist-packages/django/shortcuts.pyt   redirect"   s    	c         C   s    t  |  d ƒ r |  j j ƒ  S|  S(   sÃ   
    Return a QuerySet or a Manager.
    Duck typing in action: any class with a `get()` method (for
    get_object_or_404) or a `filter()` method (for get_list_or_404) might do
    the job.
    t   _default_manager(   t   hasattrR   t   all(   t   klass(    (    s:   /usr/local/lib/python2.7/dist-packages/django/shortcuts.pyt   _get_queryset;   s    c         O   s›   t  |  ƒ } y | j | | Ž  SWnt t k
 rg t |  t ƒ rH |  j n	 |  j j } t d | ƒ ‚ n0 | j j	 k
 r– t
 d | j j j ƒ ‚ n Xd S(   s_  
    Uses get() to return an object, or raises a Http404 exception if the object
    does not exist.

    klass may be a Model, Manager, or QuerySet object. All other passed
    arguments and keyword arguments are used in the get() query.

    Note: Like with get(), an MultipleObjectsReturned will be raised if more than one
    object is found.
    sV   First argument to get_object_or_404() must be a Model, Manager, or QuerySet, not '%s'.s   No %s matches the given query.N(   R!   t   gett   AttributeErrort
   isinstancet   typet   __name__t	   __class__t
   ValueErrort   modelt   DoesNotExistR    t   _metat   object_name(   R    R   R   t   querysett   klass__name(    (    s:   /usr/local/lib/python2.7/dist-packages/django/shortcuts.pyt   get_object_or_404H   s    $c         O   s–   t  |  ƒ } y t | j | | Ž  ƒ } WnE t k
 ro t |  t ƒ rP |  j n	 |  j j } t d | ƒ ‚ n X| s’ t	 d | j
 j j ƒ ‚ n  | S(   sø   
    Uses filter() to return a list of objects, or raise a Http404 exception if
    the list is empty.

    klass may be a Model, Manager, or QuerySet object. All other passed
    arguments and keyword arguments are used in the filter() query.
    sT   First argument to get_list_or_404() must be a Model, Manager, or QuerySet, not '%s'.s   No %s matches the given query.(   R!   t   listt   filterR#   R$   R%   R&   R'   R(   R    R)   R+   R,   (   R    R   R   R-   t   obj_listR.   (    (    s:   /usr/local/lib/python2.7/dist-packages/django/shortcuts.pyt   get_list_or_404`   s    $c         O   sÁ   t  |  d ƒ r |  j ƒ  St |  t ƒ r7 t |  ƒ }  n  t |  t j ƒ r_ |  j d ƒ r_ |  Sn  y t |  d | d | ƒSWnA t	 k
 r¼ t
 |  ƒ r› ‚  n  d |  k r½ d |  k r½ ‚  q½ n X|  S(	   sM  
    Return a URL appropriate for the arguments passed.

    The arguments could be:

        * A model: the model's `get_absolute_url()` function will be called.

        * A view name, possibly with arguments: `urls.reverse()` will be used
          to reverse-resolve the name.

        * A URL, which will be returned as-is.
    t   get_absolute_urls   ./s   ../R   R   t   /t   .(   s   ./s   ../(   R   R4   R$   R	   R   R   t   string_typest
   startswithR   R   t   callable(   R   R   R   (    (    s:   /usr/local/lib/python2.7/dist-packages/django/shortcuts.pyR   v   s    

N(   t   __doc__t   django.httpR    R   R   R   t   django.templateR   t   django.urlsR   R   t   django.utilsR   t   django.utils.encodingR   t   django.utils.functionalR	   t   NoneR   R   R   R!   R/   R3   R   (    (    (    s:   /usr/local/lib/python2.7/dist-packages/django/shortcuts.pyt   <module>   s   "						