
    hh                     D    d dl  d dlmZ  G d dej                        Zy)    )*)cmf_custom_field_choicec                       e Zd ZdZej
                  j                  g dz   Zedd       Zed        Z	ed        Z
ed	d       Zy)
CmfCustomFieldChoiceT)list_choicecreate_choiceupdate_choicedelete_choiceNc                 F   t        t        |      }t        ||d       }|r|j                  }t        t        |      }	nA|r>t        j                  j                  j
                  j                  j                  |      }	ny  |	||      }
|||
_        |
j                          |
S )N)namechoice_parent_id)
getattrmodelsmodelcmf	BaseModeldpdata_drivergen_custom_choice_modelcust_field_conf_idsave)cls
model_name
field_namevaluer   db_choice_table_namer   
base_model
base_fieldr   
new_choices              4./modules/settings/models/cmf_custom_field_choice.pyr   z"CmfCustomFieldChoice.create_choice   s    VZ0
ZT:
#))JFJ/E $

,,//;;SSThi8HI
),>J)    c                     t        t        |      }t        ||d       }|j                  }t        t        |      }	|	j                  ||dg      }
||
|<   |
j	                          |
S )Nr   )idfields)r   r   r   getr   )r   r   r   r#   choice_fieldr   r   r   field_model_namer   choices              r    r	   z"CmfCustomFieldChoice.update_choice-   se    VZ0
ZT:
%++ 01b,8L)MN$|r!   c                 2   t        t        |      }t        ||      }|j                  }t        t        |      }|j                  |      }|j	                          |j                  |      }	|	r)|	D ]#  }
t        j                  |||
j                         % y y )N)r#   )r   )	r   r   r   r%   deletelistr   r
   r#   )r   r   r   r#   r   r   r'   r   r   childrencs              r    r
   z"CmfCustomFieldChoice.delete_choice8   s    VZ0
Z4
%++ 01YY"Y%
::r:2 Q$22:z144PQ r!   c                     t        t        |      }t        ||d       }|sg S |j                  }|sg S t        t        |      }d|i} |j                  ddg di|S )Nr   r$   )r#   r   r   
cmf_hiddenr    )r   r   r   r+   )r   r   r   r   r   r   r   filter_paramss           r    r   z CmfCustomFieldChoice.list_choiceG   sk    VZ0
ZT:
I%%
I
+ ./ABuzzy!gykxyyr!   )NNN)N)__name__
__module____qualname__	api_allowr   r   api_methodsclassmethodr   r	   r
   r   r0   r!   r    r   r      sy     I)>>JJ N
 
K  (   Q Q z zr!   r   N)cmf.includemodules.settings.fieldsr   r   r0   r!   r    <module>r:      s"     ;Rz2GG Rzr!   