o 3a@sdZddlmZmZmZmZddlmZddlm Z m Z ddl m Z dddZ d d d d Zd dZddZddZddZdS)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 HttpResponseHttpResponsePermanentRedirectHttpResponseRedirect)loader)NoReverseMatchreverse)PromiseNcCstj||||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. )using)rrender_to_stringr)request template_namecontext content_typestatusr contentr2/usr/lib/python3/dist-packages/django/shortcuts.pyrenders rF) permanentcOs&|rtnt}|t|g|Ri|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. )rr resolve_url)torargskwargsredirect_classrrrredirects rcCst|dr |jS|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)hasattrrall)klassrrr _get_queryset,s  r cOsnt|}t|dst|tr|jn|jj}td|z |j|i|WS|jj y6t d|jj j w)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. getzVFirst argument to get_object_or_404() must be a Model, Manager, or QuerySet, not '%s'.No %s matches the given query.) r r isinstancetype__name__ __class__ ValueErrorr!model DoesNotExistr_meta object_name)rrrqueryset klass__namerrrget_object_or_4049s r.cOsdt|}t|dst|tr|jn|jj}td|t|j|i|}|s0t 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. filterzTFirst argument to get_list_or_404() must be a Model, Manager, or QuerySet, not '%s'.r") r rr#r$r%r&r'listr/rr(r*r+)rrrr,r-obj_listrrrget_list_or_404Qs r2cOst|dr |St|trt|}t|tr|dr|Szt|||dWStyAt|r2d|vr;d|vr>Y|SY|Sw)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../)rr/.) rr3r#r str startswithrrcallable)rrrrrrrfs$   r)NNNN)__doc__ django.httprrrrdjango.templater django.urlsrrdjango.utils.functionalr rrr r.r2rrrrrs