コード例 #1
0
def post(post_id):
    post = Post.query.get_or_404(post_id)
    users = User.query.all()
    form = CommentForm()
    if form.validate_on_submit():
        comment = Comment(body=form.body.data, post=post, author=current_user)
        db.session.add(comment)
        db.session.commit()
        flash('Your comment has been published.')
        return redirect(url_for('post', post_id=post.id))
    return render_template('post.html',
                           title=post.title,
                           post=post,
                           form=form,
                           users=users)
コード例 #2
0
def goods_page(request, goods_id):
    if request.user.is_authenticated:
        user = request.user
        user_profile = UserProfile.objects.get(user=user)
        is_marked = MarkedTable.objects.filter(user=user_profile)
    else:
        user_profile = []
        is_marked = False
    comment_form = CommentForm()
    goods = Goods.objects.get(pk=goods_id)
    # record goods' seen times
    goods.seen_times += 1
    goods.save()
    if is_marked:
        is_marked = is_marked.filter(goods=goods)

    comment_list = Comment.objects.filter(goods=goods)
    context_dic = {
        'goods': goods,
        'comments': comment_list,
        'form': comment_form,
        'user_profile': user_profile,
        'is_marked': is_marked
    }
    return render(request, 'market/goods.html', context_dic)
コード例 #3
0
ファイル: views.py プロジェクト: zhanhailiu/flea_market_sysu
def goods_page(request, goods_id):
    if request.user.is_authenticated:
        user = request.user
        user_profile = UserProfile.objects.get(user=user)
    else:
        user_profile = []
    comment_form = CommentForm()
    goods = Goods.objects.get(pk=goods_id)
    comment_list = Comment.objects.filter(goods=goods)
    context_dic = {'goods':goods,'comments':comment_list,'form':comment_form,'user_profile':user_profile}
    return render(request, 'market/goods.html',context_dic)
コード例 #4
0
ファイル: comment_views.py プロジェクト: luchiel/market
def add_comment(request, product_id):
    product = Product.objects.get(id=product_id)
    form = CommentForm(
        data=(request.POST or None),
        instance=Comment(
            product=product,
            user = request.user if request.user else None,
        ),
    )
    if form.is_valid():
        form.save()
        form.instance.make_path_and_depth(request.POST['response_to_id'])
        form.save()
    else:
        return HttpResponse(
            json.dumps({
                'result': 'error',
                'comment_error': form.errors.get('comment'),
            }), mimetype='application/json'
        )
    page = get_template('single_comment.html')
    context = RequestContext(request, { 'comment': form.instance, 'product': product })
    return HttpResponse(
        json.dumps({
            'result': 'ok',
            'comment': page.render(context),
        }), mimetype='application/json'
    )
コード例 #5
0
def add_comment(request, goods_id):
    if request.method == 'POST':
        comment_form = CommentForm(request.POST)
        if comment_form.is_valid():
            comment = comment_form.save(commit=True)
            goods = Goods.objects.get(pk=goods_id)
            user = request.user
            user_profile = UserProfile.objects.get(user=user)
            # add in comments and in_station_message
            comment.user = user_profile
            comment.goods = goods
            comment.save()
            message = InstationMessage()
            message.sender = user_profile
            message.receiver = goods.seller
            message.content = comment.content
            message.item = goods
            message.save()
            return goods_page(request, goods_id)
        else:
            print(comment_form.errors)
            pass
    else:
        comment_form = CommentForm()
    return render(request, 'market/add_comment.html')