
    >TfE"                     f   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 d dlT d dlmZ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mZ d dlmZ d dlmZ dZ ddg dfZ! G d de          Z" G d dee          Z# G d dej$        j%                  Z& G d dej'        e&          Z(dS )    N)forms)settings)	JSONField)gettext_lazy)SyncedDataMixin)*)
get_configPARAMS)NetBoxModelForm)registry)get_data_backend_choices)get_field_value)CommentFieldr   )FieldSet)
HTMXSelect)ConfigRevisionFormDataSourceFormManagedFileForm  c                        e Zd Z ej        e e                      Z e            Z	 G d d          Z
ed             Z fdZ fdZ xZS )r   )choiceswidgetc                   H    e Zd ZeZg dZd ej        dddd          iZdS )	DataSourceForm.Meta)nametype
source_urlenableddescriptioncommentsignore_rulestagsr"      font-monospacez.cache
*.txt)rowsclassplaceholderattrsN)	__name__
__module____qualname__
DataSourcemodelfieldsr   Textareawidgetsr       ;/var/www/html/netbox-4.1.3/netbox/core/forms/model_forms.pyMetar   $   sX        
 
 
 NEN-#2   
r3   r5   c                     t          dddddddt          d          	          g}| j        r1|                    t          | j        dt          d
          i           |S )Nr   r   r   r   r    r#   r"   Sourcer   zBackend Parameters)r   _backend_fieldsappend)self	fieldsetss     r4   r=   zDataSourceForm.fieldsets3   s{     VV\9mVUcjkltjujuvvv
	  	$-LA6J4K4KLL   r3   c                     t                      j        |i | t          | d          }t          d                             |          }g | _        |r|j                                        D ]\  }}d| }| j                            |           t          j	        |          | j
        |<   | j        r;| j        j        r/| j        j                            |          | j
        |         _        d S d S )Nr   data_backendsbackend_)super__init__r   r   getr:   
parametersitemsr;   copyr0   instanceinitial)	r<   argskwargsbackend_typebackendr   
form_field
field_name	__class__s	           r4   rB   zDataSourceForm.__init__?   s   $)&)))&tV44?+//== ! 	Y$+$6$<$<$>$> Y Y j...
#**:666*.)J*?*?J'= YT]%= Y6:m6N6R6RSW6X6XDK
+3	Y 	YY Yr3   c                     i }| j         D ]/}|                    d          r| j        |         ||dd          <   0|| j        _         t                      j        |i |S )Nr@      )r0   
startswithcleaned_datarG   rD   rA   save)r<   rI   rJ   rD   r   rO   s        r4   rT   zDataSourceForm.saveO   sm    
K 	? 	?Dz** ?'+'8'>
48$#- uww|T,V,,,r3   )r+   r,   r-   r   ChoiceFieldr   r   r   r   r!   r5   propertyr=   rB   rT   __classcell__rO   s   @r4   r   r      s        5(z||  D |~~H
 
 
 
 
 
 
 
 	 	 X	Y Y Y Y Y - - - - - - - - -r3   r   c            	            e Zd Z ej        d          Z ed ed                     eddd ed	                    fZ G d
 d          Z	 fdZ
 fdZ xZS )r   F)requiredupload_filezFile Uploadr8   data_source	data_fileauto_sync_enabledzData Sourcec                       e Zd ZeZdZdS )ManagedFileForm.Meta)r\   r]   r^   N)r+   r,   r-   ManagedFiler/   r0   r   r3   r4   r5   r`   d   s        Br3   r5   c                    t                                                       | j                            d          r;| j                            d          r!t	          j        t          d                    | j                            d          s;| j                            d          s!t	          j        t          d                    | j        S )Nr[   r]   z3Cannot upload a file and sync from an existing filez0Must upload a file or select a data file to sync)rA   cleanrS   rC   r   ValidationErrorr9   )r<   rO   s    r4   rc   zManagedFileForm.cleanh   s      // 	bD4E4I4I+4V4V 	b'*_(`(`aaa $$]33 	_D<M<Q<QR]<^<^ 	_'*\(](]^^^  r3   c                 P   | j         d         r| j         d         j        | j        _        t	          | j        j        d          5 }|                    | j         d                                                    d d d            n# 1 swxY w Y    t                      j	        |i |S )Nr[   zwb+)
rS   r   rG   	file_pathopen	full_pathwritereadrA   rT   )r<   rI   rJ   new_filerO   s       r4   rT   zManagedFileForm.saver   s    ]+ 	H&*&7&F&KDM#dm-u55 Ht0?DDFFGGGH H H H H H H H H H H H H H H uww|T,V,,,s   3BBB)r+   r,   r-   r   	FileFieldr[   r   r9   r=   r5   rc   rT   rW   rX   s   @r4   r   r   Z   s        !%/  K
 	QQ}%5%5666-@qqGWGWXXXI
C C C C C C C C! ! ! ! !- - - - - - - - -r3   r   c                        e Zd Z fdZ xZS )ConfigFormMetaclassc                 0   i }t           D ]S}d|j        |j        d} |j        di |j         |j        t          u rt          |_         |j        di |||j        <   T|                    |           t                      
                    | |||          S )NF)rZ   label	help_textr   )r
   rp   r    updatefield_kwargsfield
_JSONFieldr   r   rA   __new__)mcsr   basesr*   param_fieldsparamrs   rO   s          r4   rv   zConfigFormMetaclass.__new__~   s      
	C 
	CE!". L
  L55%"4555{j((''2u{'B'B\'B'BL$$\"""wwsD%777r3   )r+   r,   r-   rv   rW   rX   s   @r4   rn   rn   |   s8        8 8 8 8 8 8 8 8 8r3   rn   c                       e Zd ZdZ edd ed                     eddd ed	                     ed
d ed                     ed ed                     edddd ed                     edd ed                     edd ed                     ed ed                     eddddd  ed!                     ed" ed#                    f
Z G d$ d%          Z fd&Zd* fd(	Z	d) Z
 xZS )+r   z1
    Form for creating a new ConfigRevision.
    "RACK_ELEVATION_DEFAULT_UNIT_HEIGHT!RACK_ELEVATION_DEFAULT_UNIT_WIDTHzRack Elevationsr8   POWERFEED_DEFAULT_VOLTAGEPOWERFEED_DEFAULT_AMPERAGE!POWERFEED_DEFAULT_MAX_UTILIZATIONPowerENFORCE_GLOBAL_UNIQUEPREFER_IPV4IPAMALLOWED_URL_SCHEMESSecurityBANNER_LOGINBANNER_MAINTENANCE
BANNER_TOPBANNER_BOTTOMBannersPAGINATE_COUNTMAX_PAGE_SIZE
PaginationCUSTOM_VALIDATORSPROTECTION_RULES
ValidationDEFAULT_USER_PREFERENCESzUser PreferencesMAINTENANCE_MODEGRAPHQL_ENABLEDCHANGELOG_RETENTIONJOB_RETENTIONMAPS_URLMiscellaneouscommentzConfig Revisionc            	          e Zd ZeZdZ ej        ddi           ej        ddi           ej        ddi           ej        ddi           ej        ddi           ej        ddi           ej                    dZdS )ConfigRevisionForm.Meta__all__r'   r%   r)   )r   r   r   r   r   r   r   N)	r+   r,   r-   ConfigRevisionr/   r0   r   r1   r2   r   r3   r4   r5   r      s        *EN';K1LMMM"0%.AQ7R"S"S"S(%.9I/JKKK+U^7<L2MNNN!/w@P6Q!R!R!R .g?O5P Q Q Q%u~''
 
r3   r5   c                 B    t                      j        |i | t                      }t          D ]m}t	          ||j                  }	 t          j        |           t          |          t          t          fv r+d                    |          | j        |j                 _        n|| j        |j                 _        n# t          $ r Y nw xY wt          t           |j                  r<d| j        |j                 _        t%          d          | j        |j                 _        | j        |j                 j        }|r|dz  }|t%          d                              |pd          z  }||j        k    r|t%          d          z  }|| j        |j                 _        od S )	Nz, TzBThis parameter has been defined statically and cannot be modified.z<br />z'Current value: <strong>{value}</strong>z&mdash;)valuez
 (default))rA   rB   r	   r
   getattrr   jsondumpsr   tuplelistjoinr0   rH   	TypeErrorhasattrr   disabledr9   rq   formatdefault)r<   rI   rJ   configrz   r   rq   rO   s          r4   rB   zConfigRevisionForm.__init__   s   $)&)))  	: 	:EFEJ//E
5!!!;;5$-//6:ii6F6FDK
+336;DK
+3    x,, 37EJ'045X5 5EJ'1  EJ/9I &X%	DEELLSXSe\eLfffI%%Q|__,	09DK
#--;	: 	:s   	A3B==
C
	C
Tc                     t                                          d          }|                                 |_        |r|                                 |S )NF)commit)rA   rT   render_jsondata)r<   r   rG   rO   s      r4   rT   zConfigRevisionForm.save   sI    77<<u<-- ((** 	MMOOOr3   c                 x    i }| j         D ]/}|| j        v r$| j        |         t          vr| j        |         ||<   0|S )N)declared_fieldsrS   EMPTY_VALUES)r<   r   rN   s      r4   r   zConfigRevisionForm.render_json   sV     . 	A 	AJT...43DZ3PXd3d3d#'#4Z#@Z r3   )T)r+   r,   r-   __doc__r   r9   r=   r5   rB   rT   r   rW   rX   s   @r4   r   r      s        
 	02U\]\]^o\p\p	
 	
 	
 	')EGj7	
 	
 	
 	(-aaiiHHH&QQz]];;;!5|_[\[\]f[g[ghhh!?<III$&8qqOOO+!!4F2G2GHHH 13H/[e?##	
 	
 	
 	#4!5!5666%I*
 
 
 
 
 
 
 
": ": ": ": ":H	 	 	 	 	 	      r3   r   )	metaclass))rF   r   djangor   django.confr   django.forms.fieldsr   ru   django.utils.translationr   r9   core.forms.mixinsr   core.modelsnetbox.configr	   r
   netbox.formsr   netbox.registryr   netbox.utilsr   utilities.formsr   utilities.forms.fieldsr   utilities.forms.renderingr   utilities.forms.widgetsr   r   r   r   r   modelsModelFormMetaclassrn   	ModelFormr   r   r3   r4   <module>r      s                        7 7 7 7 7 7 6 6 6 6 6 6 - - - - - -     , , , , , , , , ( ( ( ( ( ( $ $ $ $ $ $ 1 1 1 1 1 1 + + + + + + : : : : : : : : . . . . . . . . . . . . D"b!:- :- :- :- :-_ :- :- :-z- - - - -o - - -D8 8 8 8 8%,9 8 8 8,^ ^ ^ ^ ^4G ^ ^ ^ ^ ^ ^r3   