
    vg/                     L   d Z ddlZddl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mZ  G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d d      Z G d d      Z G d de      Z G d d      Zy)z=
Module containing custom filter classes for various models.
    N)forms)Q)	FilterSet)reload_queryset   )AssetAssetAssignmentAssetCategoryAssetRequestc                   "     e Zd ZdZ fdZ xZS )CustomFilterSeta  
    Custom FilterSet class that applies specific CSS classes to filter
    widgets.

    The class applies CSS classes to different types of filter widgets,
    such as NumberInput, EmailInput, TextInput, Select, Textarea,
    CheckboxInput, CheckboxSelectMultiple, and ModelChoiceField. The
    CSS classes are applied to enhance the styling and behavior of the
    filter widgets.
    c                    t        |   |i | t        | j                  j                         | j                  j                  j                         D ]  \  }}| j                  |   }|j                  j                  }t        |t        j                  t        j                  t        j                  f      r)|j                  j                  j                  ddi       nft        |t        j                   f      r)|j                  j                  j                  ddi       n"t        |t        j"                        r(|j                  j                  j                  ddi       nt        |t        j$                  t        j&                  f      r2|j                  j                  j                  j                  ddi       nt        |t        j(                        r(|j                  j                  j                  ddi       nBt        |t        j*                        r(|j                  j                  j                  ddd       t        |t,        j.                        sd	|_         y )
Nclasszoh-input w-100zoh-select oh-select-2zoh-switch__checkboxzoh-select oh-select-2 datezoh-input  w-100)typer   	icontains)super__init__r   formfieldsitemsfiltersfieldwidget
isinstancer   NumberInput
EmailInput	TextInputattrsupdateSelectTextareaCheckboxInputCheckboxSelectMultipleModelChoiceField	DateFielddjango_filters
CharFilterlookup_expr)selfargskwargs
field_namer   filter_widgetr   	__class__s          !/var/www/horilla/asset/filters.pyr   zCustomFilterSet.__init__   s   $)&)		(()!%!1!1!7!7!9 "	0J LL4M"((//F**E,<,<eooN ""))74D*EFFU\\O4""))!8
 FU^^5""))74D*EF''00 ##**007734 FU%;%;=""))!9
 FU__6""))6DU*VW%!:!:;$/!E"	0    )__name__
__module____qualname____doc__r   __classcell__r/   s   @r0   r   r      s    	%0 %0r1   r   c                   6     e Zd ZdZ G d d      Z fdZ xZS )AssetExportFilterz@
    Custom filter class for exporting filtered Asset data.
    c                       e Zd ZdZeZdZy)AssetExportFilter.Meta  
        A nested class that specifies the configuration for the filter.
            model(class): The Asset model is used to filter.
            fields (str): A special value "__all__" to include all fields
                          of the model in the filter.
        __all__Nr2   r3   r4   r5   r   modelr    r1   r0   Metar;   J       	 r1   rA   c                     t        |   |i | | j                  j                  d   j                  j
                  j                  ddi       y )Nasset_purchase_dater   r   )r   r   r   r   r   r   r    )r*   r+   r,   r/   s      r0   r   zAssetExportFilter.__init__U   sD    $)&)		./66<<CCVVDTUr1   )r2   r3   r4   r5   rA   r   r6   r7   s   @r0   r9   r9   E   s    	 	V Vr1   r9   c                        e Zd ZdZ ej
                  d      Z ej
                  d      Z G d d      Z fdZ	d	 Z
 xZS )
AssetFilterz0
    Custom filter set for Asset instances.
    search_methodmethodasset_category_id)r-   c                       e Zd ZdZeZdZy)AssetFilter.Metar<   r=   Nr>   r@   r1   r0   rA   rL   b   rB   r1   rA   c                     t        |   |i | | j                  j                         D ]@  }t	        t        j                               |j                  j                  j                  d<   B y Nid
r   r   r   visible_fieldsstruuiduuid4r   r   r   r*   r+   r,   visibler/   s       r0   r   zAssetFilter.__init__m   X    $)&)yy//1 	AG/24::</@GMM  &&t,	Ar1   c                 h    |j                  |      |j                  |      z  j                         S )z
        Search method
        )asset_name__icontains)1asset_category_id__asset_category_name__icontains)filterdistinct)r*   queryset_values       r0   rG   zAssetFilter.search_methodr   s3    
 OO%O8ooPUoVW
(*	r1   )r2   r3   r4   r5   r'   r(   searchcategoryrA   r   rG   r6   r7   s   @r0   rF   rF   Z   sD     '^&&o>F(~((4GHH	 	A
r1   rF   c                   \     e Zd ZdZ ej
                  d      Z G d d      Z fdZ xZ	S )CustomAssetFilterzF
    Custom filter set for asset assigned to employees instances.
    r   )r)   c                       e Zd ZdZeZddgZy)CustomAssetFilter.Metaa@  
        Specifies the model and fields to be used for filtering AssetAssignment instances.

        Attributes:
        model (class): The model class AssetAssignment to be filtered.
        fields (list): The fields to include in the filter, referring to
                       related AssetAssignment fields.
        asset_id__asset_nameasset_id__asset_statusNr2   r3   r4   r5   r	   r?   r   r@   r1   r0   rA   re      s    	  "$
r1   rA   c                     t        |   |i | | j                  j                         D ]@  }t	        t        j                               |j                  j                  j                  d<   B y rN   rP   rU   s       r0   r   zCustomAssetFilter.__init__   rW   r1   )
r2   r3   r4   r5   r'   r(   rf   rA   r   r6   r7   s   @r0   rc   rc   |   s3     5>44M
 
 A Ar1   rc   c                   h     e Zd ZdZ ej
                  d      ZdefdZ G d d      Z	 fdZ
 xZS )	AssetRequestFilterz7
    Custom filter set for AssetRequest instances.
    rG   rH   r_   c                     |j                  d      }|j                  j                  j                         }|D ]*  }||j	                  |      |j	                  |      z  z  }, |j                         S )9
        This method is used to search employees
         )5requested_employee_id__employee_first_name__icontains)4requested_employee_id__employee_last_name__icontainssplitr?   objectsnoner[   r\   r*   r]   r^   r_   valuesemptyrr   s          r0   rG   z AssetRequestFilter.search_method   s     S!&&++- 	EJO    //IN " E	 ~~r1   c                       e Zd ZdZeZdZy)AssetRequestFilter.Metaa  
        Specifies the model and fields to be used for filtering AssetRequest instances.

        Attributes:
        model (class): The model class AssetRequest to be filtered.
        fields (str): A special value "__all__" to include all fields of the model in the filter.
        r=   N)r2   r3   r4   r5   r   r?   r   r@   r1   r0   rA   ry      s    	 r1   rA   c                     t        |   |i | | j                  j                         D ]@  }t	        t        j                               |j                  j                  j                  d<   B y rN   rP   rU   s       r0   r   zAssetRequestFilter.__init__   rW   r1   r2   r3   r4   r5   r'   r(   r`   rR   rG   rA   r   r6   r7   s   @r0   rk   rk      s>     '^&&o>F   "
 
A Ar1   rk   c                   h     e Zd ZdZ ej
                  d      ZdefdZ G d d      Z	 fdZ
 xZS )	AssetAllocationFilterz:
    Custom filter set for AssetAllocation instances.
    rG   rH   r_   c                     |j                  d      }|j                  j                  j                         }|D ]*  }||j	                  |      |j	                  |      z  z  }, |j                         S )rm   rn   )7assigned_to_employee_id__employee_first_name__icontains)6assigned_to_employee_id__employee_last_name__icontainsrq   ru   s          r0   rG   z#AssetAllocationFilter.search_method   s     S!&&++- 	ELQ    //KP " E	 ~~r1   c                       e Zd ZdZeZdZy)AssetAllocationFilter.MetaD  
        Specifies the model and fields to be used for filtering AssetAllocation instances.

        Attributes:
            model (class): The model class AssetAssignment to be filtered.
            fields (str): A special value "__all__" to include all fields
                          of the model in the filter.
        r=   Nrh   r@   r1   r0   rA   r          	  r1   rA   c                     t        |   |i | | j                  j                         D ]@  }t	        t        j                               |j                  j                  j                  d<   B y rN   rP   rU   s       r0   r   zAssetAllocationFilter.__init__   rW   r1   r{   r7   s   @r0   r}   r}      s>     '^&&o>F   " A Ar1   r}   c                   l     e Zd ZdZ ej
                  d      Z G d d      Z fdZd Z	 fdZ
 xZS )	AssetCategoryFilterz8
    Custom filter set for AssetCategory instances.
    rG   rH   c                       e Zd ZeZdZy)AssetCategoryFilter.Metar=   N)r2   r3   r4   r
   r?   r   r@   r1   r0   rA   r      s    r1   rA   c                     t        |   |i | | j                  j                         D ]@  }t	        t        j                               |j                  j                  j                  d<   B y rN   rP   rU   s       r0   r   zAssetCategoryFilter.__init__   rW   r1   c                 v    |s|S |j                  t        |      t        |      z        j                         S )zW
        Search method to filter by asset category name or related asset name.
        )asset_category_name__icontains)asset__asset_name__icontains)r[   r   r\   r*   r]   namer_   s       r0   rG   z!AssetCategoryFilter.search_method   s;     OU3U34
 (*	r1   c                     t         |   |      }| j                  rQd| j                  v rCt        | j                        j                  }|j                  |j                  dd            }|j                         S )zH
        Filters queryset and applies AssetFilter if necessary.
        	asset__pk)datapkT)flat)asset__pk__in)r   filter_querysetr   rF   qsr[   values_listr\   )r*   r]   assetsr/   s      r0   r   z#AssetCategoryFilter.filter_queryset
  ss    
 7*84 99		1 dii033F$00D0A ' H   ""r1   )r2   r3   r4   r5   r'   r(   r`   rA   r   rG   r   r6   r7   s   @r0   r   r      s;     '^&&o>F A

# #r1   r   c                       e Zd ZdZg dZy)AssetRequestReGroup:
    Class to keep the field name for group by option
    ) r!   )requested_employee_idEmployee)rJ   zAsset Category)asset_request_datezRequest Date)asset_request_statusStatusNr2   r3   r4   r5   r   r@   r1   r0   r   r         Fr1   r   c                       e Zd ZdZg dZy)AssetAllocationReGroupr   )r   assigned_to_employee_idr   assigned_datezAssigned Datereturn_datezReturn DateNr   r@   r1   r0   r   r   )  s    Fr1   r   c                      e Zd ZdZ ej
                  dd      Z ej
                  dd      Z ej                  dd	 e	j                  d
di            Z ej                  dd e	j                  d
di            Z ej                  dd	 e	j                  d
di            Z ej                  dd e	j                  d
di            Zd Z G d d      Zy)AssetHistoryFilterz^
    Custom filter set for AssetAssignment instances for filtering in asset history view.
    rf   r   )r-   r)   return_statusexclude_none)r-   rI   r   gter   r   )r   )r-   r)   r   lter   c                 4    |dk(  r|j                  d      }|S )z`
        Exclude objects with a null return_status from the queryset if value is "True"
        TrueF)return_status__isnull)r[   r   s       r0   r   zAssetHistoryFilter.exclude_noneV  s      F?UCHr1   c                       e Zd ZdZeZdZy)AssetHistoryFilter.Metar   r=   Nrh   r@   r1   r0   rA   r   ^  r   r1   rA   N)r2   r3   r4   r5   r'   r(   r`   returned_assets
DateFilterr   	DateInputreturn_date_gtereturn_date_lteassigned_date_gteassigned_date_lter   rA   r@   r1   r0   r   r   6  s     '^&&){F 0n//">O 0n// uff%56O
 0n// uff%56O
 211"uff%56
 211"uff%56 r1   r   c                       e Zd ZdZg dZy)AssetHistoryReGroupr   )r   )asset_idr   r   r   r   Nr   r@   r1   r0   r   r   l  r   r1   r   )r5   rS   r'   djangor   django.db.modelsr   r   base.methodsr   modelsr   r	   r
   r   r   r9   rF   rc   rk   r}   r   r   r   r   r   r@   r1   r0   <module>r      s        $ ( G G10i 10hV V*/ DA A:'A 'AT(AO (AV*#/ *#Z 
 
3 3l r1   