Exemplo n.º 1
0
 def retrieve(self, request, pk):
     """Get a single comment."""
     comment = self.get_comment(pk)
     serialized = CommentSerializer(comment, context={
         'request': request
     }).data
     return Response(serialized)
Exemplo n.º 2
0
 def create(cls, request, pk):
     get_complaint = get_object_or_404(Complaints.objects.all(), id=pk)
     get_text = request.data['text']
     comment = Comment.objects.create(text=get_text,
                                      commented_by=request.user.profile,
                                      complaint=get_complaint)
     serialized = CommentSerializer(comment)
     return Response(serialized.data, status=201)
Exemplo n.º 3
0
    def to_representation(self, value):
        if isinstance(value, Event):
            serializer = EventSerializer(value)
        elif isinstance(value, NewsEntry):
            serializer = NewsEntrySerializer(value)
        elif isinstance(value, ComplaintComment):
            serializer = CommentSerializer(value)

        return serializer.data
Exemplo n.º 4
0
    def create(cls, request, pk):
        get_complaint = get_object_or_404(Complaint.objects.all(), id=pk)
        get_text = request.data['text']
        comment = ComplaintComment.objects.create(
            text=get_text,
            commented_by=request.user.profile,
            complaint=get_complaint)
        # Auto subscribes the commenter to the complaint
        if settings.COMPLAINT_AUTO_SUBSCRIBE:
            get_complaint.subscriptions.add(request.user.profile)
            get_complaint.save()

        serialized = CommentSerializer(comment)
        return Response(serialized.data, status=201)