a
    Døg¤  ã                   @   sX   d dl mZ d dlmZ d dlmZ d dlmZmZ G dd„ deƒZ	G dd„ deƒZ
d	S )
é    )ÚImproperlyConfigured)Úreverse)Úcached_property)ÚWagtailMenuRegisterableÚWagtailMenuRegisterableGroupc                   @   sˆ   e Zd ZdZeƒ ZdZdZddd„Zdd„ Z	dd	„ Z
d
d„ Zedd„ ƒZedd„ ƒZdd„ Zdd„ Zdd„ Zedd„ ƒZedd„ ƒZdS )ÚViewSetaÌ  
    Defines a viewset to be registered with the Wagtail admin.

    All properties of the viewset can be defined as class-level attributes, or passed as
    keyword arguments to the constructor (in which case they will override any class-level
    attributes). Additionally, the :attr:`name` property can be passed as the first positional
    argument to the constructor.

    For more information on how to use this class, see :ref:`using_base_viewset`.
    NÚ c                 K   s.   |r|| j d< | ¡ D ]\}}|| j |< qd S )NÚname)Ú__dict__Úitems)Úselfr	   ÚkwargsÚkeyÚvalue© r   úZ/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/wagtail/admin/viewsets/base.pyÚ__init__   s    
zViewSet.__init__c                 K   s   |S )zj
        Returns a dictionary of keyword arguments to be passed to all views within this viewset.
        r   )r   r   r   r   r   Úget_common_view_kwargs%   s    zViewSet.get_common_view_kwargsc                    s:   ˆ   ¡ }| |¡ ‡ ‡fdd„| ¡ D ƒ}ˆjf i |¤ŽS )a"  
        Wrapper for view_class.as_view() which passes the kwargs returned from get_common_view_kwargs
        in addition to any kwargs passed to this method. Items from get_common_view_kwargs will be
        filtered to only include those that are valid for the given view_class.
        c                    s*   i | ]"\}}t ˆ|ƒr|ˆ jur||“qS r   )ÚhasattrÚ	UNDEFINED)Ú.0r   r   ©r   Ú
view_classr   r   Ú
<dictcomp>3   s   þz*ViewSet.construct_view.<locals>.<dictcomp>)r   Úupdater   Zas_view)r   r   r   Zmerged_kwargsZfiltered_kwargsr   r   r   Úconstruct_view+   s    
þzViewSet.construct_viewc                    sX   | }i }|D ].}t ||dƒ‰ ˆ r‡ fdd„}||_|||< q|rPt|j|f|ƒS |S dS )a  
        Check for the presence of any of the named methods on this viewset. If any are found,
        create a subclass of view_class that overrides those methods to call the implementation
        on this viewset instead. Otherwise, return view_class unmodified.
        Nc                    s   ˆ |i |¤ŽS ©Nr   )r   Úargsr   ©Zviewset_methodr   r   Úview_methodF   s    z0ViewSet.inject_view_methods.<locals>.view_method)ÚgetattrÚ__name__Útype)r   r   Zmethod_namesZviewsetZ	overridesÚmethod_namer   r   r   r   Úinject_view_methods:   s    
zViewSet.inject_view_methodsc                 C   s   | j std|  ƒ‚| j S )a˜  
        The preferred URL prefix for views within this viewset. When registered through
        Wagtail's :ref:`register_admin_viewset` hook, this will be used as the URL path component
        following ``/admin/``. Other URL registration mechanisms (e.g. editing ``urls.py`` manually)
        may disregard this and use a prefix of their own choosing.

        Defaults to the viewset's ``name``.
        ú)ViewSet %r must provide a `name` property©r	   r   ©r   r   r   r   Ú
url_prefixQ   s
    
ÿzViewSet.url_prefixc                 C   s   | j std|  ƒ‚| j S )zù
        The URL namespace for views within this viewset. Will be used internally as the
        application namespace for the viewset's URLs, and generally be the instance namespace
        too.

        Defaults to the viewset's ``name``.
        r%   r&   r'   r   r   r   Úurl_namespacea   s
    	ÿzViewSet.url_namespacec                 C   s   |   ¡  dS )zr
        Called when the viewset is registered; subclasses can override this to perform additional setup.
        N©Zregister_menu_itemr'   r   r   r   Úon_registerp   s    zViewSet.on_registerc                 C   s   g S )zV
        Returns a set of URL routes to be registered with the Wagtail admin.
        r   r'   r   r   r   Úget_urlpatternsv   s    zViewSet.get_urlpatternsc                 C   s   | j d | S )zE
        Returns the namespaced URL name for the given view.
        ú:)r)   )r   Z	view_namer   r   r   Úget_url_name|   s    zViewSet.get_url_namec                 C   s   | j S r   )Úiconr'   r   r   r   Ú	menu_icon‚   s    zViewSet.menu_iconc                 C   s   t |  |  ¡ d j¡ƒS )Nr   )r   r.   r,   r	   r'   r   r   r   Úmenu_url†   s    zViewSet.menu_url)N)r!   Ú
__module__Ú__qualname__Ú__doc__Úobjectr   r	   r/   r   r   r   r$   r   r(   r)   r+   r,   r.   r0   r1   r   r   r   r   r      s&   



r   c                   @   s   e Zd ZdZdd„ ZdS )ÚViewSetGroupzþ
    A container for grouping together multiple :class:`ViewSet` instances.
    Creates a menu item with a submenu for accessing the main URL for each instances.

    For more information on how to use this class, see :ref:`using_base_viewsetgroup`.
    c                 C   s   |   ¡  d S r   r*   r'   r   r   r   r+   “   s    zViewSetGroup.on_registerN)r!   r2   r3   r4   r+   r   r   r   r   r6   ‹   s   r6   N)Zdjango.core.exceptionsr   Zdjango.urlsr   Zdjango.utils.functionalr   Zwagtail.admin.menur   r   r   r6   r   r   r   r   Ú<module>   s    