def create(self, request, *args, **kwargs):  # pylint: disable=unused-argument
        """Create the reply"""
        issue_id = self.request.parser_context["kwargs"]["pk"]
        try:
            issue = models.InstallerIssue.objects.get(pk=issue_id)
        except models.InstallerIssue.DoesNotExist:
            raise Http404

        reply_payload = dict(request.data)
        # Complete the information with the current user
        reply_payload["submitted_by"] = request.user.id
        reply_payload["submitted_on"] = timezone.now()
        reply_payload["issue"] = issue_id

        serializer = serializers.InstallerIssueReplySerializer(
            data=reply_payload)
        serializer.is_valid(raise_exception=True)
        self.perform_create(serializer)

        notify_issue_reply(issue, request.user, request.data['description'])

        headers = self.get_success_headers(serializer.data)
        return Response(serializer.data,
                        status=status.HTTP_201_CREATED,
                        headers=headers)
Exemple #2
0
    def create(self, request, *args, **kwargs):  # pylint: disable=unused-argument
        """Create the reply"""
        issue_id = self.request.parser_context["kwargs"]["pk"]
        try:
            issue = models.InstallerIssue.objects.get(pk=issue_id)
        except models.InstallerIssue.DoesNotExist:
            raise Http404

        reply_payload = dict(request.data)
        # Complete the information with the current user
        reply_payload["submitted_by"] = request.user.id
        reply_payload["submitted_on"] = timezone.now()
        reply_payload["issue"] = issue_id

        serializer = serializers.InstallerIssueReplySerializer(data=reply_payload)
        serializer.is_valid(raise_exception=True)
        self.perform_create(serializer)

        notify_issue_reply(issue, request.user, request.data['description'])

        headers = self.get_success_headers(serializer.data)
        return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)