
    vg                     Z    d dl Z d dlZd dlmZ d dlmZ d dlmZmZ d Z	d Z
d Zd Zd	 Zy)
    N)User)ContentType)APP_URLSDYNAMIC_URL_PATTERNSc                 h    t         j                  j                  | |      }|j                         }|S )as  
    Retrieves the model class for the given app label and model name using Django's ContentType framework.

    Args:
        app_label (str): The label of the application where the model is defined.
        model (str): The name of the model to retrieve.

    Returns:
        Model: The Django model class corresponding to the specified app label and model name.

    	app_labelmodel)r   objectsgetmodel_class)r	   r
   content_typer   s       #/var/www/horilla/horilla/methods.pyget_horilla_model_classr   
   s3     &&**Ye*LL**,K    c                 D   |j                  d      }|D ]}  }t        j                  t              5  t	        dd      }t        | j                         |      r | j                  d      j                         } ddd       t        | |d      } | | | S  | S # 1 sw Y   xY w)a  
    Retrieves the value of a nested attribute from a related object dynamically.

    Args:
        obj: The base object from which to start accessing attributes.
        attribute_path (str): The path of the nested attribute to retrieve, using
        double underscores ('__') to indicate relationship traversal.

    Returns:
        The value of the nested attribute if it exists, or None if it doesn't exist.
    __payrollcontractr   T)	is_activeN)	split
contextlibsuppress	Exceptionr   
isinstancefirstfiltergetattr)objattribute_path
attributesattrContracts        r   dynamic_attrr$      s      %%d+J   + 	9.*UH#))+x0jj4j0668	9
 c4&;J J	9 	9s   ABB	c                    t        | t              r| g} t        j                  j	                  d      }| D ]:  }|j                  d      \  }}|t        j                  j	                  ||      z  }< |j                         S )aB  
    Filters users who have any of the specified permissions or are superusers.

    :param permissions: A list of permission strings in the format 'app_label.codename'
                        or a single permission string.
    :return: A queryset of users who have any of the specified permissions or are superusers.
    T)is_superuser.)user_permissions__codename)user_permissions__content_type__app_label)r   strr   r   r   r   distinct)permissionsusers_with_permissionspermr	   codenames        r   horilla_users_with_permsr0   5   s     +s#"m "\\00d0C  
"jjo	8$,,"5"5'/6? #6 #
 	

 "**,,r   c                 ~    | j                   j                         }|j                  dd        |j                         }|S )Ninstances_ids)GETcopypop	urlencode)requestget_dataprevious_datas      r   get_urlencoder:   O   s6    {{!HLL$'&&(Mr   c                 .   t         D ]P  }	 t        j                  |      }t        |dd      }|r)|D ]$  }|j                  | k(  s|j                  |        n R | t        v rt        j
                  |        yy# t        $ r t        d| d       Y w xY w)zFFunction to remove a dynamically added URL from any app's urlpatterns.urlpatternsNzModule z not found. Skipping...)	r   	importlibimport_moduler   nameremoveModuleNotFoundErrorprintr   )	path_infoapp_urlsurls_moduler<   paths        r   remove_dynamic_urlrG   V   s      ?	?#11(;K!+}dCK' DyyI-#**40?$ ((##I. )	 # 	?GH:%<=>	?s   8A9A99BB)r   r=   django.contrib.auth.modelsr   "django.contrib.contenttypes.modelsr   horilla.horilla_settingsr   r   r   r$   r0   r:   rG    r   r   <module>rL      s-      + : C"4-4/r   