
    恕fc                        d dl mZ d dlZd dlmZ d dlmZmZm	Z	m
Z
mZmZ d dlmZ d dlmZmZ d dlmZ d dlmZmZmZmZ ddZdd	Zd
 Z G d de      Z G d de      Z G d d eee            Z  G d de       Z! G d de      Z"y)    N)wraps)	Blueprintcurrent_apprender_templateabortgurl_for)babel)with_metaclass
as_unicode)helpers)MenuCategoryMenuViewMenuLinkSubMenuCategoryc                       fd}|S )z
        Use this decorator to expose views in your view classes.

        :param url:
            Relative URL for the view
        :param methods:
            Allowed HTTP methods. By default only GET is allowed.
    c                 h    t        | d      sg | _        | j                  j                  f       | S )N_urls)hasattrr   append)fmethodsurls    O/var/www/feuerwehr-webapp/venv/lib/python3.12/site-packages/flask_admin/base.pywrapzexpose.<locals>.wrap   s-    q'"AG	W~&     )r   r   r   s   `` r   exposer      s    
 Kr   c                       fd}|S )z
        Decorator to expose Flask's pluggable view classes
        (``flask.views.View`` or ``flask.views.MethodView``).

        :param url:
            Relative URL for the view

        .. versionadded:: 1.0.4
    c                     t        | j                        }t        | d      r! || j                  | j                              S  ||       S )Nas_view)r   r   r   r!   __name__)vhandlerr   s     r   r   zexpose_plugview.<locals>.wrap*   s?    aii(1i 199QZZ0111:r   r   )r   r   s   ` r   expose_plugviewr%       s     Kr   c                 X     t         d      r S t                fd       }d|_        |S )N_wrappedc                     t        j                  |         | j                  j                  fi |}||S  | j                  g|i |S N)hset_current_view_handle_viewr"   	_run_view)selfargskwargsr   r   s       r   innerz_wrap_view.<locals>.inner;   sV     	
4  "!!!**77Lt~~a1$1&11r   T)r   r   r'   )r   r1   s   ` r   
_wrap_viewr2   6   s6    q*
1X	2 	2 ENLr   c                       e Zd ZdZd Zy)AdminViewMetaz
        View metaclass.

        Does some precalculations (like getting list of view methods from the class) to avoid
        calculating them for each view class instance.
    c                 L   t         j                  | |||       g | _        d | _        t	        |       D ]p  }t        | |      }t        |d      s|j                  D ]0  \  }}| j                  j                  |||f       |dk(  s*|| _        2 t        | |t        |             r y )Nr   /)
type__init__r   _default_viewdirgetattrr   r   setattrr2   )cls	classnamebasesfieldspattrr   r   s           r   r8   zAdminViewMeta.__init__S   s    c9eV4 	 S 	2A3?DtW%$(JJ .LCII$$c1g%67cz,-)	. Q
4 01	2r   N)r"   
__module____qualname____doc__r8   r   r   r   r4   r4   L   s    2r   r4   c                       e Zd Zy)BaseViewClassN)r"   rC   rD   r   r   r   rG   rG   i   s    r   rG   c                       e Zd ZdZed        Z	 	 	 ddZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zed        Zy)BaseViewa  
        Base administrative view.

        Derive from this class to implement your administrative interface piece. For example::

            from flask_admin import BaseView, expose
            class MyView(BaseView):
                @expose('/')
                def index(self):
                    return 'Hello World!'

        Icons can be added to the menu by using `menu_icon_type` and `menu_icon_value`. For example::

            admin.add_view(MyView(name='My View', menu_icon_type='glyph', menu_icon_value='glyphicon-home'))
    c                 V    t        t        dd      }|t               x}t        _        |S )a<  
            Extra template arguments.

            If you need to pass some extra parameters to the template,
            you can override particular view function, contribute
            arguments you want to pass to the template and call parent view.

            These arguments are local for this request and will be discarded
            in the next request.

            Any value passed through ``_template_args`` will override whatever
            parent view function passed to the template.

            For example::

                class MyAdmin(ModelView):
                    @expose('/')
                    def index(self):
                        self._template_args['name'] = 'foobar'
                        self._template_args['code'] = '12345'
                        super(MyAdmin, self).index()
        _admin_template_argsN)r;   r   dictrK   )r.   r/   s     r   _template_argszBaseView._template_args}   s,    0 q0$7<,0F2D1)r   Nc
                 &   || _         || _        | j                  |      | _        || _        || _        || _        d| _        || _        || _	        |	| _
        d| _        d| _        | j                  "t        d| j                  j                   z        y)a  
            Constructor.

            :param name:
                Name of this view. If not provided, will default to the class name.
            :param category:
                View category. If not provided, this view will be shown as a top-level menu item. Otherwise, it will
                be in a submenu.
            :param endpoint:
                Base endpoint name for the view. For example, if there's a view method called "index" and
                endpoint is set to "myadmin", you can use `url_for('myadmin.index')` to get the URL to the
                view method. Defaults to the class name in lower case.
            :param url:
                Base URL. If provided, affects how URLs are generated. For example, if the url parameter
                is "test", the resulting URL will look like "/admin/test/". If not provided, will
                use endpoint as a base url. However, if URL starts with '/', absolute path is assumed
                and '/admin/' prefix won't be applied.
            :param static_url_path:
                Static URL Path. If provided, this specifies the path to the static url directory.
            :param menu_class_name:
                Optional class name for the menu item.
            :param menu_icon_type:
                Optional icon. Possible icon types:

                 - `flask_admin.consts.ICON_TYPE_GLYPH` - Bootstrap glyph icon
                 - `flask_admin.consts.ICON_TYPE_FONT_AWESOME` - Font Awesome icon
                 - `flask_admin.consts.ICON_TYPE_IMAGE` - Image relative to Flask static directory
                 - `flask_admin.consts.ICON_TYPE_IMAGE_URL` - Image with full URL
            :param menu_icon_value:
                Icon glyph name or URL, depending on `menu_icon_type` setting
        Nz;Attempted to instantiate admin view %s without default view)namecategory_get_endpointendpointr   static_folderstatic_url_pathmenumenu_class_namemenu_icon_typemenu_icon_valueadmin	blueprintr9   	Exception	__class__r"   )
r.   rO   rP   rR   r   rS   rT   rV   rW   rX   s
             r   r8   zBaseView.__init__   s    D 	 **84*.	.,. 
 %Z]a]k]k]t]ttuu &r   c                 R    |r|S | j                   j                  j                         S )z
            Generate Flask endpoint name. By default converts class name to lower case if endpoint is
            not explicitly provided.
        )r\   r"   lower)r.   rR   s     r   rQ   zBaseView._get_endpoint   s%    
 O~~&&,,..r   c                     |P|j                   dk7  r|j                   d| j                  }|S | |j                  k(  rd}|S d| j                  z  }|S |j                  d      s|j                   d|}|S )zU
            Generate URL for the view. Override to change default behavior.
        r6   z/%s)r   rR   
index_view
startswith)r.   rY   r   s      r   _get_view_urlzBaseView._get_view_url   s     ;yyC!&DMM: 
 5+++C 
  $--/C
 
 >>#&!&C0
r   c           
         || _         | j                  s|j                  | _        | j                  || j                        | _        | j                  dk(  r!d| _        | j                  sd| _        d| _        | j
                  *| j                  | j                  j                        | _        t        | j                  t        | j                  | j                   j                  t        j                  d| j                   j                        | j                  | j                        | _        | j                   D ]/  \  }}}| j                  j#                  ||t%        | |      |       1 | j                  S )z-
            Create Flask blueprint.
        r6   Nstaticz/static/admin	templates)
url_prefix	subdomaintemplate_folderrS   rT   )r   )rY   rT   rb   r   rS   rO   _prettify_class_namer\   r"   r   rR   rg   opjointemplate_moderZ   r   add_url_ruler;   )r.   rY   r   rO   r   s        r   create_blueprintzBaseView.create_blueprint   s9   
 
 ###(#8#8D  %%eTXX6 88s?DH''%-"'6$ 9911$..2I2IJDI #4==(.2hh-1ZZ-A-A3577;

H`H`3a151C1C373G3GI #'** 	9CwNN''(,(/d(;07 ( 9	9 ~~r   c                 .   | |d<   | j                   j                  |d<   t        j                  |d<   t        j                  |d<   t
        |d<   | j                  |d<   t        j                  |d<   |j                  | j                         t        |fi |S )z
            Render template

            :param template:
                Template path to render
            :param kwargs:
                Template arguments
        
admin_viewadmin_base_template_gettext	_ngettextr*   get_urlconfig)rY   base_templater
   gettextngettextr*   rt   r   ru   updaterM   r   )r.   templater0   s      r   renderzBaseView.render  s      $|(,

(@(@$% #]]z#nn{s !LLy '--x 	d))*x2622r   c                 ,    t        j                  |      S )z
            Split words in PascalCase string into separate words.

            :param name:
                String to prettify
        )r*   prettify_class_namer.   rO   s     r   ri   zBaseView._prettify_class_name6  s     $$T**r   c                      y)a$  
            Override this method if you want dynamically hide or show administrative views
            from Flask-Admin menu structure

            By default, item is visible in menu.

            Please note that item should be both visible and accessible to be displayed in menu.
        Tr   r.   s    r   
is_visiblezBaseView.is_visible?       r   c                      y)a!  
            Override this method to add permission checks.

            Flask-Admin does not make any assumptions about the authentication system used in your application, so it is
            up to you to implement it.

            By default, it will allow access for everyone.
        Tr   r   s    r   is_accessiblezBaseView.is_accessibleJ  r   r   c                 J    | j                         s | j                  |fi |S y)a8  
            This method will be executed before calling any view method.

            It will execute the ``inaccessible_callback`` if the view is not
            accessible.

            :param name:
                View function name
            :param kwargs:
                View function arguments
        N)r   inaccessible_callbackr.   rO   r0   s      r   r,   zBaseView._handle_viewU  s-     !!#-4--d=f== $r   c                 N    	  || g|i |S # t         $ r  |dd| i|cY S w xY w)a&  
            This method will run actual view function.

            While it is similar to _handle_view, can be used to change
            arguments that are passed to the view.

            :param fn:
                View function
            :param kwargs:
                Arguments
        r=   r   )	TypeError)r.   fnr/   r0   s       r   r-   zBaseView._run_viewd  s>    	*d,T,V,, 	*)$)&))	*s    $$c                     t        d      S )z
            Handle the response to inaccessible views.

            By default, it throw HTTP 403 error. Override this method to
            customize the behaviour.
        i  )r   r   s      r   r   zBaseView.inaccessible_callbacku  s     Szr   c                     t        |fi |S )aP  
            Generate URL for the endpoint. If you want to customize URL generation
            logic (persist some query string argument, for example), this is
            right place to do it.

            :param endpoint:
                Flask endpoint name
            :param kwargs:
                Arguments for `url_for`
        )r	   )r.   rR   r0   s      r   rt   zBaseView.get_url~  s     x*6**r   c                     | j                   r| j                   j                  sy| j                   j                  j                  S )NF)rY   appdebugr   s    r   _debugzBaseView._debug  s*    zzzz~~###r   )	NNNNNNNNN)r"   rC   rD   rE   propertyrM   r8   rQ   rb   rn   r{   ri   r   r   r,   r-   r   rt   r   r   r   r   rI   rI   m   s{      < EI59LP4vl/$(T3<+		>*"+ $ $r   rI   c                   J     e Zd ZdZ	 	 	 	 	 	 d fd	Z e       d        Z xZS )AdminIndexViewaD  
        Default administrative interface index page when visiting the ``/admin/`` URL.

        It can be overridden by passing your own view class to the ``Admin`` constructor::

            class MyHomeView(AdminIndexView):
                @expose('/')
                def index(self):
                    arg1 = 'Hello'
                    return self.render('admin/myhome.html', arg1=arg1)

            admin = Admin(index_view=MyHomeView())


        Also, you can change the root url from /admin to / with the following::

            admin = Admin(
                app,
                index_view=AdminIndexView(
                    name='Home',
                    template='admin/myhome.html',
                    url='/'
                )
            )

        Default values for the index page are:

        * If a name is not provided, 'Home' will be used.
        * If an endpoint is not provided, will default to ``admin``
        * Default URL route is ``/admin``.
        * Automatically associates with static folder.
        * Default template is ``admin/index.html``
    c	           
          t         t        |   |xs t        j                  d      ||xs d|dn|d|||       || _        y )NHomerY   z/adminrd   )rV   rW   rX   )superr   r8   r
   lazy_gettext	_template)
r.   rO   rP   rR   r   rz   rV   rW   rX   r\   s
            r   r8   zAdminIndexView.__init__  sU     	nd,T-OU5G5G5O-5-5-@9<X#-5=L<J=L 	- 	N "r   c                 8    | j                  | j                        S r)   )r{   r   r   s    r   indexzAdminIndexView.index  s    {{4>>**r   )NNNNzadmin/index.htmlNNN)r"   rC   rD   rE   r8   r   r   __classcell__)r\   s   @r   r   r     s8     B ,0$(,!% $!%"  X+ +r   r   c                       e Zd ZdZ	 	 	 	 	 	 	 	 	 ddZd Z	 	 ddZd ZddZd Z	d	 Z
d
 ZddZd Zd Zd Z	 	 ddZd Zd Zd Zy)AdminzI
        Collection of the admin views. Also manages menu structure.
    Nc                    || _         || _        g | _        g | _        t	               | _        g | _        |d}|| _        |xs t        ||      | _	        |xs | j                  j                  | _
        |xs | j                  j                  | _        || _        || _        |	xs d| _        |
xs d| _        |xs
 t	               | _        | j#                  |||       || j%                          yy)af  
            Constructor.

            :param app:
                Flask application object
            :param name:
                Application name. Will be displayed in the main menu and as a page title. Defaults to "Admin"
            :param url:
                Base URL
            :param subdomain:
                Subdomain to use
            :param index_view:
                Home page view to use. Defaults to `AdminIndexView`.
            :param translations_path:
                Location of the translation message catalogs. By default will use the translations
                shipped with Flask-Admin.
            :param endpoint:
                Base endpoint name for index view. If you use multiple instances of the `Admin` class with
                a single Flask application, you have to set a unique endpoint name for each instance.
            :param static_url_path:
                Static URL Path. If provided, this specifies the default path to the static url directory for
                all its views. Can be overridden in view configuration.
            :param base_template:
                Override base HTML template for all static views. Defaults to `admin/base.html`.
            :param template_mode:
                Base template path. Defaults to `bootstrap2`. If you want to use
                Bootstrap 3 or 4 integration, change it to `bootstrap3` or `bootstrap4`.
            :param category_icon_classes:
                A dict of category names as keys and html classes as values to be added to menu category icons.
                Example: {'Favorites': 'glyphicon glyphicon-star'}
        Nr   rR   r   zadmin/base.html
bootstrap2r`   rR   r   )r   translations_path_views_menurL   _menu_categories_menu_linksrO   r   r`   rR   r   rT   rg   rv   rl   category_icon_classes_set_admin_index_view_init_extension)r.   r   rO   r   rg   r`   r   rR   rT   rv   rl   r   s               r   r8   zAdmin.__init__  s    P !2
 $<D	$Rc(R <DOO$<$<-$//--."*?.?*:l%:%Ddf" 	""j8QT"U ?  " r   c                     | j                   j                  |       | j                  *| j                  j                  |j	                  |              | j                  |       y)zj
            Add a view to the collection.

            :param view:
                View to add.
        N)r   r   r   register_blueprintrn   _add_view_to_menur.   views     r   add_viewzAdmin.add_view  sM     	4  88HH''(=(=d(CDt$r   c                    |xs t        ||      | _        |xs | j                  j                  | _        |xs | j                  j                  | _        t	        | j
                        dkD  rQ| j                  | j
                  d<   t        | j                  j                  | j                        | j                  d<   y| j                  | j                         y)a  
            Add the admin index view.

          :param index_view:
               Home page view to use. Defaults to `AdminIndexView`.
           :param url:
               Base URL
          :param endpoint:
               Base endpoint name for index view. If you use multiple instances of the `Admin` class with
               a single Flask application, you have to set a unique endpoint name for each instance.
        r   r   N)
r   r`   rR   r   lenr   r   rO   r   r   )r.   r`   rR   r   s       r   r   zAdmin._set_admin_index_view#  s     %Rc(R <DOO$<$<-$//-- t{{a!__DKKN$T__%9%94??KDJJqMMM$//*r   c                 4    |D ]  }| j                  |        y)a8  
            Add one or more views to the collection.

            Examples::

                admin.add_views(view1)
                admin.add_views(view1, view2, view3, view4)
                admin.add_views(*my_list)

            :param args:
                Argument list including the views to add.
        N)r   )r.   r/   r   s      r   	add_viewszAdmin.add_views<        	 DMM$	 r   c                     t        |      }| j                  |      }|ryt        ||||      }|| j                  |<   | j                  j                  |       y)a  
            Add a category of a given name

            :param name:
                The name of the new menu category.
            :param class_name:
                The class name for the new menu category.
            :param icon_type:
                The icon name for the new menu category.
            :param icon_value:
                The icon value for the new menu category.
        N)
class_name	icon_type
icon_value)r   get_category_menu_itemr   r   r   r   )r.   rO   r   r   r   cat_textrP   s          r   add_categoryzAdmin.add_categoryL  sW     d#..t4y]gh*2h'

(#r   c                     t        |      }t        |      }| j                  |      }| j                  |      }|/|,t        |      }|| j                  |<   |j	                  |       yyy)a
  
            Add a category of a given name underneath
            the category with parent_name.

            :param name:
                The name of the new menu category.
            :param parent_name:
                The name of a parent_name category
        N)r   r   r   r   	add_child)r.   rO   parent_name	name_textparent_name_textrP   parents          r   add_sub_categoryzAdmin.add_sub_categoryc  su     t$	%k2..y9,,-=> 2&t,H/7D!!),X& !3r   c                     |j                   r| j                  ||j                          y| j                  j                  |       y)zo
            Add link to menu links collection.

            :param link:
                Link to add.
        N)rP   add_menu_itemr   r   )r.   links     r   add_linkzAdmin.add_linkx  s3     ==tT]]3##D)r   c                 4    |D ]  }| j                  |        y)aC  
            Add one or more links to the menu links collection.

            Examples::

                admin.add_links(link1)
                admin.add_links(link1, link2, link3, link4)
                admin.add_links(*my_list)

            :param args:
                Argument list including the links to add.
        N)r   )r.   r/   r   s      r   	add_linkszAdmin.add_links  r   r   c                 \   |rt        |      }| j                  j                  |      }|Ut        |      }| j                  j                  |      |_        || j                  |<   | j                  j                  |       |j                  |       y| j                  j                  |       y)z
            Add menu item to menu tree hierarchy.

            :param menu_item:
                MenuItem class instance
            :param target_category:
                Target category name
        N)	r   r   getr   r   r   r   r   r   )r.   	menu_itemtarget_categoryr   rP   s        r   r   zAdmin.add_menu_item  s     !/2H,,00:H '8&*&@&@&D&DX&N#2:%%h/

!!(+y)JJi(r   c                 P    t        j                  d       | j                  ||      S )NzCAdmin._add_menu_item is obsolete - use Admin.add_menu_item instead.)warningswarnr   )r.   r   r   s      r   _add_menu_itemzAdmin._add_menu_item  s"    [\!!)_==r   c                 d    | j                  t        |j                  |      |j                         y)zg
            Add a view to the menu tree

            :param view:
                View to add
        N)r   r   rO   rP   r   s     r   r   zAdmin._add_view_to_menu  s#     	8DIIt4dmmDr   c                 8    | j                   j                  |      S r)   )r   r   r~   s     r   r   zAdmin.get_category_menu_item  s    $$((..r   c                     || _         | j                          || j                  |||       | j                  D ]"  }|j	                  |j                  |              $ y)z
            Register all views with the Flask application.

            :param app:
                Flask application instance
        Nr   )r   r   r   r   r   rn   )r.   r   r`   rR   r   r   s         r   init_appzAdmin.init_app  sk      !&&%! '  KK 	@D""4#8#8#>?	@r   c                    t        | j                  d      st               | j                  _        | j                  j                  j	                  dg       }|D ]d  }|j
                  | j
                  k(  rt        d      |j                  | j                  k(  sA|j                  | j                  k(  s[t        d       |j                  |        || j                  j                  d<   y )N
extensionsrY   z:Cannot have two Admin() instances with same endpoint name.zXCannot assign two Admin() instances with same URL and subdomain to the same application.)
r   r   rL   r   r   rR   r[   r   rg   r   )r.   adminsrA   s      r   r   zAdmin._init_extension  s    txx."&&DHH$$(("5 	PAzzT]]* !3 4 4 uu Q[[DNN%B !O P P	P 	d'-G$r   c                     | j                   S )z0
            Return the menu hierarchy.
        )r   r   s    r   rU   z
Admin.menu  s     zzr   c                     | j                   S )z(
            Return menu links.
        )r   r   s    r   
menu_linkszAdmin.menu_links  s     r   )NNNNNNNNNNN)NNNr)   )r"   rC   rD   rE   r8   r   r   r   r   r   r   r   r   r   r   r   r   r   rU   r   r   r   r   r   r     s     '+%) #'!%##'+C#J%  0415+2  $.'*
*  )4>E/ (,$(@0.$ r   r   )r6   )GET)r6   )#os.pathpathrj   r   	functoolsr   flaskr   r   r   r   r   r	   flask_adminr
   flask_admin._compatr   r   r   r*   flask_admin.menur   r   r   r   r   r%   r2   r7   r4   objectrG   rI   r   r   r   r   r   <module>r      s~       L L  : $ O N",,2D 2:	F 	c$~m]; c$L	4+X 4+nh F h r   