forms.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from django import forms
  2. from .models import Amministratore
  3. class FormAmministratoreEditId(forms.Form):
  4. def __init__(self,*args,amministratore=[],**kwargs):
  5. super().__init__(*args, **kwargs)
  6. self.fields['scelta'] = forms.ChoiceField(required=True,choices=self.c(amministratore))
  7. def c(self,amministratore):
  8. choices = []
  9. for u in amministratore:
  10. choices.append((u.id,u.id),)
  11. print('choices',choices)
  12. return choices
  13. class FormAmministratore(forms.Form):
  14. def __init__(self,*args,azienda=[],**kwargs):
  15. forms.Form.__init__(self,*args,**kwargs)
  16. self.fields['login'] = forms.CharField(required=True)
  17. self.fields['nome'] = forms.CharField(required=True)
  18. self.fields['mail'] = forms.CharField(required=False)
  19. self.fields['pin'] = forms.CharField(required=True)
  20. self.fields['uuid'] = forms.CharField(required=False)
  21. self.fields['azienda'] = forms.ChoiceField(required=True,choices=self.c(azienda))
  22. def c(self,azienda):
  23. choices = []
  24. for a in azienda:
  25. choices.append((a.id,a.id))
  26. print('choices',choices)
  27. return choices
  28. class FormCancellaPermessi(forms.Form):
  29. def __init__(self,*args,**kwargs):
  30. forms.Form.__init__(self,*args,**kwargs)
  31. self.fields['ConfermaCancellazionePermesso'] = forms.IntegerField(required=True)
  32. class FormCancellaPermessiXAmministratore(forms.Form):
  33. def __init__(self,*args,**kwargs):
  34. forms.Form.__init__(self,*args,**kwargs)
  35. self.fields['ConfermaCancellazionePermessoXAmministratore'] = forms.IntegerField(required=True)
  36. class FormAziendaMancante(forms.Form):
  37. choices = list()
  38. def __init__(self,*args,**kwargs):
  39. forms.Form.__init__(self,*args,**kwargs)
  40. self.fields['aziendadaaggiungere'] = forms.ChoiceField(required=True,choices=self.choices)
  41. def c(self,azienda):
  42. print("aziende passate a fam",len(azienda))
  43. for a in azienda:
  44. print(a.id,a.nome)
  45. self.choices.append((a.id,a.id),)
  46. print('choices',self.choices,len(self.choices))