Ejemplo n.º 1
0
def new_comment(request, board_id):
    if request.method == 'GET':
        context = {'board_id': board_id}
        return render(request, 'boards/new_comment.html', context)
    if request.method == 'POST':
        board = get_object_or_404(Board, id=board_id)
        content = request.POST.get('content')
        comment = Comment(board_id=board.id, content=content)
        comment.save()
        return redirect('boards:detail', board.id)
Ejemplo n.º 2
0
    def form_valid(self, form):
        """
        Append default data while creating a comment, not provided in a form.
        """
        obj = self.get_object()
        comment = Comment(author=current_user.id,
                          object_id=obj.id,
                          object_type=obj.object_type,
                          text=form.text.data)
        db.session.add(comment)
        db.session.commit()

        return super(CommentMixin, self).form_valid(form)
Ejemplo n.º 3
0
def comments_create(request, board_pk):
    # 댓글을 달 게시물
    board = Board.objects.get(pk=board_pk)
    if request.method == 'POST':
        # form 에서 넘어온 댓글 정보
        content = request.POST.get('content')
        # 댓글 생성 및 저장
        comment = Comment(board=board, content=content)
        # comment = Comment(board_id=board.pk, content=content)
        comment.save()
        return redirect('boards:detail', board.pk)
        # return redirect('boards:detail', comment.board_id)
    else:
        return redirect('boards:detail', board.pk)
Ejemplo n.º 4
0
    def setUp(self):
        user = User.objects.create_user('test', '*****@*****.**', 'test1234@')
        self.user = user
        profile = Profile(user=user)
        profile.save()

        category = Category(title="카테고리", creator=self.user)
        category.save()
        self.category = category
        self.assertIsInstance(category, Category)

        post = Post(title="포스트",
                    content="내용",
                    category=self.category,
                    creator=self.user)
        post.save()
        self.post = post
        self.assertIsInstance(post, Post)

        comment = Comment(content="댓글", creator=self.user, post=self.post)
        comment.save()
        self.comment = comment
        self.assertIsInstance(comment, Comment)

        reply = Reply(content="대댓글", creator=self.user, comment=self.comment)
        reply.save()
        self.reply = reply
        self.assertIsInstance(reply, Reply)

        user = {"username": "******", "password": "******"}

        response = self.client.post('/api/v1/auth/login/',
                                    json.dumps(user),
                                    content_type='application/json')
        self.assertEqual(response.status_code, 200)

        self.token = response.data['access_token']
        self.csrftoken = response.cookies.get('csrftoken').value

        self.assertNotEqual(self.token, '')

        self.headers = {
            "HTTP_Authorization": "jwt " + self.token,
            "X-CSRFToken": self.csrftoken,
        }
Ejemplo n.º 5
0
 def setUp(self):
     self.client = APIClient()
     self.user = setup_user()
     self.user.save()
     self.board = Board(title='Test Board', created_by=self.user)
     self.board.save()
     self.label = Label(board=self.board,
                        title='Red Label',
                        color='#FF0000')
     self.label.save()
     self.label2 = Label(board=self.board,
                         title='Green Label',
                         color='#00FF00')
     self.label2.save()
     self.card = Card(board=self.board,
                      title='Test Card',
                      description='Test Card description',
                      created_by=self.user)
     self.card.save()
     self.comment = Comment(card=self.card,
                            message='Test message.',
                            created_by=self.user)
     self.comment.save()
Ejemplo n.º 6
0
    def post(self, request, *args, **kwargs):
        """
        post_id 글에 새로운 댓글을 작성한다.
        content 필수
        """
        post_id = kwargs['post_id']
        post = get_object_or_404(Post, pk=post_id)

        content = request.data.get('content', '')

        if content == '':
            return Response({"message": "content required"},
                            status=status.HTTP_400_BAD_REQUEST)

        comment = Comment(
            creator=request.user,
            post=post,
            content=content,
        )

        comment.save()

        return Response({"message": "Comment created success"},
                        status=status.HTTP_201_CREATED)
Ejemplo n.º 7
0
def comment_create(request, board_id):
    content = request.POST.get('content')
    comment = Comment(board_id=board_id, content=content)
    comment.save()
    return redirect('boards:detail', board_id)