
    si"&                        d 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 ddlmZ dd	lmZ dd
lmZmZmZ ddlmZmZmZ ddlmZmZmZmZ ddlm Z m!Z! ddl"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) G d de$      Z* ee d       e e!d      d       G d de%                    Z+y )!z
Asset category forms
    )Any)forms)messages)HttpResponse)reverse)method_decorator)gettext_lazy)DynamicCreateBatchNo)AssetCategoryFilterAssetFilterCustomAssetFilter)AssetCategoryForm	AssetFormAssetReportForm)AssetAssetCategoryAssetDocumentsAssetReport)login_requiredpermission_required)HorillaDetailedViewHorillaFormViewHorillaNavViewdispatch)namezasset.view_assetcategoryc                   N     e Zd ZdZeZeZ ed      Z	 fdZ
dedef fdZ xZS )AssetCategoryFormViewz-
    form view for create asset category
    zAsset Category Creationc                     t        |   di |}| j                  j                  j                  rt        d      | j                  _        |S )NzAsset Category Update )superget_context_dataforminstancepk_
form_classverbose_name)selfkwargscontext	__class__s      </var/www/python-projects/worksol/asset/cbv/asset_category.pyr!   z&AssetCategoryFormView.get_context_data%   s?    '*4V499  +,-D+EDOO(    r"   returnc                 $   |j                         rq|j                  j                  rt        d      }nt        d      }|j	                          t        j                  | j                  t        |             t        d      S t        | )  |      S )Nz#Asset category updated successfully#Asset category created successfully]<script>$('#genericModal').removeClass('oh-modal--show');$('.filterButton').click();</script>is_validr#   r$   r%   saver   successrequestr   r    
form_validr(   r"   messager+   s      r,   r7   z AssetCategoryFormView.form_valid,   sr    ==?}}ABABIIKT\\1W:6o  w!$''r-   __name__
__module____qualname____doc__r   r&   r   modelr%   new_display_titler!   r   r7   __classcell__r+   s   @r,   r   r      s>     #JE34(0 (\ ( (r-   r   zasset.add_assetc                   X     e Zd ZdZeZeZ ed      Z	de
fgZ fdZdedef fdZ xZS )AssetFormViewz$
    form view for create asset
    zAsset Creationasset_lot_number_idc                 l   t        |   di |}| j                  j                  d      }|| j                  j
                  d   _        t        j                         | j                  j
                  d   _	        | j                  j                  j                  rt        d      | j                  _        |S )Nasset_category_idzAsset Updater   )r    r!   r)   getr"   fieldsinitialr   HiddenInputwidgetr#   r$   r%   r&   r'   )r(   r)   r*   rG   r+   s       r,   r!   zAssetFormView.get_context_dataF   s    '*4V4 KKOO,?@8I		,-57<7H7H7J		,-499  +,^+<DOO(r-   r"   r.   c                 $   |j                         rq|j                  j                  rt        d      }nt        d      }|j	                          t        j                  | j                  t        |             t        d      S t        | )  |      S NzAsset updated successfullyzAsset created successfullyr1   r2   r8   s      r,   r7   zAssetFormView.form_validO   r    ==?}}8989IIKT\\1W:6o  w!$''r-   )r;   r<   r=   r>   r   r&   r   r?   r%   r@   r
   dynamic_create_fieldsr!   r   r7   rA   rB   s   @r,   rD   rD   :   sL     JE*+35IJK(y (\ ( (r-   rD   c                   N     e Zd ZdZeZeZ ed      Z	 fdZ
dedef fdZ xZS )AssetCategoryDuplicateFormViewz7
    form view for create duplicate asset category
    zAsset Category Duplicatec                    t        |   di |}t        j                  j	                  | j
                  d         }| j                  |      }|j                  j                         D ]{  \  }}t        |t        j                        s!|j                  r|j                  }n|j                  j	                  |d       d}||j                  |<   ||j                  |   _        } ||d<   t        d      | j                  _        |S )	Nobj_ididr#     (copy)r"   	Duplicater   )r    r!   r   objectsrH   r)   r&   rI   items
isinstancer   	CharFieldrJ   r%   r'   	r(   r)   r*   original_objectr"   
field_namefieldinitial_valuer+   s	           r,   r!   z/AssetCategoryDuplicateFormView.get_context_datah   s    '*4V4'//33t{{87L3M8!%!2!2!4 	@J%1==$)MMM'+||'7'7
B'G&H$PM+8Z(2?J'/	@ '(~$r-   r"   r.   c                     |j                         rOt        d      }|j                          t        j                  | j
                  t        |             t        d      S t        | !  |      S )Nr0   r1   )	r3   r%   r4   r   r5   r6   r   r    r7   r8   s      r,   r7   z)AssetCategoryDuplicateFormView.form_validx   sZ    ==?=>GIIKT\\1W:6o  w!$''r-   r:   rB   s   @r,   rR   rR   ]   s>     #JE45 (0 (\ ( (r-   rR   zasset.view_assetc                   N     e Zd ZdZeZeZ ed      Z	 fdZ
dedef fdZ xZS )AssetDuplicateFormViewz2
    form view for create duplicate for asset
    zAsset Duplicatec                 ^   t        |   d	i |}t        j                  j	                  | j
                  d         }| j                  |      }t        j                         |j                  d   _
        |j                  j                         D ]{  \  }}t        |t        j                        s!|j                  r|j                  }n|j                  j	                  |d       d}||j                  |<   ||j                  |   _        } ||d<   t        d      | j                  _        |S )
NrT   rU   rW   rG   rX   rY   r"   rZ   r   )r    r!   r   r[   rH   r)   r&   r   rK   rI   rL   r\   r]   r^   rJ   r%   r'   r_   s	           r,   r!   z'AssetDuplicateFormView.get_context_data   s    '*4V4--++t{{8/D+E8272C2C2E'(/!%!2!2!4 	@J%1==$)MMM'+||'7'7
B'G&H$PM+8Z(2?J'/	@ '(~$r-   r"   r.   c                 $   |j                         rq|j                  j                  rt        d      }nt        d      }|j	                          t        j                  | j                  t        |             t        d      S t        | )  |      S rN   r2   r8   s      r,   r7   z!AssetDuplicateFormView.form_valid   rO   r-   )r;   r<   r=   r>   r   r&   r   r?   r%   r@   r!   r   r7   rA   rB   s   @r,   rf   rf      s=     JE+,"(y (\ ( (r-   rf   c                   ^     e Zd ZdZeZeZ ed      Z	de
f fdZ fdZdedef fdZ xZS )AssetReportFormViewz%
    form view for create button
    zAdd Asset Reportr.   c                 `    t         |          }| j                  j                  d      |d<   |S )Nasset_id)r    get_initialr)   rH   )r(   rJ   r+   s     r,   rm   zAssetReportFormView.get_initial   s,    '%'"kkooj9
r-   c                     t        |   di |}| j                  j                  d      }t        j
                  j                  |      }|| j                  j                  d   _	        |S )Nrl   rU   r   )
r    r!   r)   rH   r   r[   filterr"   rI   queryset)r(   r)   r*   rl   assetr+   s        r,   r!   z$AssetReportFormView.get_context_data   sZ    '*4V4;;??:.$$$105		$-r-   r"   c                 b   |j                         rt        d      }|j                         }|j                  j	                  d      }|r(|D ]#  }t
        j                  j                  ||       % t        j                  | j                  |       | j                         S t        | 5  |      S )Nz Asset report added successfully.files)asset_reportfile)r3   r%   r4   cleaned_datarH   r   r[   creater   r5   r6   r   r    r7   )r(   r"   r9   rq   uploaded_filesru   r+   s         r,   r7   zAssetReportFormView.form_valid   s    ==?:;GIIKE!..227;N* QD"**11u41PQT\\73$$&&w!$''r-   )r;   r<   r=   r>   r   r&   r   r?   r%   r@   dictrm   r!   r   r7   rA   rB   s   @r,   rj   rj      sI     !JE,-T 

( 
(< 
( 
(r-   rj   c                   V     e Zd ZdZ ed      ZdZ e       ZdZ	dZ
deddf fd	Z xZS )
AssetCategoryNavz$
    nav bar for asset category
    zAsset Categoryzcbv/asset_category/filter.htmlr"   z#assetCategoryListr)   r.   Nc                 *   t        |   di | t        d      | _        g | _        | j
                  j                  j                  d      rdt        d       d| _        | j
                  j                  j                  d      r4| j                  j                  t        d      dt        d       d	d
       | j
                  j                  j                  d      r5| j                  j                  t        d      dt        d       dd
       y y )Nz!asset-category-view-search-filteradd_assetcategoryz
                            data-toggle="oh-modal-toggle"
                            data-target="#genericModal"
                            hx-get="zasset-category-creationzX"
                            hx-target="#genericModalBody"
                            Importz
                            onclick="getAssetImportTemplate();"
                            data-toggle="oh-modal-toggle"
                            data-target="#objectCreateModal"
                            hx-get="zasset-importz"
                            hx-target="#objectCreateModalTarget"
                            style="cursor: pointer;"
                        )actionattrs
view_assetExportz
                        data-toggle="oh-modal-toggle"
                        data-target="#objectCreateModal"
                        hx-get="zasset-export-excelz"
                        hx-target="#objectCreateModalTarget"
                        style="cursor: pointer;"
                    r   )r    __init__r   
search_urlactionsr6   userhas_permcreate_attrsappendr%   )r(   r)   r+   s     r,   r   zAssetCategoryNav.__init__   s   "6"!"EF<<%%&9:%% &--F%G$H I! D <<%%&9:LLk"% &-^%<$= >	
 <<%%l3LLk"! "))=!> ? @	 4r-   )r;   r<   r=   r>   r%   	nav_titlefilter_body_templater   filter_instancefilter_form_context_namesearch_swap_targetr   r   rA   rB   s   @r,   r{   r{      sF     "#I;!mO%-& & & &r-   r{   N),r>   typingr   djangor   django.contribr   django.httpr   django.urlsr   django.utils.decoratorsr   django.utils.translationr	   r%   asset.cbv.asset_batch_nor
   asset.filtersr   r   r   asset.formsr   r   r   asset.modelsr   r   r   r   horilla_views.cbv_methodsr   r   horilla_views.generic.cbv.viewsr   r   r   r   rD   rR   rf   rj   r{   r   r-   r,   <module>r      sp     # $  4 6 9 M M E E J J I  .z2%&@A
S(O ( T 3(< .z2%&78zJ(O ( K 3(B .z2%&@A
S!(_ !( T 3!(H .z2%&89
K%(_ %( L 3%(P(/ (D .z2%&89
K1~ 1 L 31r-   