forms.py 5.6 KB

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