Skip to content

Commit

Permalink
Merge branch 'user-api' of github.com:InsaLan/backend-insalan.fr into…
Browse files Browse the repository at this point in the history
… user-api
  • Loading branch information
ShiroUsagi-san committed Oct 14, 2023
2 parents 47b01ff + 13c16a5 commit 88357a8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
9 changes: 8 additions & 1 deletion insalan/user/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@
from django.contrib.auth.admin import UserAdmin
from .models import User

admin.site.register(User, UserAdmin)
class CustomUserAdmin(UserAdmin):
fieldsets = UserAdmin.fieldsets + (
("Image", {
'fields': ('image',),
}),
)

admin.site.register(User, CustomUserAdmin)
# Register your models here.
13 changes: 12 additions & 1 deletion insalan/user/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from django.utils import timezone
from django.utils.http import urlencode
from django.utils.translation import gettext_lazy as _

from django.core.validators import FileExtensionValidator

class UserManager(BaseUserManager):
"""
Expand All @@ -39,6 +39,7 @@ def create_user(
user = self.model(
email=self.normalize_email(email),
username=username,
image=None,
date_joined=timezone.make_aware(datetime.now()),
**extra_fields
)
Expand Down Expand Up @@ -80,6 +81,16 @@ def __init__(self, *args, **kwargs):
USERNAME_FIELD = "username"
EMAIL_FIELD = "email"

image = models.FileField(
verbose_name=_("photo de profil"),
blank=True,
null=True,
upload_to="profile-pictures",
validators=[
FileExtensionValidator(allowed_extensions=["png", "jpg", "jpeg", "svg"])
],
)

email = models.EmailField(
verbose_name=_("Courriel"), max_length=255, unique=True, blank=False
)
Expand Down
9 changes: 9 additions & 0 deletions insalan/user/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from django.utils.translation import gettext_lazy as _
from rest_framework import serializers
from rest_framework.validators import UniqueValidator
from django.core.validators import FileExtensionValidator


from .models import User, UserMailer

Expand Down Expand Up @@ -35,6 +37,12 @@ class UserRegisterSerializer(serializers.ModelSerializer):
first_name = serializers.CharField(max_length=50, required=False)
last_name = serializers.CharField(max_length=50, required=False)
password_validation = serializers.CharField(write_only=True, required=True)
image = serializers.FileField(
required=False,
validators=[
FileExtensionValidator(allowed_extensions=["png", "jpg", "jpeg", "svg"])
],
)

class Meta:
"""Meta class, used to set parameters"""
Expand All @@ -48,6 +56,7 @@ class Meta:
"is_staff",
"is_superuser",
"email",
"image",
"email_active",
"password",
"password_validation",
Expand Down

0 comments on commit 88357a8

Please sign in to comment.