models.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. from django import forms
  2. from django.db import models
  3. from django.utils import timezone
  4. from gest_clin.models import Clinique as Clinique
  5. from gest_clin.models import Services as Clin_Services
  6. login_type = (
  7. (u'pnom', u'1er lettre du Prenom puis Nom'),
  8. (u'pnomMGAG', u'1er lettre du Prenom puis Nom en Mag'),
  9. (u'pre.nom', u'Prenom.Nom'),
  10. (u'preMAG.nomMAG', u'PRENOM.NOM'),
  11. (u'mixed', u'Au choix'),
  12. (u'pre.nom', u'Lié a AD'),
  13. (u'pre.nom@el', u'Lié au compte email'),
  14. (u'autre', u'Autre'),
  15. )
  16. def generate_password(length=9, chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"):
  17. import random
  18. password = ""
  19. for _ in range(length):
  20. password += random.choice(chars)
  21. return password
  22. class GES_APP(models.Model):
  23. GESAP_Nom = models.CharField("Nom", max_length=16)
  24. GESAP_ltype = models.CharField("Type de Login",choices=login_type, max_length=48, default='pre.nom')
  25. GESAP_Sup_Nom = models.CharField("Champ complaimentaire", max_length=16, blank=True)
  26. #GESAP_Commentaire = models.TextField("Aide pour la création du compte", blank=True)
  27. GESAP_Procedure = models.CharField("Lien vers la Procédure de création de compte", max_length=248, blank=True)
  28. GESAP_Actif = models.BooleanField("Active ?", default = True)
  29. def __str__(self):
  30. return self.GESAP_Nom
  31. class Meta:
  32. verbose_name = "Les apllications métiers"
  33. verbose_name_plural = "Les apllications métiers"
  34. ordering = ['GESAP_Nom']
  35. class GES_Fonction(models.Model):
  36. GESFC_Nom = models.CharField("Nom", max_length=16)
  37. def __str__(self):
  38. return self.GESFC_Nom
  39. class Meta:
  40. verbose_name = "Les fonctions"
  41. verbose_name_plural = "Les fonctions"
  42. ordering = ['GESFC_Nom']
  43. class GES_User(models.Model):
  44. GES_Site = models.ForeignKey(Clinique, verbose_name="Clinique", on_delete=models.PROTECT, null=True)
  45. GES_Nom = models.CharField("Nom", max_length=16)
  46. GES_Prenom = models.CharField("Prénom", max_length=16)
  47. GES_Motdepasse = models.CharField("Mot de passe", max_length=16, blank=True)
  48. GES_Service = models.ForeignKey(Clin_Services, verbose_name="Service", on_delete=models.PROTECT, blank=True, null=True)
  49. GES_Fonction = models.ForeignKey(GES_Fonction, verbose_name="Fonction", on_delete=models.PROTECT, blank=True, null=True)
  50. GES_APPs = models.ManyToManyField(GES_APP, verbose_name="Applications", limit_choices_to={'GESAP_Actif': True},)
  51. GES_Date = models.DateField("Date d'arrivée", blank=True, null=True)
  52. GES_OK = models.BooleanField("Création complété", default = False)
  53. ordering = ['GES_Service']
  54. def save(self, *args, **kwargs) :
  55. if self.GES_Motdepasse == "" :
  56. self.GES_Motdepasse = generate_password()
  57. super(GES_User, self).save(*args, **kwargs)
  58. def __str__(self):
  59. return self.GES_Nom + ' ' + self.GES_Prenom
  60. class Meta:
  61. verbose_name = "Les utilisateurs"
  62. verbose_name_plural = "Les utilisateurs"
  63. class GES_APPLink(models.Model):
  64. GES_APPLink_User = models.ForeignKey(GES_User, on_delete=models.CASCADE)
  65. GES_APPLink_APP = models.ForeignKey(GES_APP, on_delete=models.CASCADE, verbose_name="Application", limit_choices_to={'GESAP_Actif': True},)
  66. GES_APPLink_Login = models.CharField("Login", max_length=48)
  67. GES_APPLink_MDP = models.CharField("Mot de passe", max_length=16)
  68. GES_APPLink_Sup = models.CharField("Info supplémentaire", max_length=16, blank=True)
  69. GES_APPLink_Create = models.BooleanField("Crée", default = False)
  70. class GES_APPMat(models.Model):
  71. GES_Fonction = models.ForeignKey(GES_Fonction, verbose_name="Fonction", on_delete=models.PROTECT, blank=True, null=True)
  72. GES_Service = models.ManyToManyField(Clin_Services, verbose_name="Services")
  73. GES_APPs = models.ManyToManyField(GES_APP, verbose_name="Applications", limit_choices_to={'GESAP_Actif': True},)
  74. def __str__(self):
  75. return self.GES_Fonction.GESFC_Nom
  76. def Select_GES_Service(self):
  77. return "\n".join([p.SERVICE_Nom +', ' for p in self.GES_Service.all()])
  78. def Select_GES_APPs(self):
  79. return "\n".join([p.GESAP_Nom +', ' for p in self.GES_APPs.all()])
  80. class Meta:
  81. verbose_name = "Matrice Services - Fonctions - Applications"
  82. verbose_name_plural = "Matrice Services - Fonctions - Applications"
  83. class GES_User_form(forms.ModelForm):
  84. class Meta:
  85. model = GES_User
  86. fields = '__all__'
  87. exclude = ['GES_APPs','GES_OK',]
  88. class GES_APPLink_form(forms.ModelForm):
  89. class Meta:
  90. model = GES_APPLink
  91. fields = ['GES_APPLink_Login', 'GES_APPLink_MDP', 'GES_APPLink_Sup']
  92. class GES_APPLink_add_form(forms.ModelForm):
  93. class Meta:
  94. model = GES_APPLink
  95. fields = ['GES_APPLink_APP',]
  96. class PSearch_form(forms.Form):
  97. PSearch = forms.CharField(label='Recherche', max_length=128)