forms.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. from django.contrib.auth.forms import AuthenticationForm
  2. from .models import SharixUser
  3. from django import forms
  4. from metaservicesynced.models import ServiceType, Service
  5. class LoginUserForm(AuthenticationForm):
  6. password = forms.CharField(label="Пароль",
  7. widget=forms.PasswordInput(attrs={'class':'form-control'}))
  8. username = forms.CharField(label="Номер телефона",
  9. widget=forms.TextInput(attrs={'class':'form-control'}))
  10. class Meta:
  11. model = SharixUser
  12. fields = ['username', 'password']
  13. class ServiceTypeUpdateForm(forms.ModelForm):
  14. def __init__(self, *args, **kwargs):
  15. super(ServiceTypeUpdateForm, self).__init__(*args, **kwargs)
  16. # Добавляет стиль бутстрапа form-control всем полям таблицы если у них нет своих стилей
  17. for field in iter(self.fields):
  18. if 'class' not in self.fields[field].widget.attrs:
  19. self.fields[field].widget.attrs.update({'class':'form-control'})
  20. class Meta:
  21. model = ServiceType
  22. fields = ['status','ticket_status','id_metaservice','codename',
  23. 'description','requirements','price_type','link_agreement',
  24. 'is_global','is_visible']
  25. widgets = {
  26. 'status': forms.TextInput(attrs={'readonly': True}),
  27. 'ticket_status': forms.TextInput(attrs={'readonly': True}),
  28. }
  29. class ServiceTypeCreateForm(forms.ModelForm):
  30. def __init__(self, *args, **kwargs):
  31. super(ServiceTypeCreateForm, self).__init__(*args, **kwargs)
  32. # Добавляет стиль бутстрапа form-control всем полям таблицы если у них нет своих стилей
  33. for field in iter(self.fields):
  34. if 'class' not in self.fields[field].widget.attrs:
  35. self.fields[field].widget.attrs.update({'class':'form-control'})
  36. class Meta:
  37. model = ServiceType
  38. fields = '__all__'
  39. widgets = {
  40. 'ticket_status': forms.Select(attrs={'class': 'form-select'}),
  41. }
  42. class ServiceInformationUpdateForm(forms.ModelForm):
  43. def __init__(self, *args, **kwargs):
  44. super(ServiceInformationUpdateForm, self).__init__(*args, **kwargs)
  45. # Добавляет стиль бутстрапа form-control всем полям таблицы если у них нет своих стилей
  46. for field in iter(self.fields):
  47. if 'class' not in self.fields[field].widget.attrs:
  48. self.fields[field].widget.attrs.update({'class':'form-control'})
  49. class Meta:
  50. model = Service
  51. fields = ['servicetype_id', 'id_provider']
  52. widgets = {
  53. # 'status': forms.TextInput(attrs={'readonly': True}),
  54. # 'ticket_status': forms.TextInput(attrs={'readonly': True}),
  55. 'servicetype_id': forms.Select(attrs={'class': 'form-select'}),
  56. #'repr_id': forms.Select(attrs={'class': 'form-select'}),
  57. # 'resource_id': forms.Select(attrs={'class': 'form-select'}),
  58. }
  59. class ServiceInformationCreateForm(forms.ModelForm):
  60. def __init__(self, *args, **kwargs):
  61. super(ServiceInformationCreateForm, self).__init__(*args, **kwargs)
  62. # Добавляет стиль бутстрапа form-control всем полям таблицы если у них нет своих стилей
  63. for field in iter(self.fields):
  64. if 'class' not in self.fields[field].widget.attrs:
  65. self.fields[field].widget.attrs.update({'class':'form-control'})
  66. class Meta:
  67. model = Service
  68. fields = ["servicetype_id", "id_provider"]
  69. exclude = ["resource_id"]
  70. widgets = {
  71. #'servicetype_id': forms.CharField(max_length=255)
  72. # 'legal_name': forms.TextInput(label = 'Название')
  73. # 'servicetype_id': forms.Select(attrs={'class': 'form-select'}),
  74. #'repr_id': forms.Select(attrs={'class': 'form-select'}),
  75. # 'resource_id': forms.Select(attrs={'class': 'form-select'}),
  76. # 'ticket_status': forms.Select(attrs={'class': 'form-select'}),
  77. }