
 X5                 @   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	 d
  Z d d d d d d  Z d d   Z d d   Z d d   Z d d   Z d d   Z d S)z
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.
    )Http404HttpResponseHttpResponsePermanentRedirectHttpResponseRedirect)loader)NoReverseMatchreverse)six)
force_text)PromiseNc             C   s(   t  j |  | d | } t | | |  S)z
    Returns a HttpResponse whose content is filled with the result of calling
    django.template.loader.render_to_string() with the passed arguments.
    using)r   render_to_stringr   )template_namecontextcontent_typestatusr   content r   >/home/ubuntu/projects/ifolica/build/django/django/shortcuts.pyrender_to_response   s    r   c             C   s+   t  j | | |  d | } t | | |  S)z
    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   )requestr   r   r   r   r   r   r   r   r   render   s    r   c             O   s7   | j  d d  r t } n t } | t |  | |   S)a  
    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
    Z	permanentF)popr   r   resolve_url)toargskwargsZredirect_classr   r   r   redirect"   s    	r   c             C   s    t  |  d  r |  j j   S|  S)z
    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.
    _default_manager)hasattrr   all)klassr   r   r   _get_queryset;   s    r"   c             O   s   t  |   } y | j | |   SWnv t k
 rh t |  t  rH |  j n	 |  j j } t d |   Yn1 | j j	 k
 r t
 d | j j j   Yn Xd S)a_  
    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.
    zVFirst argument to get_object_or_404() must be a Model, Manager, or QuerySet, not '%s'.zNo %s matches the given query.N)r"   getAttributeError
isinstancetype__name__	__class__
ValueErrormodelZDoesNotExistr   _metaobject_name)r!   r   r   querysetklass__namer   r   r   get_object_or_404H   s    $r/   c             O   s   t  |   } y t | j | |    } WnF t k
 rp t |  t  rP |  j n	 |  j j } t d |   Yn X| s t	 d | j
 j j   n  | S)z
    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.
    zTFirst argument to get_list_or_404() must be a Model, Manager, or QuerySet, not '%s'.zNo %s matches the given query.)r"   listfilterr$   r%   r&   r'   r(   r)   r   r*   r+   r,   )r!   r   r   r-   Zobj_listr.   r   r   r   get_list_or_404`   s    $r2   c             O   s   t  |  d  r |  j   St |  t  r7 t |   }  n  t |  t j  r_ |  j d  r_ |  Sn  y t |  d | d | SWnB t	 k
 r t
 |   r   n  d |  k r d |  k r   n  Yn X|  S)	aM  
    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.
    get_absolute_url./../r   r   /.)r4   r5   )r   r3   r%   r   r
   r	   string_types
startswithr   r   callable)r   r   r   r   r   r   r   v   s    
r   )__doc__Zdjango.httpr   r   r   r   Zdjango.templater   Zdjango.urlsr   r   Zdjango.utilsr	   Zdjango.utils.encodingr
   Zdjango.utils.functionalr   r   r   r   r"   r/   r2   r   r   r   r   r   <module>   s   "		