Пример #1
0
    def share(self, request, *args, **kwargs):
        self.object = self.get_object()
        data = merge_dicts(request.data.dict(), {'project': self.object.pk})

        remove = data.get("remove")
        if remove and remove is not isinstance(remove, bool):
            remove = strtobool(remove)

        if remove:
            serializer = RemoveUserFromProjectSerializer(data=data)
        else:
            serializer = ShareProjectSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            email_msg = data.get('email_msg')
            if email_msg:
                # send out email message.
                try:
                    user = serializer.instance.user
                except AttributeError:
                    for instance in serializer.instance:
                        user = instance.user
                        send_mail(
                            SHARE_PROJECT_SUBJECT.format(self.object.name),
                            email_msg, DEFAULT_FROM_EMAIL, (user.email, ))
                else:
                    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)
Пример #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.
                    # 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)
Пример #3
0
    def share(self, request, *args, **kwargs):
        self.object = self.get_object()
        data = dict(request.DATA.items() + [('project', self.object.pk)])
        if data.get("remove"):
            serializer = RemoveUserFromProjectSerializer(data=data)
        else:
            serializer = ShareProjectSerializer(data=data)

        if serializer.is_valid():
            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)
Пример #4
0
    def share(self, request, *args, **kwargs):
        self.object = self.get_object()
        data = merge_dicts(request.data.dict(), {'project': self.object.pk})

        remove = data.get("remove")
        if remove and remove is not isinstance(remove, bool):
            remove = strtobool(remove)

        if remove:
            serializer = RemoveUserFromProjectSerializer(data=data)
        else:
            serializer = ShareProjectSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            email_msg = data.get('email_msg')
            if email_msg:
                # send out email message.
                user = serializer.instance.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)
Пример #5
0
    def share(self, request, *args, **kwargs):
        self.object = self.get_object()
        data = dict(request.data.items() + [('project', self.object.pk)])
        if data.get("remove"):
            serializer = RemoveUserFromProjectSerializer(data=data)
        else:
            serializer = ShareProjectSerializer(data=data)

        if serializer.is_valid():
            serializer.save()

            email_msg = data.get('email_msg')

            if email_msg:
                # send out email message.
                user = serializer.instance.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)
Пример #6
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)