
    >Tf(                     
   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T d dlT d dlmZmZ d d	lmZmZ d d
lmZ dZ G d dee          Z G d dee          Z G d deee          Z G d deee          ZdS )    )GenericRelation)ValidationError)models)reverse)gettext_lazy)TimeZoneField)*)NestedGroupModelPrimaryModel)ContactsMixinImageAttachmentsMixin)NaturalOrderingField)LocationRegionSite	SiteGroupc                   V    e Zd ZdZ edddd          Z G d d          Zd	 Zd
 ZdS )r   a;  
    A region represents a geographic collection of sites. For example, you might create regions representing countries,
    states, and/or cities. Regions are recursively nested into a hierarchy: all sites belonging to a child region are
    also considered to be members of its parent and ancestor region(s).
    ipam.VLANGroup
scope_typescope_idregiontocontent_type_fieldobject_id_fieldrelated_query_namec                      e Zd Z ej        dd           ej        dd ed           ed          	           ej        d
d           ej        dd ed           ed          	          fZ ed          Z ed          Z	dS )Region.Metaparentname#%(app_label)s_%(class)s_parent_namefieldsr!   r!   %(app_label)s_%(class)s_nameTparent__isnullz1A top-level region with this name already exists.r$   r!   	conditionviolation_error_messager    slug#%(app_label)s_%(class)s_parent_slugr-   %(app_label)s_%(class)s_slugz1A top-level region with this slug already exists.r   regionsN
__name__
__module____qualname__r   UniqueConstraintQ_constraintsverbose_nameverbose_name_plural     6/var/www/html/netbox-4.1.3/netbox/dcim/models/sites.pyMetar   '   s        #F#):   $F# 3!4000()*](^(^	   $F#):   $F# 3!4000()*](^(^	  
, q{{a	llr=   r?   c                 0    t          d| j        g          S )Nzdcim:regionargsr   pkselfs    r>   get_absolute_urlzRegion.get_absolute_urlA   s    }DG95555r=   c                     t           j                            t          |           t          |                                           z                                            S )N)r   )
region__inr   objectsfilterr7   get_descendantscountrE   s    r>   get_site_countzRegion.get_site_countD   sQ    |""TNNN--//0001
 
 %''	r=   N	r3   r4   r5   __doc__r   vlan_groupsr?   rG   rO   r<   r=   r>   r   r      s         
 "/'"#	  K+ + + + + + + +46 6 6    r=   r   c                   V    e Zd ZdZ edddd          Z G d d          Zd	 Zd
 ZdS )r   a  
    A site group is an arbitrary grouping of sites. For example, you might have corporate sites and customer sites; and
    within corporate sites you might distinguish between offices and data centers. Like regions, site groups can be
    nested recursively to form a hierarchy.
    r   r   r   
site_groupr   c                      e Zd Z ej        dd           ej        dd ed           ed          	           ej        d
d           ej        dd ed           ed          	          fZ ed          Z ed          Z	dS )SiteGroup.Metar   r"   r#   r%   r&   Tr'   z5A top-level site group with this name already exists.r)   r,   r.   r/   r0   z5A top-level site group with this slug already exists.z
site groupzsite groupsNr2   r<   r=   r>   r?   rV   \   s        #F#):   $F# 3!4000()*a(b(b	   $F#):   $F# 3!4000()*a(b(b	  
, qa..r=   r?   c                 0    t          d| j        g          S )Nzdcim:sitegrouprA   rC   rE   s    r>   rG   zSiteGroup.get_absolute_urlv   s    'twi8888r=   c                     t           j                            t          |           t          |                                           z                                            S )N)group)	group__inrJ   rE   s    r>   rO   zSiteGroup.get_site_county   sQ    |""DMMM,,..///0
 
 %''	r=   NrP   r<   r=   r>   r   r   O   s         
 "/'"'	  K/ / / / / / / /49 9 9    r=   r   c            
          e Zd ZdZ ej         ed          dd ed                    Z eddd          Z	 ej
         ed          dd	          Z ej         ed
          deej                  Z ej        dej        ddd          Z ej        dej        ddd          Z ej        dej        ddd          Z ej         ed          dd ed                    Z ej        ddd          Z ed          Z ej         ed          dd ed                    Z ej         ed          dd ed                    Z ej         ed          dddd ed           !          Z ej         ed"          d#ddd ed           !          Z ed$d%d&d'(          Z d)Z! G d* d+          Z"d, Z#d- Z$d. Z%d/S )0r   z
    A Site represents a geographic location within a network; typically a building or campus. The optional facility
    field can be used to include an external designation, such as a data center name (e.g. Equinix SV6).
    r!   d   TzFull name of the site)r:   
max_lengthunique	help_text)target_fieldr]   blankr-   )r:   r]   r^   status2   r:   r]   choicesdefaultzdcim.Regionsitesr   	on_deleterelated_namera   nullzdcim.SiteGrouptenancy.Tenantfacility Local facility ID or descriptionr:   r]   ra   r_   zipam.ASN)r   rj   ra   )ra   zphysical address   z!Physical location of the buildingzshipping addressz&If different from the physical addresslatitude      z,GPS coordinate in decimal format (xx.yyyyyy))r:   
max_digitsdecimal_placesra   rk   r_   	longitude	   r   r   r   siter   )rb   r   rY   tenantrm   	time_zonephysical_addressshipping_addressrq   rv   descriptionc                   >    e Zd ZdZ ed          Z ed          ZdS )	Site.Meta)_namerx   rg   N)r3   r4   r5   orderingr8   r:   r;   r<   r=   r>   r?   r      s0        qyyajjr=   r?   c                     | j         S Nr%   rE   s    r>   __str__zSite.__str__   s
    yr=   c                 0    t          d| j        g          S )Nz	dcim:siterA   rC   rE   s    r>   rG   zSite.get_absolute_url   s    {$'3333r=   c                 J    t           j                            | j                  S r   )SiteStatusChoicescolorsgetrb   rE   s    r>   get_status_colorzSite.get_status_color   s     '++DK888r=   N)&r3   r4   r5   rQ   r   	CharFieldr8   r!   r   r   	SlugFieldr-   r   STATUS_ACTIVErb   
ForeignKeySET_NULLr   rY   PROTECTry   rm   ManyToManyFieldasnsr   rz   r{   r|   DecimalFieldrq   rv   r   rR   clone_fieldsr?   r   rG   r   r<   r=   r>   r   r      sQ         6QvYY!+,,	  D !   E
 6QvYY  D
 VQx[[!!/	  F V/  F F/  E V.  F  vQz]]!677	  H "6!  D
   I (v'Q)**!788	   (v'Q)**!<==	   #v"Qz]]!BCC  H $#Q{^^!BCC  I "/'"!	  KL
) ) ) ) ) ) ) )
  4 4 49 9 9 9 9r=   r   c                   b    e Zd ZdZ ej        dej        d          Z ej         e	d          de
e
j                  Z ej        dej        dd	d	
          Z ej         e	d          dd	 e	d                    Z edddd          ZdZdZ G d d          Zd Zd Z fdZ xZS )r   z
    A Location represents a subgroup of Racks and/or Devices within a Site. A Location may represent a building within a
    site, or a room within a building, for example.
    	dcim.Site	locations)r   ri   rj   rb   rc   rd   rl   Trh   rm   rn   ro   r   r   r   locationr   )rx   r    rb   ry   rm   r}   )r   c                   "   e Zd ZddgZ ej        dd           ej        dd ed	           ed
                     ej        dd           ej        dd ed	           ed                    fZ ed          Z	 ed          Z
dS )Location.Metarx   r!   )rx   r    r!   r"   r#   )rx   r!   r&   Tr'   zCA location with this name already exists within the specified site.r)   )rx   r    r-   r.   )rx   r-   r0   zCA location with this slug already exists within the specified site.r   r   N)r3   r4   r5   r   r   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r   *  s        F##F#1:   $F#'3!4000()*o(p(p	   $F#1:   $F#'3!4000()*o(p(p	  
, q}}annr=   r?   c                 0    t          d| j        g          S )Nzdcim:locationrA   rC   rE   s    r>   rG   zLocation.get_absolute_urlE  s    dgY7777r=   c                 J    t           j                            | j                  S r   )LocationStatusChoicesr   r   rb   rE   s    r>   r   zLocation.get_status_colorH  s    $+//<<<r=   c                     t                                                       | j        rP| j        j        | j        k    r=t	          t          d                              | j        | j                            d S d S )NzAParent location ({parent}) must belong to the same site ({site}).)r    rx   )supercleanr    rx   r   r8   format)rF   	__class__s    r>   r   zLocation.cleanK  sw     ; 	:4;+ty88!!S# #fDKdif88: : :	: 	:88r=   )r3   r4   r5   rQ   r   r   CASCADErx   r   r8   r   r   rb   r   ry   rm   r   rR   r   prerequisite_modelsr?   rG   r   r   __classcell__)r   s   @r>   r   r      sz         6.   D
 VQx[[%%3	  F V.   F  vQz]]!677	  H "/'"%	  K UL- - - - - - - -68 8 8= = =: : : : : : : : :r=   r   N)"django.contrib.contenttypes.fieldsr   django.core.exceptionsr   	django.dbr   django.urlsr   django.utils.translationr   r8   timezone_fieldr   dcim.choicesdcim.constantsnetbox.modelsr
   r   netbox.models.featuresr   r   utilities.fieldsr   __all__r   r   r   r   r<   r=   r>   <module>r      s   > > > > > > 2 2 2 2 2 2             6 6 6 6 6 6 ( ( ( ( ( (         8 8 8 8 8 8 8 8 G G G G G G G G 1 1 1 1 1 1. . . . .], . . .j. . . . ./ . . .jt9 t9 t9 t9 t9=/ t9 t9 t9vS: S: S: S: S:}35E S: S: S: S: S:r=   