service.py 10 KB

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