o 3ak@sddlZddlmZddlmZddlmZmZmZm Z m Z ddl m Z ddl mZddlmZedZGd d d ZGd d d ZGd ddZGdddeeeZGdddeZdS)N)update_wrapper)ImproperlyConfigured) HttpResponseHttpResponseGoneHttpResponseNotAllowedHttpResponsePermanentRedirectHttpResponseRedirect)TemplateResponse)reverse)classonlymethodzdjango.requestc@seZdZdZdZddZdS) ContextMixinz A default context mixin that passes the keyword arguments received by get_context_data() as the template context. NcKs&|d||jdur||j|S)Nview) setdefault extra_contextupdate)selfkwargsr;/usr/lib/python3/dist-packages/django/views/generic/base.pyget_context_datas   zContextMixin.get_context_data)__name__ __module__ __qualname____doc__rrrrrrr s r c@sTeZdZdZgdZddZeddZddZd d Z d d Z d dZ ddZ dS)Viewz} Intentionally simple parent class for all views. Only implements dispatch-by-method and simple sanity checking. )getpostputpatchdeleteheadoptionstracecKs"|D] \}}t|||qdS)z| Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things. N)itemssetattr)rrkeyvaluerrr__init__&sz View.__init__c s~D]}|jvrtd|jft|s tdj|fqfdd}|_|_t|ddt|jdd|S)z0Main entry point for a request-response process.zAThe method name %s is not accepted as a keyword argument to %s().zm%s() received an invalid keyword %r. as_view only accepts arguments that are already attributes of the class.csVdi}|j|g|Ri|t|dstdj|j|g|Ri|S)Nrequestz\%s instance has no 'request' attribute. Did you override setup() and forget to call super()?r)setuphasattrAttributeErrorrdispatch)r(argsrrcls initkwargsrrr >s zView.as_view..viewr)updated)assigned)http_method_names TypeErrorrr* view_classview_initkwargsrr,)r/r0r%r rr.ras_view0s$   z View.as_viewcOs2t|drt|ds|j|_||_||_||_dS)z1Initialize attributes shared by all view methods.rr N)r*rr r(r-rrr(r-rrrrr)Rs  z View.setupcOsB|j|jvrt||j|j}n|j}||g|Ri|SN)methodlowerr3getattrhttp_method_not_allowed)rr(r-rhandlerrrrr,Zsz View.dispatchcOs(tjd|j|jd|ddt|S)NzMethod Not Allowed (%s): %si status_coder(extra)loggerwarningr:pathr_allowed_methodsr8rrrr=ds   zView.http_method_not_allowedcOs(t}d||jd<d|jd<|S)z8Handle responding to requests for the OPTIONS HTTP verb.z, Allow0zContent-Length)rjoinrFheaders)rr(r-rresponserrrr!ks z View.optionscsfddjDS)Ncsg|] }t|r|qSr)r*upper).0mrrr ssz)View._allowed_methods..)r3rOrrOrrFrszView._allowed_methodsN) rrrrr3r'r r7r)r,r=r!rFrrrrrs !  rc@s0eZdZdZdZdZeZdZddZ ddZ dS)TemplateResponseMixinz.A mixin that can be used to render a template.NcKs0|d|j|jd|j|||jd|S)z Return a response, using the `response_class` for this view, with a template rendered with the given context. Pass response_kwargs to the constructor of the response class. content_type)r(templatecontextusingNr)rrRresponse_classr(get_template_namestemplate_engine)rrTresponse_kwargsrrrrender_to_response}sz(TemplateResponseMixin.render_to_responsecCs|jdur td|jgS)z Return a list of template names to be used for the request. Must return a list. May not be called if render_to_response() is overridden. NztTemplateResponseMixin requires either a definition of 'template_name' or an implementation of 'get_template_names()') template_namerrOrrrrWs z(TemplateResponseMixin.get_template_names) rrrrr[rXr rVrRrZrWrrrrrQvs rQc@seZdZdZddZdS) TemplateViewzT Render a template. Pass keyword arguments from the URLconf to the context. cOs|jdi|}||S)Nr)rrZ)rr(r-rrTrrrrs zTemplateView.getN)rrrrrrrrrr\s r\c@s`eZdZdZdZdZdZdZddZddZ dd Z d d Z d d Z ddZ ddZddZdS) RedirectViewz&Provide a redirect on any GET request.FNcOsX|jr |j|}n|jrt|j||d}ndS|jjdd}|r*|jr*d||f}|S)z Return the URL redirect to. Keyword arguments from the URL pattern match generating the redirect request are provided as kwargs to this method. )r-rN QUERY_STRINGz%s?%s)url pattern_namer r(METAr query_string)rr-rr`rrrget_redirect_urls   zRedirectView.get_redirect_urlcOsH|j|i|}|r|jrt|St|Stjd|jd|ddtS)NzGone: %sir?rA)rd permanentrrrCrDrEr)rr(r-rr`rrrrszRedirectView.getcO|j|g|Ri|Sr9rr8rrrr zRedirectView.headcOrfr9rgr8rrrrrhzRedirectView.postcOrfr9rgr8rrrr!rhzRedirectView.optionscOrfr9rgr8rrrrrhzRedirectView.deletecOrfr9rgr8rrrrrhzRedirectView.putcOrfr9rgr8rrrrrhzRedirectView.patch)rrrrrer`rarcrdrr rr!rrrrrrrr]s r])logging functoolsrdjango.core.exceptionsr django.httprrrrrdjango.template.responser django.urlsr django.utils.decoratorsr getLoggerrCr rrQr\r]rrrrs      X$