
    n^j                        d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZmZ ddlmZmZmZmZ  eed       e ed      d       G d de                    Z eed       e ed      d       G d de                    Z eed       e ed      d       G d de                    Z eed       e ed      d       G d de                    Z y)zX
budget/cbv/allocation.py
========================
CBV views for BudgetAllocation CRUD.
    )Any)messages)HttpResponse)reversereverse_lazy)method_decorator)gettext_lazy)BudgetAllocationFilter)BudgetAllocationForm)BudgetAllocation)login_requiredpermission_required)HorillaFormViewHorillaListViewHorillaNavViewTemplateViewdispatch)namezbudget.view_budgetallocationc                       e Zd ZdZy)BudgetAllocationViewPagez#cbv/allocation/allocation_home.htmlN)__name__
__module____qualname__template_name     9/var/www/python-projects/worksol/budget/cbv/allocation.pyr   r      s	     :Mr   r   c                   N     e Zd Zdeddf fdZ ed      Z e       ZdZ	dZ
 xZS )BudgetAllocationNavViewkwargsreturnNc                 z    t        |   di | t        d      | _        d| _        dt        d       d| _        y )Nbudget-allocation-listz#listContainerzhx-get="zbudget-allocation-createzY" hx-target="#genericModalBody" data-target="#genericModal" data-toggle="oh-modal-toggle"r   )super__init__r   
search_urlsearch_swap_targetr   create_attrsselfr    	__class__s     r   r%   z BudgetAllocationNavView.__init__$   sI    "6"!":;"2|$>?@ A, , 	r   zBudget Allocationszcbv/allocation/filter.htmlform)r   r   r   r   r%   _	nav_titler
   filter_instancefilter_body_templatefilter_form_context_name__classcell__r+   s   @r   r   r   !   s7    	
 	
 	
 &'I,.O7%r   r   c                       e Zd ZeZeZdeddf fdZ e	d      df e	d      df e	d	      d
f e	d      df e	d      df e	d      df e	d      df e	d      df e	d      dfg	Z
g dZdddddddZdZ fdZdZ xZS )BudgetAllocationListViewr    r!   Nc                    t        |   di | d| _        t        d      | _        g | _        | j                  j                  j                  d      r(| j
                  j                  t        d      ddd       | j                  j                  j                  d      r)| j
                  j                  t        d	      d
dd       y y )Nzbudget-allocation-containerr#   zbudget.change_budgetallocationEditzcreate-outlineaA  
                        class="oh-btn oh-btn--light-bkg w-100"
                        hx-get='{get_update_url}?instance_ids={ordered_ids}'
                        hx-target="#genericModalBody"
                        data-toggle="oh-modal-toggle"
                        data-target="#genericModal"
                    )actioniconattrszbudget.delete_budgetallocationDeleteztrash-outlineao  
                        class="oh-btn oh-btn--danger-outline oh-btn--light-bkg w-100"
                        hx-get="{get_delete_url}?model=budget.BudgetAllocation&pk={pk}"
                        data-toggle="oh-modal-toggle"
                        data-target="#deleteConfirmation"
                        hx-target="#deleteConfirmationBody"
                    r   )r$   r%   view_idr   r&   actionsrequestuserhas_permappendr-   r)   s     r   r%   z!BudgetAllocationListView.__init__;   s    "6"4!":;<<%%&FGLLi,
 <<%%&FGLLk+
 Hr   ItemitemFYfiscal_yearPeriodperiod_labelu   Allocated (₦)allocated_amountu   Committed (₦)committed_amountu   Approved (₦)approved_amountu   Disbursed (₦)disbursed_amountBalancebalance_displayStatusoverrun_indicator))zFiscal YearrE   )	AllocatedrH   )	DisbursedrK   z style="width:90px !important" z  style="width:150px !important" z  style="width:160px !important" )rE   rH   rI   rJ   rK   r8   z:
        id="budgetAllocationTr{get_delete_instance}"
    c                     t        |   |i |j                  d      }| j                  j                  j                  d      }|r|j                  |      }|S )Nitem__sub_head__headrC   )item_id)r$   get_querysetselect_relatedr>   GETgetfilter)r*   argsr    qsitem_pkr+   s        r   rU   z%BudgetAllocationListView.get_queryset}   sU    W!4262AABXY,,""&&v.7+B	r      )r   r   r   r   modelr
   filter_classr   r%   r-   columnssortby_mappingheader_attrs	row_attrsrU   records_per_pager2   r3   s   @r   r5   r5   5   s     E)L! ! !H 
6F	
4- 	
8n%	
	12	
	12	
	/0	
	12	
9()	
8)*
GN =BBAB8LI r   r5   zbudget.add_budgetallocationc                   N     e Zd ZeZeZ ed      ZdZ	 fdZ
dedef fdZ xZS )BudgetAllocationFormViewzAdd Budget Allocationz#cbv/allocation/allocation_form.htmlc                     t         |          }| j                  j                  j	                  d      xs% | j                  j
                  j	                  d      }|r||d<   |S )NrC   )r$   get_initialr>   rW   rX   POST)r*   initialr\   r+   s      r   rh   z$BudgetAllocationFormView.get_initial   sU    '%',,""&&v.O$,,2C2C2G2G2O%GFOr   r,   r!   c                 T   |j                         r|j                  j                  r*t        j                  | j
                  t        d             n)t        j                  | j
                  t        d             |j                          | j                         S t        | )  |      S )NzAllocation updated.zAllocation created.)is_validinstancepkr   successr>   r-   saver   r$   
form_valid)r*   r,   r+   s     r   rq   z#BudgetAllocationFormView.form_valid   su    ==?}}  q1F/GH  q1F/GHIIK$$&&w!$''r   )r   r   r   r   r^   r   
form_classr-   new_display_titler   rh   r   rq   r2   r3   s   @r   rf   rf      s>     E%J129M(3 ( ( (r   rf   N)!__doc__typingr   django.contribr   django.httpr   django.urlsr   r   django.utils.decoratorsr   django.utils.translationr	   r-   budget.filtersr
   budget.formsr   budget.modelsr   horilla_views.cbv_methodsr   r   horilla_views.generic.cbv.viewsr   r   r   r   r   r   r5   rf   r   r   r   <module>r      s    # $ - 4 6 1 - * I  .z2%&DEJW:| : X 3: .z2%&DEJW&n & X 3&$ .z2%&DEJWM M X 3M` .z2%&CD:V( ( W 3(r   