
    恕f                     Z    d dl mZmZ d dlmZ d dlmZ d dlmZm	Z	 d	dZ
 G d de      Zy)
    )requestredirect)tools)	text_type)get_redirect_targetflash_errorsNc                       fd}|S )aJ  
        Use this decorator to expose actions that span more than one
        entity (model, file, etc)

        :param name:
            Action name
        :param text:
            Action text.
        :param confirmation:
            Confirmation text. If not provided, action will be executed
            unconditionally.
    c                     f| _         | S N)_action)fconfirmationnametexts    R/var/www/feuerwehr-webapp/venv/lib/python3.12/site-packages/flask_admin/actions.pywrapzaction.<locals>.wrap   s    4.	     )r   r   r   r   s   ``` r   actionr   	   s     Kr   c                   0    e Zd ZdZd Zd Zd Zd ZddZy)	ActionsMixina  
        Actions mixin.

        In some cases, you might work with more than one "entity" (model, file, etc) in
        your admin view and will want to perform actions on a group of entities simultaneously.

        In this case, you can add this functionality by doing this:
        1. Add this mixin to your administrative view class
        2. Call `init_actions` in your class constructor
        3. Expose actions view
        4. Import `actions.html` library and add call library macros in your template
    c                      g | _         i | _        y)z*
            Default constructor.
        N)_actions_actions_data)selfs    r   __init__zActionsMixin.__init__+   s     r   c                    g | _         i | _        t        |       D ]n  }t        j                  | |      }t        |d      s&|j                  \  }}}| j                   j                  ||f       t        | |      ||f| j                  |<   p y)zU
            Initialize list of actions for the current administrative view.
        r   N)	r   r   dirr   get_dict_attrhasattrr   appendgetattr)r   pattrr   r   descs         r   init_actionszActionsMixin.init_actions2   s     T 	JA&&tQ/DtY'#'<< dD$$dD\2
 -4D!,<dD+I""4(	Jr   c                      y)zt
            Verify if action with `name` is allowed.

            :param name:
                Action name
        Tr   )r   r   s     r   is_action_allowedzActionsMixin.is_action_allowedF   s     r   c                     g }i }| j                   D ]X  }|\  }}| j                  |      s|j                  |t        |      f       | j                  |   d   }|sKt        |      ||<   Z ||fS )zH
            Return a list and a dictionary of allowed actions.
           )r   r(   r!   r   r   )r   actionsactions_confirmationactr   r   r   s          r   get_actions_listzActionsMixin.get_actions_listO   s     !== 	ICJD$%%d+io67#11$7:1:<1H(.	I ,,,r   Nc                    | j                         }| j                  |      rrt        j                  j	                  d      }|j
                  j                  }| j                  j                  |      }|r-| j                  |      r |d   |      }||S t        |d       |r| j                  d|z         }t        |      S t               xs | j                  d      }t        |      S )a   
            Handle action request.

            :param return_view:
                Name of the view to return to after the request.
                If not provided, will return user to the return url in the form
                or the list view.
        rowidr   z#Failed to perform action. %(error)s)message.z.index_view)action_formvalidate_formr   formgetlistr   datar   getr(   r   get_urlr   r   )r   return_viewr5   idsr   handlerresponseurls           r   handle_actionzActionsMixin.handle_actionb   s     !d#,,&&w/C[[%%F((,,V4G411&9%71:c?'#O'LM,,s[01C } &'F4<<+FC}r   r   )	__name__
__module____qualname____doc__r   r&   r(   r.   r?   r   r   r   r   r      s!     J(-&r   r   r   )flaskr   r   flask_adminr   flask_admin._compatr   flask_admin.helpersr   r   r   objectr   r   r   r   <module>rI      s&    #  ) A(d6 dr   