Example #1
0
    def share(self, request, *args, **kwargs):
        self.object = self.get_object()
        data = dict(request.data.items() + [('project', self.object.pk)])
        serializer = ShareProjectSerializer(data=data)

        if serializer.is_valid():
            if data.get("remove"):
                serializer.remove_user()
            else:
                serializer.save()
                email_msg = data.get('email_msg')

                if email_msg:
                    # send out email message.
                    # serializer.object doesn't exist anymore in DRF, so
                    # we have to pull the user from the DB
                    username = serializer.validated_data['username']
                    user = User.objects.get(username=username)
                    send_mail(SHARE_PROJECT_SUBJECT.format(self.object.name),
                              email_msg,
                              DEFAULT_FROM_EMAIL,
                              (user.email, ))

        else:
            return Response(data=serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)

        return Response(status=status.HTTP_204_NO_CONTENT)
Example #2
0
    def share(self, request, *args, **kwargs):
        self.object = self.get_object()
        data = dict(request.DATA.items() + [('project', self.object.pk)])
        serializer = ShareProjectSerializer(data=data)

        if serializer.is_valid():
            if data.get("remove"):
                serializer.remove_user()
            else:
                serializer.save()
                email_msg = data.get('email_msg')

                if email_msg:
                    # send out email message.
                    user = serializer.object.user
                    send_mail(SHARE_PROJECT_SUBJECT.format(self.object.name),
                              email_msg,
                              DEFAULT_FROM_EMAIL,
                              (user.email, ))

        else:
            return Response(data=serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)

        return Response(status=status.HTTP_204_NO_CONTENT)
Example #3
0
    def share(self, request, *args, **kwargs):
        self.object = self.get_object()
        data = dict(request.data.items() + [('project', self.object.pk)])
        serializer = ShareProjectSerializer(data=data)

        if serializer.is_valid():
            if data.get("remove"):
                serializer.remove_user()
            else:
                serializer.save()
                email_msg = data.get('email_msg')

                if email_msg:
                    # send out email message.
                    # serializer.object doesn't exist anymore in DRF, so
                    # we have to pull the user from the DB
                    username = serializer.validated_data['username']
                    user = User.objects.get(username=username)
                    send_mail(SHARE_PROJECT_SUBJECT.format(self.object.name),
                              email_msg, DEFAULT_FROM_EMAIL, (user.email, ))

        else:
            return Response(data=serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)

        return Response(status=status.HTTP_204_NO_CONTENT)
Example #4
0
    def share(self, request, *args, **kwargs):
        self.object = self.get_object()
        data = dict(request.DATA.items() + [('project', self.object.pk)])
        serializer = ShareProjectSerializer(data=data)

        if serializer.is_valid():
            if data.get("remove"):
                serializer.remove_user()
            else:
                serializer.save()
        else:
            return Response(data=serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)

        return Response(status=status.HTTP_204_NO_CONTENT)
Example #5
0
    def share(self, request, *args, **kwargs):
        self.object = self.get_object()
        data = dict(request.DATA.items() + [('project', self.object.pk)])
        serializer = ShareProjectSerializer(data=data)

        if serializer.is_valid():
            if data.get("remove"):
                serializer.remove_user()
            else:
                serializer.save()
                email_msg = data.get('email_msg')

                if email_msg:
                    # send out email message.
                    user = serializer.object.user
                    send_mail(SHARE_PROJECT_SUBJECT.format(self.object.name),
                              email_msg, DEFAULT_FROM_EMAIL, (user.email, ))

        else:
            return Response(data=serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)

        return Response(status=status.HTTP_204_NO_CONTENT)