forms.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from django.contrib.auth.forms import AuthenticationForm
  2. from .models import SharixUser
  3. from django import forms
  4. from metaservicesynced.models import ServiceType
  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. }