
 X                 @   s  d  d l  m Z d  d l Z d  d l m Z d  d l m Z d  d l m Z d  d l	 m
 Z
 d  d l m Z m Z d  d l m Z d  d	 l m Z e j d
  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e e e  Z Gd d   d e  Z d S)    )unicode_literalsN)update_wrapper)http)ImproperlyConfigured)TemplateResponse)NoReverseMatchreverse)six)classonlymethodzdjango.requestc               @   s"   e  Z d  Z d Z d d   Z d S)ContextMixinz}
    A default context mixin that passes the keyword arguments received by
    get_context_data as the template context.
    c             K   s   d | k r |  | d <n  | S)Nview )selfkwargsr   r   G/home/ubuntu/projects/ifolica/build/django/django/views/generic/base.pyget_context_data   s    zContextMixin.get_context_dataN)__name__
__module____qualname____doc__r   r   r   r   r   r      s   r   c               @   s   e  Z d  Z d Z d d d d d d d d	 g Z d
 d   Z e d d    Z d d   Z d d   Z	 d d   Z
 d d   Z d S)Viewz}
    Intentionally simple parent class for all views. Only implements
    dispatch-by-method and simple sanity checking.
    getpostputpatchdeleteheadoptionstracec             K   s4   x- t  j |  D] \ } } t |  | |  q Wd S)z|
        Constructor. Called in the URLconf; can contain helpful extra
        keyword arguments, and other things.
        N)r	   	iteritemssetattr)r   r   keyvaluer   r   r   __init__$   s    zView.__init__c                s   xd  D]\ } |   j  k r8 t d |   j f   n  t   |  s t d   j | f   q q W   f d d   }   | _  | _ t |   d f  t |   j d f  | S)zB
        Main entry point for a request-response process.
        zUYou tried to pass in the %s method name as a keyword argument to %s(). Don't do that.zm%s() received an invalid keyword %r. as_view only accepts arguments that are already attributes of the class.c                sh        } t  | d  r: t  | d  r: | j | _ n  |  | _ | | _ | | _ | j |  | |  S)Nr   r   )hasattrr   r   requestargsr   dispatch)r%   r&   r   r   )cls
initkwargsr   r   r   =   s    			zView.as_view.<locals>.viewupdatedassigned)http_method_names	TypeErrorr   r$   Z
view_classZview_initkwargsr   r'   )r(   r)   r!   r   r   )r(   r)   r   as_view.   s    		zView.as_viewc             O   sR   | j  j   |  j k r9 t |  | j  j   |  j  } n	 |  j } | | | |  S)N)methodlowerr,   getattrhttp_method_not_allowed)r   r%   r&   r   handlerr   r   r   r'   P   s    !	zView.dispatchc             O   s@   t  j d | j | j d i d d 6| d 6t j |  j    S)NzMethod Not Allowed (%s): %sextrai  status_coder%   )loggerwarningr/   pathr   ZHttpResponseNotAllowed_allowed_methods)r   r%   r&   r   r   r   r   r2   Z   s    zView.http_method_not_allowedc             O   s3   t  j   } d j |  j    | d <d | d <| S)zK
        Handles responding to requests for the OPTIONS HTTP verb.
        z, ZAllow0zContent-Length)r   ZHttpResponsejoinr9   )r   r%   r&   r   responser   r   r   r   a   s    
zView.optionsc                s     f d d     j  D S)Nc                s+   g  |  ]! } t    |  r | j    q Sr   )r$   upper).0m)r   r   r   
<listcomp>k   s   	 z)View._allowed_methods.<locals>.<listcomp>)r,   )r   r   )r   r   r9   j   s    zView._allowed_methodsN)r   r   r   r   r,   r#   r
   r.   r'   r2   r   r9   r   r   r   r   r      s   
"
	r   c               @   sF   e  Z d  Z d Z d Z d Z e Z d Z d d   Z	 d d   Z
 d S)TemplateResponseMixinz8
    A mixin that can be used to render a template.
    Nc          
   K   sD   | j  d |  j  |  j d |  j d |  j   d | d |  j |  S)z
        Returns a response, using the `response_class` for this
        view, with a template rendered with the given context.

        If any keyword arguments are provided, they will be
        passed to the constructor of the response class.
        content_typer%   templatecontextZusing)
setdefaultrB   response_classr%   get_template_namestemplate_engine)r   rD   Zresponse_kwargsr   r   r   render_to_responsew   s    		z(TemplateResponseMixin.render_to_responsec             C   s,   |  j  d k r t d   n
 |  j  g Sd S)z
        Returns 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_namer   )r   r   r   r   rG      s    z(TemplateResponseMixin.get_template_names)r   r   r   r   rJ   rH   r   rF   rB   rI   rG   r   r   r   r   rA   n   s   rA   c               @   s"   e  Z d  Z d Z d d   Z d S)TemplateViewz
    A view that renders a template.  This view will also pass into the context
    any keyword arguments passed by the URLconf.
    c             O   s   |  j  |   } |  j |  S)N)r   rI   )r   r%   r&   r   rD   r   r   r   r      s    zTemplateView.getN)r   r   r   r   r   r   r   r   r   rK      s   rK   c               @   s   e  Z d  Z d Z d Z d Z d Z d Z d d   Z d d   Z	 d d	   Z
 d
 d   Z d d   Z d d   Z d d   Z d d   Z d S)RedirectViewz=
    A view that provides a redirect on any GET request.
    FNc             O   s   |  j  r |  j  | } nH |  j r] y t |  j d | d | } Wqa t k
 rY d SYqa Xn d S|  j j j d d  } | r |  j r d | | f } n  | 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&   r   NQUERY_STRING z%s?%s)urlpattern_namer   r   r%   ZMETAr   query_string)r   r&   r   rO   r   r   r   get_redirect_url   s    		zRedirectView.get_redirect_urlc             O   ss   |  j  | |   } | r> |  j r. t j |  St j |  Sn1 t j d | j d i d d 6| d 6t j   Sd  S)NzGone: %sr4   i  r5   r%   )	rR   	permanentr   ZHttpResponsePermanentRedirectZHttpResponseRedirectr6   r7   r8   ZHttpResponseGone)r   r%   r&   r   rO   r   r   r   r      s    	zRedirectView.getc             O   s   |  j  | | |  S)N)r   )r   r%   r&   r   r   r   r   r      s    zRedirectView.headc             O   s   |  j  | | |  S)N)r   )r   r%   r&   r   r   r   r   r      s    zRedirectView.postc             O   s   |  j  | | |  S)N)r   )r   r%   r&   r   r   r   r   r      s    zRedirectView.optionsc             O   s   |  j  | | |  S)N)r   )r   r%   r&   r   r   r   r   r      s    zRedirectView.deletec             O   s   |  j  | | |  S)N)r   )r   r%   r&   r   r   r   r   r      s    zRedirectView.putc             O   s   |  j  | | |  S)N)r   )r   r%   r&   r   r   r   r   r      s    zRedirectView.patch)r   r   r   r   rS   rO   rP   rQ   rR   r   r   r   r   r   r   r   r   r   r   r   rL      s   rL   )
__future__r   logging	functoolsr   Zdjangor   Zdjango.core.exceptionsr   Zdjango.template.responser   Zdjango.urlsr   r   Zdjango.utilsr	   Zdjango.utils.decoratorsr
   	getLoggerr6   objectr   r   rA   rK   rL   r   r   r   r   <module>   s   R'
