Exemplo n.º 1
0
class TaskDetailsSerializer(ModelSerializer):
    comments = CommentDetailsSerializer(many=True, read_only=True)
    performer_id = UserDetailsSerializer(read_only=True)

    class Meta:
        model = Task
        fields = '__all__'
Exemplo n.º 2
0
def update_comment(comment_id):
    comment = Comment.query.get_or_404(comment_id)
    if comment is None:
        return get_error_response(messages='not found', status_code=404)
    content = request.json.get('content')
    if content:
        comment.content = content

    db.session.commit()
    return get_success_response(data=CommentDetailsSerializer(comment).data,
                                messages='Comment updated successfully')
Exemplo n.º 3
0
 def test_should_get_all_task_comments(self):
     response = self.client.get(
         reverse('boards:comments-list',
                 kwargs={
                     'board_id': self.board.id,
                     'list_id': self.list_obj.id,
                     'task_id': self.task_obj.id
                 }))
     comments = Comment.objects.filter(task_id=self.task_obj.id)
     serializer = CommentDetailsSerializer(comments, many=True)
     self.assertEqual(response.data, serializer.data)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
Exemplo n.º 4
0
def create_comment(article_slug):
    content = request.json.get('content')
    claims = get_jwt_claims()
    user_id = claims.get('id')
    article_id = db.session.query(
        Article.id).filter_by(slug=article_slug).first()[0]
    comment = Comment(content=content, user_id=user_id, article_id=article_id)

    db.session.add(comment)
    db.session.commit()

    return get_success_response(data=CommentDetailsSerializer(comment).data,
                                messages='Comment created successfully')
Exemplo n.º 5
0
def create_comment(product_slug):
    content = request.json.get('content')

    # claims = get_jwt_claims()
    # user_id = claims.get('user_id')
    # user_id = get_jwt_identity()
    # user = current_user

    claims = get_jwt_claims()
    user_id = claims.get('user_id')
    product_id = db.session.query(
        Product.id).filter_by(slug=product_slug).first()[0]
    comment = Comment(content=content, user_id=user_id, product_id=product_id)

    db.session.add(comment)
    db.session.commit()

    return get_success_response(data=CommentDetailsSerializer(comment).data,
                                messages='Comment created successfully')
Exemplo n.º 6
0
def update_comment(comment_id):
    # comment = Comment.query.get_or_404(comment_id)
    comment = Comment.query.get(comment_id)
    if comment is None:
        return get_error_response(messages='not found', status_code=404)

    if current_user.is_admin() or comment.user_id == current_user.id:
        content = request.json.get('content')
        rating = request.json.get('rating')

        if content:
            comment.content = content
        if rating:
            comment.rating = rating

        db.session.commit()
        return get_success_response(
            data=CommentDetailsSerializer(comment).data,
            messages='Comment updated successfully')
    else:
        return get_error_response(
            'Permission denied, you can not update this comment',
            status_code=401)
Exemplo n.º 7
0
def show_comment(comment_id):
    comment = Comment.query.get(comment_id)
    return jsonify(CommentDetailsSerializer(comment).data), 200
Exemplo n.º 8
0
 def get_comments(obj):
     return CommentDetailsSerializer(obj.comments.all(), many=True).data