Files
crmApi/apps/cuser/forms.py
T
2026-10-08 16:37:45 +03:30

31 lines
944 B
Python

from django import forms
from django.contrib.auth.forms import UserChangeForm, UserCreationForm
from django.core.exceptions import ValidationError
from apps.cuser.cuser_model import CUser
from utils.validations.mobile import normalize_mobile
class MobileFormMixin:
def clean_mobile(self):
try:
return normalize_mobile(self.cleaned_data['mobile'])
except ValidationError as error:
raise forms.ValidationError(error.messages)
class CUserCreationForm(MobileFormMixin, UserCreationForm):
mobile = forms.CharField(label='شماره موبایل')
class Meta(UserCreationForm.Meta):
model = CUser
fields = ('username', 'name_family', 'mobile', 'is_active', 'is_staff')
class CUserChangeForm(MobileFormMixin, UserChangeForm):
mobile = forms.CharField(label='شماره موبایل')
class Meta(UserChangeForm.Meta):
model = CUser
fields = '__all__'