forms.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. 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 ServiceTariffUpdateForm(forms.ModelForm):
  14. def __init__(self, *args, **kwargs):
  15. super(ServiceTariffUpdateForm, 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 = Service
  22. fields = ['status','ticket_status','servicetype_id','id_provider',
  23. 'resource_id','requirements','price_alg','price_km','price_min','price_amount','service_status',
  24. 'is_global','is_visible']
  25. widgets = {
  26. 'status': forms.TextInput(attrs={'readonly': True}, ),
  27. 'ticket_status': forms.TextInput(attrs={'readonly': True}),
  28. 'servicetype_id': forms.Select(attrs={'class': 'form-select'}),
  29. 'id_provider': forms.Select(attrs={'class': 'form-select'}),
  30. 'resource_id': forms.Select(attrs={'class': 'form-select'}),
  31. }
  32. class ServiceTariffCreateForm(forms.ModelForm):
  33. def __init__(self, *args, **kwargs):
  34. super(ServiceTariffCreateForm, self).__init__(*args, **kwargs)
  35. # Добавляет стиль бутстрапа form-control всем полям таблицы если у них нет своих стилей
  36. for field in iter(self.fields):
  37. if 'class' not in self.fields[field].widget.attrs:
  38. self.fields[field].widget.attrs.update({'class':'form-control'})
  39. class Meta:
  40. model = Service
  41. fields = '__all__'
  42. widgets = {
  43. 'servicetype_id': forms.Select(attrs={'class': 'form-select'}),
  44. 'id_provider': forms.Select(attrs={'class': 'form-select'}),
  45. 'resource_id': forms.Select(attrs={'class': 'form-select'}),
  46. 'ticket_status': forms.Select(attrs={'class': 'form-select'}),
  47. }