
    >Tf                         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mZ d d	lmZ d d
lmZ dZ e j        d          Z G d deej                  ZdS )    N)settings)ValidationError)models)reverse)gettext   )ManagedFileRootPathChoices)SyncedDataMixin)RestrictedQuerySet)ManagedFileznetbox.core.filesc                       e Zd ZdZ ej         ed          d          Z ej         ed          ddd          Z ej	         ed          d	e

          Z ej         ed          d ed                    Z ej                    ZdZ G d d          Zd Zd Zed             Zed             Zd Zd Z fdZ fdZ xZS )r   z
    Database representation for a file on disk. This class is typically wrapped by a proxy class (e.g. ScriptModule)
    to provide additional functionality.
    createdT)verbose_nameauto_now_addzlast updatedF)r   editableblanknullz	file rooti  )r   
max_lengthchoicesz	file pathz.File path relative to the designated root path)r   r   	help_textc                       e Zd ZdZ ej        dd          fZ ej        dd          gZ e	d          Z
 e	d          ZdS )ManagedFile.Meta	file_root	file_pathz(%(app_label)s_%(class)s_unique_root_path)fieldsnamecore_managedfile_root_pathzmanaged filezmanaged filesN)__name__
__module____qualname__orderingr   UniqueConstraintconstraintsIndexindexes_r   verbose_name_plural     6/var/www/html/netbox-4.1.3/netbox/core/models/files.pyMetar   2   sy        -#F#1?  
 FL :A]^^^
 q((a00r*   r,   c                     | j         S N)r   selfs    r+   __str__zManagedFile.__str__@   s
    yr*   c                 0    t          d| j        g          S )Nzcore:managedfile)args)r   pkr/   s    r+   get_absolute_urlzManagedFile.get_absolute_urlC   s    )	::::r*   c                     | j         S r.   )r   r/   s    r+   r   zManagedFile.nameF   s
    ~r*   c                 p    t           j                            |                                 | j                  S r.   )ospathjoin_resolve_root_pathr   r/   s    r+   	full_pathzManagedFile.full_pathJ   s&    w||D3355t~FFFr*   c                 J    t           j        t           j        d| j                 S )N)scriptsreports)r   SCRIPTS_ROOTREPORTS_ROOTr   r/   s    r+   r;   zManagedFile._resolve_root_pathN   s)    ,,
 
 . 	r*   c                     | j         rLt          j                            | j                  | _        | j                             | j        d           d S d S )NT)	overwrite)	data_filer8   r9   basename	data_pathr   write_to_diskr<   r/   s    r+   	sync_datazManagedFile.sync_dataT   sU    > 	IW--dn==DNN((4(HHHHH	I 	Ir*   c           	         t                                                       | j        r0| j        s)t          j                            | j                  | _        | j        j	        j
                            | j        | j                                      | j                                                  r?t!          d| j        j                                         d| j         d| j         d          d S )Nr   )r4   zA z% with this file path already exists (/z).)supercleanrD   r   r8   r9   rE   rF   _metamodelobjectsfilterr   excluder4   existsr   r   lower)r0   	__class__s    r+   rL   zManagedFile.cleanY   s    > 	>$. 	>W--dn==DN :#**T^t~*^^ffjnjqfrryy{{ 	@!~TZ,2244~~[_[i~~lplz~~~@ @ @	@ 	@r*   c                     	 t          j        | j                   n# t          $ r Y nw xY w t	                      j        |i |S r.   )r8   remover<   FileNotFoundErrorrK   delete)r0   r3   kwargsrT   s      r+   rX   zManagedFile.deleted   sZ    	Idn%%%%  	 	 	D	 uww~t.v...s    
**)r   r    r!   __doc__r   DateTimeFieldr'   r   last_updated	CharFieldr	   r   FilePathFieldr   r   
as_managerrO   _netbox_privater,   r1   r5   propertyr   r<   r;   rH   rL   rX   __classcell__)rT   s   @r+   r   r      s         #f"Qy\\  G (6'Q~&&	  L ! Q{^^*  I
 %$Q{^^!DEE  I , +--GO1 1 1 1 1 1 1 1  ; ; ;   X G G XG  I I I
	@ 	@ 	@ 	@ 	@/ / / / / / / / /r*   r   )loggingr8   django.confr   django.core.exceptionsr   	django.dbr   django.urlsr   django.utils.translationr   r'   r   r	   netbox.models.featuresr
   utilities.querysetsr   __all__	getLoggerloggerModelr   r)   r*   r+   <module>ro      s    				             2 2 2 2 2 2             1 1 1 1 1 1 0 0 0 0 0 0 2 2 2 2 2 2 2 2 2 2 2 2 
	.	/	/V/ V/ V/ V/ V//6< V/ V/ V/ V/ V/r*   