
    siD                         d Z ddlm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 dd	lmZ d
 Z G d de      Zy)z
accessibility/filters.py
    )reduceN)Q)render_to_string)gettext)Employee)HorillaFilterSet)_thread_localsc                 J    t        t        dd      }| |d}t        d|      }|S )zK
    Render the form fields as HTML table rows with Bootstrap styling.
    requestN)formr   z#accessibility/filter_form_body.html)getattrr	   r   )selfr   context
table_htmls       9/var/www/python-projects/worksol/accessibility/filters.py_filter_form_structuredr      s4     ni6GG ""GQJ    c                       e Zd ZdZ fdZ ej                  ej                  j                         dd e
d            Z ej                  ej                  j                          e
d            Z e
d	       e
d
       e
d       e
d       e
d       e
d       e
d       e
d       e
d       e
d      d
Z G d d      Zd Z xZS )AccessibilityFilterzC
    Accessibility Filter with dynamic OR logic between fields
    c                 l    t        |   |i | t        | j                        | j                  _        y N)super__init__r   r   
structured)r   argskwargs	__class__s      r   r   zAccessibilityFilter.__init__#   s*    $)&)6tyyA		r   pkinr   )queryset
field_namelookup_exprlabelzExclude Employees)r    r#   zJob Position
Departmentz	Work TypezEmployee TypezJob RoleCompanyShiftTagsGroupsPermissions)
#employee_work_info__job_position_id!employee_work_info__department_id employee_work_info__work_type_id$employee_work_info__employee_type_idemployee_work_info__job_role_idemployee_work_info__company_idemployee_work_info__shift_idemployee_work_info__tagsemployee_user_id__groups"employee_user_id__user_permissionsc                       e Zd ZdZeZg dZy)AccessibilityFilter.Metaz3
        Meta class for additional options
        )r   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   N)__name__
__module____qualname____doc__r   modelfields r   r   Metar5   ?   s    	 
r   r=   c           	      b   g }| j                   j                  D ]  }| j                  j                  |      }|s!t	        |t
        t        f      s|g}	 |D cg c]  }|st        |       }}d|v r |j                  t        di | d|i       z|j                  t        di | d|i        |r|j                  t        d |            }| j                  j                  d      }|r+t	        |t
        t        f      s|g}|j                  |      }|S c c}w # t        $ r Y w xY w)zM
        Dynamically apply OR condition between all specified fields
        ____id__in__inc                     | |z  S r   r<   )xys     r   <lambda>z5AccessibilityFilter.filter_queryset.<locals>.<lambda>m   s
    1q5 r   excluded_employees)pk__inr<   )r=   r;   dataget
isinstancelisttupleint
ValueErrorappendr   filterr   exclude)r   r    or_conditionsfieldfield_valuevrF   s          r   filter_querysetz#AccessibilityFilter.filter_querysetS   s3    YY%% 	ME))--.K!+e}=#.-K3>"Da!3q6"DK"D
 5=!(()Ox.@+-N)OP!(()Ktnk-J)KL#	M& v.@-'PQH!YY]]+?@04-@&8%9"''/A'BH' #E! s*   D!D D-D!D!!	D.-D.)r6   r7   r8   r9   r   django_filtersModelMultipleChoiceFilterr   objectsall_r   rF   verbose_namer=   rV   __classcell__)r   s   @r   r   r      s    B 
2	1	1!!%%'
m	
B BAA!!%%'#$ 01/@-.|_,-kN01/0B+,Z=*+I,()'
$%fI$%hK./.>L
 
("r   r   )r9   	functoolsr   rW   django.db.modelsr   django.template.loaderr   django.utils.translationr   r[   employee.modelsr   horilla.filtersr   horilla.horilla_middlewaresr	   r   r   r<   r   r   <module>re      s8       3 1 $ , 6
W* Wr   