
vÅÏ^  ã               @   sZ   d  d l  m Z d  d l m Z d  d l m Z d d l m Z Gd d „  d e ƒ Z d S)	é    )Úsettings)ÚHttpResponse)ÚMiddlewareMixiné   )Úget_view_namec               @   s"   e  Z d  Z d Z d d „  Z d S)ÚXViewMiddlewarez9
    Add an X-View header to internal HEAD requests.
    c             C   s—   t  | d ƒ s4 t d t j d k r* d n d ƒ ‚ | j d k r“ | j j d ƒ t j k sv | j j	 r“ | j j
 r“ t ƒ  } t | ƒ | d <| Sd S)	a  
        If the request method is HEAD and either the IP is internal or the
        user is a logged-in staff member, return a responsewith an x-view
        header indicating the view function. This is used to lookup the view
        function for an arbitrary page.
        Úuserz¬The XView middleware requires authentication middleware to be installed. Edit your MIDDLEWARE%s setting to insert 'django.contrib.auth.middleware.AuthenticationMiddleware'.NZ_CLASSESÚ ÚHEADZREMOTE_ADDRzX-View)ÚhasattrÚAssertionErrorr   Z
MIDDLEWAREÚmethodZMETAÚgetZINTERNAL_IPSr   Z	is_activeZis_staffr   r   )ÚselfÚrequestZ	view_funcZ	view_argsZview_kwargsÚresponse© r   úE/tmp/pip-build-8lau8j11/django/django/contrib/admindocs/middleware.pyÚprocess_view   s    *	zXViewMiddleware.process_viewN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s   r   N)	Zdjango.confr   Zdjango.httpr   Zdjango.utils.deprecationr   Úutilsr   r   r   r   r   r   Ú<module>   s   