Ejemplo n.º 1
0
    def _create_new_social_profile(self, social_id, backend, user=None):
        if user is None:
            user = self.user_class(username=self.email)
            with revalidate_integrityerror(self.user_class,
                                           user.validate_unique):
                user.save()

        social_profile = UserSocialProfile(
            backend=backend,
            social_id=social_id,
            user=user,
        )
        with revalidate_integrityerror(UserSocialProfile,
                                       user.validate_unique):
            social_profile.save()

        return social_profile
Ejemplo n.º 2
0
    def _create_new_social_profile(self, social_id, backend, admin=None):
        if admin is None:
            admin = self.user_class(email=self.email, is_active=True)
            with revalidate_integrityerror(self.user_class,
                                           admin.validate_unique):
                admin.save()

        social_profile = AdminSocialProfile(
            backend=backend,
            social_id=social_id,
            admin=admin,
        )
        with revalidate_integrityerror(AdminSocialProfile,
                                       social_profile.validate_unique):
            social_profile.save()

        return social_profile
Ejemplo n.º 3
0
    def rename(self, request, *args, **kwargs):
        obj = self.get_object()
        serializer_class = self.__class__.serializer_class
        serializer = serializer_class(obj, context=self.get_serializer_context())

        field = serializer.fields['name']
        new_name = request.data.get('new_name')

        self._validate_new_name(field, new_name)
        obj.name = new_name

        with revalidate_integrityerror(self.model, partial(self._validate_new_name, field, new_name)):
            obj.save()

        # Set kwargs so we end up with correct new links
        self.kwargs['name'] = new_name
        return Response(serializer.data, status=status.HTTP_200_OK)
Ejemplo n.º 4
0
 def update(self, instance, validated_data):
     with revalidate_integrityerror(
             self.Meta.model,
             partial(self.run_validation, self.initial_data, False)):
         return super().update(instance, validated_data)
Ejemplo n.º 5
0
 def create(self, validated_data):
     with revalidate_integrityerror(
             self.Meta.model,
             partial(self.run_validation, self.initial_data, False)):
         return super().create(validated_data)