o Ih@sddlZddlmZddlmZddlmZmZmZm Z m Z ddl m Z ddl mZddlmZddlmZed ZGd d d ZGd d d ZGdddZGdddeeeZGdddeZdS)N)update_wrapper)ImproperlyConfigured) HttpResponseHttpResponseGoneHttpResponseNotAllowedHttpResponsePermanentRedirectHttpResponseRedirect)TemplateResponse)reverse)classonlymethod) log_responsezdjango.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-)r0r1r&rrr/ras_view1s$   z View.as_viewcOs2t|drt|ds|j|_||_||_||_dS)z1Initialize attributes shared by all view methods.rr!N)r+rr!r)r.rrr)r.rrrrr*Ss  z View.setupcOsB|j|jvrt||j|j}n|j}||g|Ri|SN)methodlowerr4getattrhttp_method_not_allowed)rr)r.rhandlerrrrr-[sz View.dispatchcOs&t|}td|j|j||d|S)NzMethod Not Allowed (%s): %sresponser))r_allowed_methodsr r;pathrr)r.rrArrrr>es  zView.http_method_not_allowedcOs(t}d||jd<d|jd<|S)z8Handle responding to requests for the OPTIONS HTTP verb.z, Allow0zContent-Length)rjoinrBheadersrDrrrr"os z View.optionscsfddjDS)Ncsg|] }t|r|qSr)r+upper).0mrrr wsz)View._allowed_methods..)r4rLrrLrrBvszView._allowed_methodsN) rrrrr4r(r r8r*r-r>r"rBrrrrrs !  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)rrOresponse_classr)get_template_namestemplate_engine)rrQresponse_kwargsrrrrender_to_responsesz(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_namerrLrrrrTs z(TemplateResponseMixin.get_template_names) rrrrrXrUr rSrOrWrTrrrrrNzs rNc@seZdZdZddZdS) TemplateViewzT Render a template. Pass keyword arguments from the URLconf to the context. cOs|jdi|}||S)Nr)rrW)rr)r.rrQrrrrs zTemplateView.getN)rrrrrrrrrrYs rYc@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_urlcOsF|j|i|}|r|jrt|St|St}td|j||d|S)NzGone: %sr@)ra permanentrrrr rC)rr)r.rr]rArrrrszRedirectView.getcO|j|g|Ri|Sr:rr9rrrr!zRedirectView.headcOrcr:rdr9rrrrrezRedirectView.postcOrcr:rdr9rrrr"rezRedirectView.optionscOrcr:rdr9rrrr rezRedirectView.deletecOrcr:rdr9rrrrrezRedirectView.putcOrcr:rdr9rrrrrezRedirectView.patch)rrrrrbr]r^r`rarr!rr"r rrrrrrrZs  rZ)logging functoolsrdjango.core.exceptionsr django.httprrrrrdjango.template.responser django.urlsr django.utils.decoratorsr django.utils.logr getLoggerloggerr rrNrYrZrrrrs       [$