first
This commit is contained in:
commit
fa9d154db9
260 files changed
+17643
No files matched your search
@@ -0,0 +1,31 @@
|
||||
from django import forms
|
||||
|
||||
from .models import StaffProfile
|
||||
|
||||
|
||||
class StaffProfileAdminForm(forms.ModelForm):
|
||||
"""Upload/replace avatars without exposing a direct public media URL."""
|
||||
role = forms.ChoiceField(
|
||||
choices=StaffProfile.Role.choices,
|
||||
required=False,
|
||||
initial=StaffProfile.Role.SALES_EXPERT,
|
||||
label="نقش سازمانی",
|
||||
)
|
||||
avatar = forms.ImageField(
|
||||
required=False,
|
||||
widget=forms.FileInput(attrs={"accept": "image/jpeg,image/png,image/webp"}),
|
||||
help_text="تصویر JPG، PNG یا WebP انتخاب کنید. تصویر جدید جایگزین تصویر فعلی میشود.",
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = StaffProfile
|
||||
fields = "__all__"
|
||||
|
||||
def clean_avatar(self):
|
||||
avatar = self.cleaned_data.get("avatar")
|
||||
if avatar and avatar.size > 5 * 1024 * 1024:
|
||||
raise forms.ValidationError("حجم تصویر پروفایل نباید بیشتر از ۵ مگابایت باشد.")
|
||||
return avatar
|
||||
|
||||
def clean_role(self):
|
||||
return self.cleaned_data.get("role") or StaffProfile.Role.SALES_EXPERT
|
||||
Reference in new issue
Block a user