B
    ¡0H[É  ã               @   sž   d Z ddl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d	„Zdd
d„Zddœ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.
é    N)ÚHttp404ÚHttpResponseÚHttpResponsePermanentRedirectÚHttpResponseRedirect)Úloader)ÚNoReverseMatchÚreverse)ÚRemovedInDjango30Warning)ÚPromisec             C   s,   t jdtdd� tj| ||d�}t|||ƒS )z›
    Return a HttpResponse whose content is filled with the result of calling
    django.template.loader.render_to_string() with the passed arguments.
    zzrender_to_response() is deprecated in favor of render(). It has the same signature except that it also requires a request.é   )Ú
stacklevel)Úusing)ÚwarningsÚwarnr	   r   Úrender_to_stringr   )Útemplate_nameÚcontextÚcontent_typeÚstatusr   Úcontent© r   úTC:\Users\HIRONO~1\AppData\Local\Temp\pip-install-6bm3nxem\django\django\shortcuts.pyÚrender_to_response   s
    
r   c             C   s   t j||| |d�}t|||ƒS )z›
    Return 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   F)Ú	permanentc            O   s    |rt nt}|t| f|ž|ŽƒS )aç  
    Return 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
    )r   r   Úresolve_url)Útor   ÚargsÚkwargsZredirect_classr   r   r   Úredirect(   s    r    c             C   s   t | dƒr| 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   sz   t | ƒ}y|j||ŽS  tk
rL   t| tƒr4| jn| jj}td| ƒ‚Y n* |jj	k
rt   t
d|jjj ƒ‚Y nX dS )aX  
    Use get() to return an object, or raise 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.

    Like with QuerySet.get(), MultipleObjectsReturned is 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_404J   s    r2   c             O   sp   t | ƒ}yt|j||Žƒ}W n8 tk
rT   t| tƒr<| jn| jj}td| ƒ‚Y nX |slt	d|j
jj ƒ‚|S )z÷
    Use 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   r0   Zobj_listr1   r   r   r   Úget_list_or_404b   s    r5   c             O   s€   t | dƒr|  ¡ S t| tƒr$t| ƒ} t| tƒr<|  d¡r<| S yt| ||d�S  tk
rz   t| ƒrd‚ d| krvd| krv‚ Y n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)z./z../)r   r   ú/Ú.)	r"   r6   r(   r
   ÚstrÚ
startswithr   r   Úcallable)r   r   r   r   r   r   r   x   s    



r   )NNNN)NNNN)Ú__doc__r   Zdjango.httpr   r   r   r   Zdjango.templater   Zdjango.urlsr   r   Zdjango.utils.deprecationr	   Zdjango.utils.functionalr
   r   r   r    r%   r2   r5   r   r   r   r   r   Ú<module>   s   

	