feat: finalize UI/UX
This commit is contained in:
+24
-18
@@ -1,33 +1,39 @@
|
||||
from pathlib import Path
|
||||
from uuid import uuid4
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.validators import FileExtensionValidator
|
||||
from django.db import models
|
||||
|
||||
|
||||
class ClientProfile(models.Model):
|
||||
TIMEZONE_CHOICES = [
|
||||
("UTC", "UTC"),
|
||||
("America/New_York", "America/New York"),
|
||||
("America/Chicago", "America/Chicago"),
|
||||
("America/Denver", "America/Denver"),
|
||||
("America/Los_Angeles", "America/Los Angeles"),
|
||||
("Europe/London", "Europe/London"),
|
||||
("Europe/Berlin", "Europe/Berlin"),
|
||||
("Asia/Dubai", "Asia/Dubai"),
|
||||
("Asia/Tehran", "Asia/Tehran"),
|
||||
("Asia/Tokyo", "Asia/Tokyo"),
|
||||
("Australia/Sydney", "Australia/Sydney"),
|
||||
]
|
||||
def profile_avatar_upload_to(instance, filename):
|
||||
suffix = Path(filename).suffix.lower()
|
||||
return f"accounts/avatars/{instance.user_id}/{uuid4().hex}{suffix}"
|
||||
|
||||
|
||||
def validate_avatar_size(image):
|
||||
if image.size > 5 * 1024 * 1024:
|
||||
raise ValidationError("Profile pictures must be 5 MB or smaller.")
|
||||
|
||||
|
||||
class ClientProfile(models.Model):
|
||||
user = models.OneToOneField(
|
||||
settings.AUTH_USER_MODEL,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="client_profile",
|
||||
)
|
||||
company = models.CharField(max_length=200, blank=True)
|
||||
job_title = models.CharField(max_length=150, blank=True)
|
||||
phone = models.CharField(max_length=50, blank=True)
|
||||
timezone = models.CharField(
|
||||
max_length=64,
|
||||
choices=TIMEZONE_CHOICES,
|
||||
default="UTC",
|
||||
bio = models.TextField(max_length=600, blank=True)
|
||||
avatar = models.ImageField(
|
||||
upload_to=profile_avatar_upload_to,
|
||||
blank=True,
|
||||
validators=[
|
||||
FileExtensionValidator(["jpg", "jpeg", "png", "webp"]),
|
||||
validate_avatar_size,
|
||||
],
|
||||
)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
Reference in New Issue
Block a user