oasupport/clientapp/forms.py
2025-12-03 11:16:47 +03:00

43 lines
1.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from .models import Call, CustomUser, AddMessage
from django.forms import ModelForm, forms
from django import forms
class CallForm(ModelForm):
class Meta:
model = Call
fields = ['title', 'category', 'message', 'file']
class AddMessageForm(ModelForm):
class Meta:
model = AddMessage
fields = ['message', 'file']
class LoginForm(ModelForm):
username = forms.CharField(max_length=40)
password = forms.CharField(max_length=40, widget=forms.PasswordInput)
def __init__(self, *args, **kwagrs):
super().__init__(*args, **kwagrs)
self.fields['username'].label = 'Логин'
self.fields['password'].label = 'Пароль'
def clean(self, *args, **kwagrs):
username = self.cleaned_data['username']
password = self.cleaned_data['password']
if not CustomUser.objects.filter(username=username).exists():
raise forms.ValidationError(f'Пользователь с логином {username} не найден в системе.')
user = CustomUser.objects.filter(username=username).first()
if user:
if not user.check_password(password):
raise forms.ValidationError('Неверный пароль')
class Meta:
model = CustomUser
fields = ['username', 'password']
widgets = {
'password': forms.PasswordInput()
}