o
    ÎŸŽi‘  ã                   @   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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.
é    )ÚHttp404ÚHttpResponseÚHttpResponsePermanentRedirectÚHttpResponseRedirect)Úloader)ÚNoReverseMatchÚreverse)ÚPromiseNc                 C   s   t j||| |d�}t|||ƒS )zœ
    Return an HttpResponse whose content is filled with the result of calling
    django.template.loader.render_to_string() with the passed arguments.
    )ÚusingN)r   Zrender_to_stringr   )ÚrequestZtemplate_nameÚcontextÚcontent_typeÚstatusr
   Úcontent© r   úZC:\Users\psant\Downloads\Anu Raj Backend\school\venv\Lib\site-packages\django/shortcuts.pyÚrender   s   r   F)Ú	permanentc                O   s&   |rt nt}|t| g|¢R i |¤Žƒ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.

    Issues a temporary redirect by default; pass permanent=True to issue a
    permanent redirect.
    N)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_managerN)Úhasattrr   Úall)Úklassr   r   r   Ú_get_queryset3   s   

r   c                 O   sn   t | ƒ}t|dƒst| tƒr| jn| jj}td| ƒ‚z	|j|i |¤ŽW S  |jj	y6   t
d|jjj ƒ‚w )aY  
    Use get() to return an object, or raise an 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.
    ÚgetzVFirst argument to get_object_or_404() must be a Model, Manager, or QuerySet, not '%s'.úNo %s matches the given query.N)r   r   Ú
isinstanceÚtypeÚ__name__Ú	__class__Ú
ValueErrorr   ÚmodelZDoesNotExistr   Ú_metaÚobject_name)r   r   r   ÚquerysetÚklass__namer   r   r   Úget_object_or_404@   s    
ÿÿÿÿÿr*   c                 O   sd   t | ƒ}t|dƒst| tƒr| jn| jj}td| ƒ‚t|j|i |¤Žƒ}|s0t	d|j
jj ƒ‚|S )zø
    Use filter() to return a list of objects, or raise an 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.
    ÚfilterzTFirst argument to get_list_or_404() must be a Model, Manager, or QuerySet, not '%s'.r   N)r   r   r    r!   r"   r#   r$   Úlistr+   r   r%   r&   r'   )r   r   r   r(   r)   Zobj_listr   r   r   Úget_list_or_404\   s   
ÿÿÿÿr-   c                 O   s„   t | dƒr	|  ¡ S t| tƒrt| ƒ} t| tƒr|  d¡r| S zt| ||d�W S  tyA   t| ƒr2‚ d| vr;d| vr>‚ Y | S Y | S w )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   ú/Ú.N)	r   r.   r    r	   ÚstrÚ
startswithr   r   Úcallable)r   r   r   r   r   r   r   u   s$   

ÿü÷r   )NNNN)Ú__doc__Zdjango.httpr   r   r   r   Zdjango.templater   Zdjango.urlsr   r   Zdjango.utils.functionalr	   r   r   r   r*   r-   r   r   r   r   r   Ú<module>   s    
ÿ