mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
refactor: Traduction en anglais des modules "GestionInscription" et
"GestionLogin"
This commit is contained in:
51
Back-End/Auth/serializers.py
Normal file
51
Back-End/Auth/serializers.py
Normal file
@ -0,0 +1,51 @@
|
||||
from rest_framework import serializers
|
||||
from Auth.models import Profile
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
class ProfileSerializer(serializers.ModelSerializer):
|
||||
id = serializers.IntegerField(required=False)
|
||||
password = serializers.CharField(write_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Profile
|
||||
fields = ['id', 'password', 'email', 'code', 'datePeremption', 'estConnecte', 'droit', 'username', 'is_active']
|
||||
extra_kwargs = {'password': {'write_only': True}}
|
||||
|
||||
def create(self, validated_data):
|
||||
user = Profile(
|
||||
username=validated_data['username'],
|
||||
email=validated_data['email'],
|
||||
is_active=validated_data['is_active'],
|
||||
droit=validated_data['droit']
|
||||
)
|
||||
user.set_password(validated_data['password'])
|
||||
user.save()
|
||||
return user
|
||||
|
||||
def to_representation(self, instance):
|
||||
ret = super().to_representation(instance)
|
||||
ret['password'] = '********'
|
||||
return ret
|
||||
|
||||
class ProfilUpdateSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Profile
|
||||
fields = ['id', 'password', 'email', 'code', 'datePeremption', 'estConnecte', 'droit', 'username', 'is_active']
|
||||
extra_kwargs = {
|
||||
'password': {'write_only': True, 'required': False}
|
||||
}
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
password = validated_data.pop('password', None)
|
||||
instance = super().update(instance, validated_data)
|
||||
|
||||
if password:
|
||||
instance.set_password(password)
|
||||
instance.save()
|
||||
|
||||
return instance
|
||||
|
||||
def to_representation(self, instance):
|
||||
ret = super().to_representation(instance)
|
||||
ret['password'] = '********'
|
||||
return ret
|
||||
Reference in New Issue
Block a user