Beispiel #1
0
    def update(self, instance, validated_data):
        ente = validated_data.pop('ente', None)

        instance.name = validated_data.get('name', instance.name)
        password = validated_data.pop('password1', None)
        confirm_password = validated_data.pop('password2', None)
        is_admin = validated_data.pop('is_admin', False)

        if ente and not is_admin:
            ente_serializer = EnteSerializer(instance.ente, data=ente)
            if ente_serializer.is_valid():
                ente_serializer.save()

        if password and confirm_password and password == confirm_password:
            instance.set_password(password)

        instance.save()
        update_session_auth_hash(self.context.get('request'), instance)

        return instance
Beispiel #2
0
    def update(self, instance, validated_data):
        ente = validated_data.pop('ente', None)

        instance.name = validated_data.get('name', instance.name)
        password = validated_data.pop('password1', None)
        confirm_password = validated_data.pop('password2', None)
        is_admin = validated_data.pop('is_admin', False)

        if ente and not is_admin:
            ente_serializer = EnteSerializer(instance.ente, data=ente)
            if ente_serializer.is_valid():
                ente_serializer.save()

        if password and confirm_password and password == confirm_password:
            instance.set_password(password)

        instance.save()
        update_session_auth_hash(self.context.get('request'), instance)

        return instance
Beispiel #3
0
    def create(self, validated_data):
        ente = validated_data.pop('ente', None)
        password1 = validated_data.pop('password1', None)
        password2 = validated_data.pop('password2', None)

        if ente:
            serializer = EnteSerializer(data=ente)
            if serializer.is_valid():
                if password1 and password2 and password1 == password2:
                    user = User.objects.create(**validated_data)
                    user.set_password(password1)
                    user.save()
                else:
                    raise serializers.ValidationError({
                        "password2":
                        "As senhas não se batem. Digite novamente"
                    })
                serializer.save(user=user)

        return user
Beispiel #4
0
    def create(self, validated_data):
        ente = validated_data.pop('ente', None)
        password1 = validated_data.pop('password1', None)
        password2 = validated_data.pop('password2', None)

        if ente:
            serializer = EnteSerializer(data=ente)
            if serializer.is_valid():
                if password1 and password2 and password1 == password2:
                    user = User.objects.create(**validated_data)
                    user.set_password(password1)
                    user.save()
                else:
                    raise serializers.ValidationError(
                        {
                            "password2":
                            "As senhas não se batem. Digite novamente"
                        }
                    )
                serializer.save(user=user)

        return user