forms.py 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. from django.contrib.auth.forms import AuthenticationForm
  2. from metaservicesynced.models import *
  3. from .models import SharixUser
  4. from django import forms
  5. from metaservicesynced.models import ServiceType, Service
  6. from .models import SharixUser
  7. from django import forms
  8. class LoginUserForm(AuthenticationForm):
  9. password = forms.CharField(label="Пароль",
  10. widget=forms.PasswordInput(attrs={'class':'form-control'}))
  11. username = forms.CharField(label="Номер телефона",
  12. widget=forms.TextInput(attrs={'class':'form-control'}))
  13. class Meta:
  14. model = SharixUser
  15. fields = ['username', 'password']
  16. class ServiceTariffUpdateForm(forms.ModelForm):
  17. def __init__(self, *args, **kwargs):
  18. super(ServiceTariffUpdateForm, self).__init__(*args, **kwargs)
  19. # Добавляет стиль бутстрапа form-control всем полям таблицы если у них нет своих стилей
  20. for field in iter(self.fields):
  21. if 'class' not in self.fields[field].widget.attrs:
  22. self.fields[field].widget.attrs.update({'class':'form-control'})
  23. class Meta:
  24. model = Service
  25. fields = ['status','ticket_status','servicetype_id','id_provider',
  26. 'resource_id','requirements','price_alg','price_km','price_min','price_amount','service_status',
  27. 'is_global','is_visible']
  28. widgets = {
  29. 'status': forms.TextInput(attrs={'readonly': True}, ),
  30. 'ticket_status': forms.TextInput(attrs={'readonly': True}),
  31. 'servicetype_id': forms.Select(attrs={'class': 'form-select'}),
  32. 'id_provider': forms.Select(attrs={'class': 'form-select'}),
  33. 'resource_id': forms.Select(attrs={'class': 'form-select'}),
  34. }
  35. class ServiceTariffCreateForm(forms.ModelForm):
  36. def __init__(self, *args, **kwargs):
  37. super(ServiceTariffCreateForm, self).__init__(*args, **kwargs)
  38. # Добавляет стиль бутстрапа form-control всем полям таблицы если у них нет своих стилей
  39. for field in iter(self.fields):
  40. if 'class' not in self.fields[field].widget.attrs:
  41. self.fields[field].widget.attrs.update({'class':'form-control'})
  42. class Meta:
  43. model = Service
  44. fields = '__all__'
  45. widgets = {
  46. 'servicetype_id': forms.Select(attrs={'class': 'form-select'}),
  47. 'id_provider': forms.Select(attrs={'class': 'form-select'}),
  48. 'resource_id': forms.Select(attrs={'class': 'form-select'}),
  49. 'ticket_status': forms.TextInput(attrs={'readonly': True}),
  50. }
  51. class ServiceTypeUpdateForm(forms.ModelForm):
  52. def __init__(self, *args, **kwargs):
  53. super(ServiceTypeUpdateForm, self).__init__(*args, **kwargs)
  54. class Meta:
  55. model = ServiceType
  56. fields = ['status','ticket_status','id_metaservice','codename',
  57. 'description','requirements','price_type','link_agreement',
  58. 'is_global','is_visible']
  59. widgets = {
  60. 'status': forms.TextInput(attrs={'readonly': True}),
  61. 'ticket_status': forms.TextInput(attrs={'readonly': True}),
  62. }
  63. PRICE_CHOICES = [
  64. ('one', 'text #1'),
  65. ('two', 'text #2'),
  66. ('three', 'text #3'),
  67. ]
  68. class ServiceTypeCreateForm(forms.ModelForm):
  69. codename = forms.CharField(label="Название услуги")
  70. requirements = forms.CharField(label="Требования")
  71. price_type = forms.ChoiceField(choices=PRICE_CHOICES, label="Ценообразование")
  72. description = forms.CharField(label="Описание")
  73. is_global = forms.BooleanField(label="Доступно во всех сервисах")
  74. is_visible = forms.BooleanField(label="Доступно для планирования цепочек во всех сервисах")
  75. def __init__(self, *args, **kwargs):
  76. super(ServiceTypeCreateForm, self).__init__(*args, **kwargs)
  77. class Meta:
  78. model = ServiceType
  79. fields = ['codename','requirements', 'price_type',
  80. 'description',
  81. 'is_global','is_visible','id_metaservice']
  82. widgets = {
  83. }
  84. class ServiceInformationUpdateForm(forms.ModelForm):
  85. def __init__(self, *args, **kwargs):
  86. super(ServiceInformationUpdateForm, self).__init__(*args, **kwargs)
  87. # Добавляет стиль бутстрапа form-control всем полям таблицы если у них нет своих стилей
  88. for field in iter(self.fields):
  89. if 'class' not in self.fields[field].widget.attrs:
  90. self.fields[field].widget.attrs.update({'class':'form-control'})
  91. class Meta:
  92. model = Service
  93. fields = ['servicetype_id', 'id_provider']
  94. widgets = {
  95. # 'status': forms.TextInput(attrs={'readonly': True}),
  96. # 'ticket_status': forms.TextInput(attrs={'readonly': True}),
  97. 'servicetype_id': forms.Select(attrs={'class': 'form-select'}),
  98. #'repr_id': forms.Select(attrs={'class': 'form-select'}),
  99. # 'resource_id': forms.Select(attrs={'class': 'form-select'}),
  100. }
  101. class ServiceInformationCreateForm(forms.ModelForm):
  102. def __init__(self, *args, **kwargs):
  103. super(ServiceInformationCreateForm, self).__init__(*args, **kwargs)
  104. # Добавляет стиль бутстрапа form-control всем полям таблицы если у них нет своих стилей
  105. for field in iter(self.fields):
  106. if 'class' not in self.fields[field].widget.attrs:
  107. self.fields[field].widget.attrs.update({'class':'form-control'})
  108. class Meta:
  109. model = Service
  110. fields = "__all__"
  111. exclude = ["id",
  112. "is_global",
  113. "is_visible",
  114. "ticket_status",
  115. "id_metaservice",
  116. "resource_id"]
  117. widgets = {
  118. #'servicetype_id': forms.CharField(max_length=255)
  119. # 'legal_name': forms.TextInput(label = 'Название')
  120. # 'servicetype_id': forms.Select(attrs={'class': 'form-select'}),
  121. #'repr_id': forms.Select(attrs={'class': 'form-select'}),
  122. # 'resource_id': forms.Select(attrs={'class': 'form-select'}),
  123. # 'ticket_status': forms.Select(attrs={'class': 'form-select'}),
  124. }
  125. class PartnerInformationUpdateForm(forms.ModelForm):
  126. def __init__(self, *args, **kwargs):
  127. super(PartnerInformationUpdateForm, self).__init__(*args, **kwargs)
  128. # Добавляет стиль бутстрапа form-control всем полям таблицы если у них нет своих стилей
  129. for field in iter(self.fields):
  130. if 'class' not in self.fields[field].widget.attrs:
  131. self.fields[field].widget.attrs.update({'class':'form-control'})
  132. class Meta:
  133. model = Company
  134. fields = "__all__"
  135. exclude = ["id", "ticket_status",
  136. "is_global",
  137. "is_visible",
  138. "id_metaservice",
  139. "status"
  140. ]
  141. widgets = {
  142. 'description': forms.Select(attrs={'class': 'form-select'}),
  143. 'repr_id': forms.Select(attrs={'class': 'form-select'}),
  144. }
  145. class PartnerInformationCreateForm(forms.ModelForm):
  146. def __init__(self, *args, **kwargs):
  147. super(PartnerInformationCreateForm, self).__init__(*args, **kwargs)
  148. for field in iter(self.fields):
  149. if 'class' not in self.fields[field].widget.attrs:
  150. self.fields[field].widget.attrs.update({'class':'form-control'})
  151. # legal_name = forms.Fi()
  152. class Meta:
  153. model = Company
  154. fields = "__all__"
  155. exclude = ["id", "ticket_status",
  156. "is_global",
  157. "is_visible",
  158. "id_metaservice",
  159. "status"
  160. ]
  161. widgets = {
  162. 'description': forms.Select(attrs={'class': 'form-select'}),
  163. 'repr_id': forms.Select(attrs={'class': 'form-select'}),
  164. }
  165. # username = forms.CharField(label="Номер телефона",
  166. # widget=forms.TextInput(attrs={'class':'form-control'}))