
    Dvg                         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Zdd	d
Zd Zd Zd Zd Zd Z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                 T    t          j        ||| |          }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.
    )using)r   render_to_stringr   )requesttemplate_namecontextcontent_typestatusr   contents          M/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/django/shortcuts.pyrenderr      s/     %mWgUSSSGv666    F)	permanentc                T    |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.
    )r   r   resolve_url)tor   argskwargsredirect_classs        r   redirectr      sB    $ *3L%%8L  >+b:4:::6::;;;r   c                 X    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)klasss    r   _get_querysetr$   4   s1     u()) ,%))+++Lr   c                 8   t          |           }t          |d          s:t          | t                    r| j        n| j        j        }t          d|z            	  |j        |i |S # |j        j	        $ r" t          d|j        j        j        z            w xY 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.)r$   r!   
isinstancetype__name__	__class__
ValueErrorr&   modelDoesNotExistr   _metaobject_namer#   r   r   querysetklass__names        r   get_object_or_404r4   A   s     U##H8U## 
(55SENN5?;S 	 %'23
 
 	

x|T,V,,,>& 
 
 
,x~/C/OO
 
 	

s   A( (1Bc                 L  K   t          |           }t          |d          s;t          | t                    r| j        n| j        j        }t          d| d          	  |j        |i | d{V S # |j        j	        $ r# t          d|j        j        j         d          w xY w)zSee get_object_or_404().agetzSFirst argument to aget_object_or_404() must be a Model, Manager, or QuerySet, not ''.NNo  matches the given query.)r$   r!   r(   r)   r*   r+   r,   r6   r-   r.   r   r/   r0   r1   s        r   aget_object_or_404r:   ]   s      U##H8V$$ 
(55SENN5?;S 	 .). . .
 
 	
Y"X]D3F333333333>& Y Y YWHN0<WWWXXXYs   A1 12B#c                 2   t          |           }t          |d          s:t          | t                    r| j        n| j        j        }t          d|z            t           |j        |i |          }|s!t          d|j
        j        j        z            |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'   )r$   r!   r(   r)   r*   r+   r,   listr<   r   r-   r/   r0   r#   r   r   r2   r3   obj_lists         r   get_list_or_404r@   n   s     U##H8X&& 
(55SENN5?;S 	 "$/0
 
 	
 OHOT4V4455H 
,x~/C/OO
 
 	
 Or   c                 @  K   t          |           }t          |d          s;t          | t                    r| j        n| j        j        }t          d| d          d  |j        |i |2              d{V }|s"t          d|j	        j
        j         d          |S )zSee get_list_or_404().r<   zQFirst argument to aget_list_or_404() must be a Model, Manager, or QuerySet, not 'r7   c                 "   K   g | 3 d {V }|
6 S )N ).0objs     r   
<listcomp>z$aget_list_or_404.<locals>.<listcomp>   s.      FFFFFFFFcFFFFs   Nr8   r9   )r$   r!   r(   r)   r*   r+   r,   r<   r   r-   r/   r0   r>   s         r   aget_list_or_404rG      s      U##H8X&& 
(55SENN5?;S 	 .). . .
 
 	
 GF_X_d%Ef%E%EFFFFFFFFFH YWHN0<WWWXXXOr   c                 f   t          | d          r|                                 S t          | t                    rt	          |           } t          | t                    r|                     d          r| S 	 t          | ||          S # t          $ r t          |           r d| vrd| vr Y nw xY w| 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!   rI   r(   r
   str
startswithr	   r   callable)r   r   r   s      r   r   r      s     r%&& %""$$$"g  WW "c r}}];; 	rV4444   B<< 	b==S]] Is   6B #B.-B.)NNNN)__doc__django.httpr   r   r   r   django.templater   django.urlsr   r	   django.utils.functionalr
   r   r   r$   r4   r:   r@   rG   r   rC   r   r   <module>rT      s)               # " " " " " / / / / / / / / + + + + + + QU7 7 7 7 #( < < < < <.
 
 

 
 
8Y Y Y"  2  "& & & & &r   