
    si                     |    d dl mZ d dlmZ  G d dej                        Zd dlmZ  G d dej                        Zy)    forms)	mark_safec                   :     e Zd ZdZ fdZd fd	ZddlmZ  xZS )CustomModelChoiceWidgeta  
    A custom Django widget for rendering a select input with an optional delete button.

    This widget extends the standard Select widget to include a delete button.
    The URL for the delete action can be dynamically provided via the widget's
    attributes or constructor.

    Attributes:
        delete_url (str): The URL to be used for the delete button's action.
                        If not provided, the button will not be rendered.
    c                 f    d | _         d|v r|j                  d      | _         t        |   |i | y N
delete_urlr
   popsuper__init__selfargskwargs	__class__s      0/var/www/python-projects/worksol/base/widgets.pyr   z CustomModelChoiceWidget.__init__   4    6!$jj6DO$)&)    c           
          t         |   ||||      }|j                  d| j                        }d| d| d|r	d| d| dnd d	}t	        |      S 
Nr
   z
        <div class="pt-2" id="zS">
            <div class="oh-input__group" style="display: flex">
                z
                z<button hx-get="zF" class="oh-btn oh-btn--danger-outline oh-btn--light-bkg" hx-target="#zZ" hx-swap="outerHTML" id="delete-link"><ion-icon name="trash-outline"></ion-icon></button> z+
            </div>
        </div>
        r   rendergetr
   r   	r   namevalueattrsrendereroriginal_htmlr
   custom_htmlr   s	           r   r   zCustomModelChoiceWidget.render       tUE8D YY|T__=
#f %   [e#J</uvzu{  |V  W  km  n n		 %%r   r   r   NN)	__name__
__module____qualname____doc__r   r   djangor   __classcell__r   s   @r   r   r      s    
*&$ r   r   c                   .     e Zd ZdZ fdZd fd	Z xZS )CustomTextInputWidgeta  
    A custom Django widget for rendering a text input with an optional delete button.

    This widget extends the standard TextInput widget to include a delete button.
    The URL for the delete action can be dynamically provided via the widget's
    attributes or constructor.

    Attributes:
        delete_url (str): The URL to be used for the delete button's action.
                        If not provided, the button will not be rendered.
    c                 f    d | _         d|v r|j                  d      | _         t        |   |i | y r	   r   r   s      r   r   zCustomTextInputWidget.__init__>   r   r   c           
          t         |   ||||      }|j                  d| j                        }d| d| d|r	d| d| dnd d	}t	        |      S r   r   r   s	           r   r   zCustomTextInputWidget.renderE   r$   r   r%   )r&   r'   r(   r)   r   r   r+   r,   s   @r   r.   r.   1   s    
*& &r   r.   N)r*   r   django.utils.safestringr   Selectr   	TextInputr.    r   r   <module>r5      s1     -&ell &R .$&EOO $&r   