
    \j	                     &    d Z ddlZ G d de      Zy)zG
Mixin to dynamically select only a subset of fields per DRF resource.
    Nc                   ,     e Zd ZdZe fd       Z xZS )DynamicFieldsMixinz{
    A serializer mixin that takes an additional `fields` argument that controls
    which fields should be displayed.
    c           	      \   t         t        | 
  }t        | d      s|S | j                  | k(  }| j
                  | j                  k(  xr t        | j
                  dd      }|s|s|S 	 | j                  d   }t        |dt        |dd            }|t        j                  d	       	 |j                  d
d      j                  d      }	 |j                  dd      j                  d      }t        |j                               }||}	nt        t!        d|            }	t        t!        d|            }
|D ]/  }||	vr|j#                  |d       ||
v s|j#                  |d       1 |S # t        $ r t        j                  d       |cY S w xY w# t        $ r d}Y w xY w# t        $ r g }Y w xY w)a  
        Filters the fields according to the `fields` query parameter.

        A blank `fields` parameter (?fields) will remove all fields. Not
        passing `fields` will pass all fields individual fields are comma
        separated (?fields=id,name,url,email).

        _contextmanyFrequestz'Context does not have access to requestquery_paramsGETNz/Request object does not contain query paramtersfields,omit)superr   r   hasattrrootparentgetattrcontextKeyErrorwarningswarngetsplitAttributeErrorsetkeysfilterpop)selfr   is_rootparent_is_list_rootr   paramsfilter_fieldsomit_fieldsexistingallowedomittedfield	__class__s               E/root/env/lib/python3.12/site-packages/drf_dynamic_fields/__init__.pyr   zDynamicFieldsMixin.fields   s    )47tZ(M ))t#"kkTYY6^74;;PVX];^.M	ll9-G ^WWeT%B
 >MMKL	!"JJx6<<SAM	 **VT288=K
 v{{}% G&}56G fT;/0 	(EG#

5$'

5$'	( S  	MMCDM	  	! M	!
  	K	s6   &E& %!F !F & F	F	FFF+*F+)__name__
__module____qualname____doc__propertyr   __classcell__)r(   s   @r)   r   r      s    
 A A    r   )r-   r   objectr    r0   r)   <module>r3      s    H Hr0   