1
0

models.py 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. from email.policy import default
  2. from django.db import models
  3. from django.utils import timezone
  4. from django.template.defaultfilters import slugify
  5. from gest_clin.models import Clinique as Clinique
  6. from gest_clin.models import Services as Clin_Services
  7. # SITE = [
  8. # ('GEN', 'Gentilly'),
  9. # ('CAP', 'Ambroise Paré'),
  10. # ('HPN', 'HPNL'),
  11. # ('EXT', 'Extéreieur'),
  12. # ]
  13. TYPE = [
  14. ('PC', 'PC'),
  15. ('PORTABLE', 'Portable'),
  16. ('CL', 'Client Léger'),
  17. ('PANEL-PC', 'Panel-PC'),
  18. ('IMP', 'Imprimante'),
  19. ]
  20. STATUT = [
  21. ('RAS', '-'),
  22. ('PREPROD','En préparation'),
  23. ('HS','A réparer'),
  24. ('ADEPROD','A retirer'),
  25. ('EN STOCK', 'En stock'),
  26. ('INAPTE', 'Inapte / HS'),
  27. ]
  28. SWOS = [
  29. ('CISCO', 'Cisco'),
  30. ('ARUBA', 'Aruba'),
  31. ('HP', 'HP'),
  32. ]
  33. SWTYPE = [
  34. ('F', 'Fast'),
  35. ('G', 'Giga'),
  36. ]
  37. class Accessory_Link(models.Model):
  38. Accessory_Nom = models.CharField("Nom de l\'accesoire", max_length=64, unique=True)
  39. Accessory_N_slugify = models.CharField("Nom de l\'accesoir slugifié", max_length=64, blank = True, editable = False)
  40. Accessory_icone = models.CharField("Code de l'icone", max_length = 64, blank = True)
  41. Accessory_on_list = models.BooleanField("Afficher sur le listing", default=False)
  42. def save(self, *args, **kwargs) :
  43. self.Accessory_N_slugify = slugify(self.Accessory_Nom)
  44. super(Accessory_Link, self).save(*args, **kwargs)
  45. def __str__(self):
  46. return str(self.Accessory_Nom)
  47. class Meta:
  48. verbose_name = "Accessoires lié un poste Informatique"
  49. verbose_name_plural = "Accessoires lié un poste Informatique"
  50. # Create your models here.
  51. class PIC(models.Model):
  52. PIC_NUnic = models.PositiveSmallIntegerField("Numéro uniq", unique=True, blank=True, null=True)
  53. PIC_L_Statut = models.CharField("Statut", max_length=16, choices=STATUT, default='RAS')
  54. PIC_Site = models.ForeignKey(Clinique, verbose_name="Clinique", on_delete=models.PROTECT, null=True)
  55. PIC_L_Chassi_Type = models.CharField("Type", max_length=8, choices=TYPE, default='PC')
  56. PIC_Deg = models.BooleanField("Poste avec procédure dégradé", default=False)
  57. PIC_is_for_Cadre = models.BooleanField("Poste utiliser pas des RUS ou Cadre", default=False)
  58. PIC_with_Snow = models.BooleanField("Sync avec Snow", default=False)
  59. PIC_with_Office = models.BooleanField("Office installé sur le poste", default=False)
  60. PIC_Nom_netbios = models.CharField("Nom NETBIOS", max_length=64, blank=True, null=True)
  61. PIC_Utilisateur = models.CharField("Utilisateur", max_length=64, blank=True, null=True)
  62. PIC_Utilisateur_Fq = models.CharField("Utilisateur Frequent", max_length=64, blank=True, null=True)
  63. PIC_Service = models.ForeignKey(Clin_Services, verbose_name="Service", on_delete=models.PROTECT, blank=True, null=True)
  64. PIC_Local = models.CharField("Localisation", max_length=64, blank=True, null=True)
  65. PIC_Adresse_IP = models.CharField("Adresse IP", max_length=32, default="DHCP" )
  66. PIC_Adresse_Mac = models.CharField("Adresse MAC", max_length=18, blank=True, null=True)
  67. PIC_OS = models.CharField("OS", max_length=64, blank=True, null=True)
  68. PIC_Marque = models.CharField("Marque", max_length=64, blank=True, null=True)
  69. PIC_Type = models.CharField("Modèle", max_length=64, blank=True, null=True)
  70. PIC_SN = models.CharField("SN", max_length=64, blank=True, null=True)
  71. PIC_Date_Achat = models.CharField("Date d'achat", max_length=64, blank=True, null=True)
  72. PIC_Fin_de_Garantie = models.CharField("Date de fin de garentie", max_length=64, blank=True, null=True)
  73. PIC_CPU = models.CharField("CPU", max_length=64, blank=True, null=True)
  74. PIC_RAM = models.PositiveSmallIntegerField("RAM", blank=True, null=True)
  75. PIC_Commentaires = models.TextField("Commentaires", blank=True, null=True)
  76. PIC_Precisions = models.TextField("Precisions", blank=True, null=True)
  77. PIC_Accessory = models.ManyToManyField(Accessory_Link, blank=True)
  78. def __str__(self):
  79. return self.PIC_Nom_netbios
  80. def save(self, *args, **kwargs):
  81. if self.PIC_Nom_netbios != None :
  82. if "GEN-" in self.PIC_Nom_netbios or "CAP-" in self.PIC_Nom_netbios or "HPN-" in self.PIC_Nom_netbios:
  83. tmp_PIC_NUnic = self.PIC_Nom_netbios[-4:]
  84. try:
  85. self.PIC_NUnic = int(tmp_PIC_NUnic)
  86. except:
  87. pass
  88. self.PIC_Nom_netbios = self.PIC_Nom_netbios.upper()
  89. if self.PIC_Adresse_IP != None :
  90. self.PIC_Adresse_IP = self.PIC_Adresse_IP.replace(',','.').replace(';','.')
  91. if self.PIC_Adresse_IP != None :
  92. self.PIC_Adresse_IP = self.PIC_Adresse_IP.replace(',','.').replace(';','.')
  93. super(PIC, self).save(*args, **kwargs)
  94. class Meta:
  95. verbose_name = "Poste client"
  96. verbose_name_plural = "Postes clients"
  97. class PIC_History(models.Model):
  98. H_PIC = models.ForeignKey("PIC", on_delete=models.CASCADE)
  99. H_Date = models.DateTimeField("Date", auto_now_add=True)
  100. H_Commentaire = models.TextField("Historique")
  101. def __str__(self):
  102. return str(self.H_PIC)
  103. class Meta:
  104. verbose_name = "Historique un poste Informatique"
  105. verbose_name_plural = "Historique lié un poste Informatique"
  106. class PIS(models.Model):
  107. PIC_NUnic = models.PositiveSmallIntegerField("Numéro uniq", unique=True, blank=True, null=True)
  108. PIS_Site = models.ForeignKey(Clinique, verbose_name="Clinique", on_delete=models.PROTECT, null=True)
  109. PIS_Nom_netbios = models.CharField("Nom NETBIOS", max_length=64, blank=True, null=True)
  110. PIS_Friendly_Name = models.CharField("Friendly Name", max_length=64, blank=True, null=True)
  111. PIS_OS = models.CharField("OS", max_length=64, blank=True, null=True)
  112. PIS_with_Snow = models.BooleanField("Sync avec Snow", default=False)
  113. PIS_with_Web = models.BooleanField("Portail web", default=False)
  114. PIS_Adresse_IP = models.CharField("Adresse IP", max_length=64, blank=True, null=True)
  115. PIS_Adresse_Mac = models.CharField("Adresse MAC", max_length=64, blank=True, null=True)
  116. PIS_Role = models.CharField("Application", max_length=64, blank=True, null=True)
  117. PIS_Type = models.CharField("Type", max_length=64, blank=True, null=True)
  118. PIS_SN = models.CharField("SN", max_length=64, blank=True, null=True)
  119. PIS_CPU = models.CharField("CPU", max_length=64, blank=True, null=True)
  120. PIS_RAM = models.PositiveSmallIntegerField("RAM", blank=True, null=True)
  121. PIS_Localisation = models.CharField("Localisation", max_length=64, blank=True, null=True)
  122. PIS_Fonctionnalite = models.TextField("Fonctionnalité", blank=True, null=True)
  123. PIS_Commentaires = models.TextField("Commentaires", blank=True, null=True)
  124. PIS_Archive = models.BooleanField("Serveur plus en Production", default=False)
  125. def __str__(self):
  126. return self.PIS_Nom_netbios
  127. def save(self, *args, **kwargs):
  128. self.PIS_Nom_netbios = self.PIS_Nom_netbios.upper()
  129. if self.PIS_Type != None :
  130. self.PIS_Type = self.PIS_Type.upper()
  131. if self.PIS_Role != None :
  132. self.PIS_Role = self.PIS_Role.upper()
  133. if self.PIS_Adresse_IP != None :
  134. self.PIS_Adresse_IP = self.PIS_Adresse_IP.replace(',','.').replace(';','.')
  135. if self.PIS_Commentaires != None :
  136. self.PIS_Commentaires = self.PIS_Commentaires.replace(',','.').replace(';','.')
  137. super(PIS, self).save(*args, **kwargs)
  138. class Meta:
  139. verbose_name = "Serveur"
  140. verbose_name_plural = "Serveurs"
  141. class Swich(models.Model):
  142. SW_Baie = models.ForeignKey("Baie", on_delete=models.CASCADE)
  143. SW_Nom = models.CharField("Nom", max_length=64)
  144. SW_IP = models.CharField("Adresse IP", max_length=64, blank=True, null=True)
  145. SW_OS = models.CharField("OS", max_length=5, choices=SWOS, default='HP')
  146. SW_TYPE = models.CharField("Type", max_length=1, choices=SWTYPE, default='G')
  147. SW_Commentaires = models.TextField("Commentaires", blank=True, null=True)
  148. SW_Update_Port = models.TextField("Last Auto update port of switch", blank=True, null=True)
  149. SW_Archive = models.BooleanField("Switch plus en production", default=False)
  150. class Meta:
  151. verbose_name = "Switch"
  152. verbose_name_plural = "Switchs"
  153. def __str__(self):
  154. return self.SW_Nom
  155. class Port_Link(models.Model):
  156. PL_Swich = models.ForeignKey("Swich", on_delete=models.CASCADE)
  157. PL_Port_NG = models.CharField("Port sur le Switch", max_length=10)
  158. PL_VLAN = models.PositiveSmallIntegerField("VLAN sur le Port")
  159. PL_Headbang_plug = models.CharField("Prise sur le bandeau", max_length=8, blank=True)
  160. PL_Commentaires = models.TextField("Commentaires", blank=True, null=True)
  161. def __str__(self):
  162. return str(self.PL_Swich)+' - '+str(self.PL_Port)
  163. class Meta:
  164. verbose_name = "Lien des prises vers les Switchs"
  165. verbose_name_plural = "Lien des prises vers les Switchs"
  166. class Services(models.Model):
  167. SERVICE_Anag = models.CharField("Anagrame du Service", max_length=2, unique=True)
  168. SERVICE_Nom = models.CharField("Nom du Service", max_length=64, unique=True)
  169. def __str__(self):
  170. return self.SERVICE_Nom
  171. class Meta:
  172. verbose_name = "Service"
  173. verbose_name_plural = "Services"
  174. class Baie(models.Model):
  175. BAIE_Site_NG = models.ForeignKey(Clinique, verbose_name="Clinique", on_delete=models.PROTECT, null=True)
  176. BAIE_Nom = models.CharField("Nom de la Baie", max_length=32, unique=True)
  177. BAIE_Local = models.CharField("Localisation", max_length=64, blank=True, null=True)
  178. BAIE_Commentaire = models.TextField("Commentaires", blank=True, null=True)
  179. def __str__(self):
  180. return self.BAIE_Nom
  181. class Meta:
  182. verbose_name = "Baie"
  183. verbose_name_plural = "Baies"