Пример #1
0
def comment_book(book_id):
    """ Создание комментариев к книгам"""
    # если пользователь не авторизован, кидаем его на страницу входа
    if 'username' not in session:
        return redirect('login')
    form = AddCommentForm()
    book = BooksModel(db.get_connection()).get(book_id)
    if not book:
        return render_template('error.html', loged=True, title='Ошибка')
    if form.validate_on_submit():
        # создать комментарий
        comment = Comment(book_id=book_id,
                          username=session['username'],
                          name=form.name.data,
                          text=form.text.data,
                          date=form.date.data,
                          book_name=book[1])
        db_comments.session.add(comment)
        db_comments.session.commit()
        # редирект на страницу книги
        return redirect('/book/' + str(book_id))
    return render_template("add_comment.html",
                           title='Добавить рецензию',
                           form=form,
                           loged=True)
Пример #2
0
def post(title):
    post = Post.query.filter(Post.title == title).first()
    form = AddCommentForm()
    if form.validate_on_submit():
        comment = Comment(author_name=form.author_name.data, email=form.email.data,
                          content=form.content.data, post=post, pub_date=datetime.datetime.now())
        db.session.add(comment)
        db.session.commit()
        return redirect(url_for("main.post", title=title))
    return render_template('post.html', post=post, form=form, title=title)
Пример #3
0
def add_comment(post_id):
    comment_form = AddCommentForm()
    if comment_form.validate_on_submit():
        post = BlogPost.query.get(post_id)
        new_comment = Comment(body=comment_form.body.data,
                              author=current_user,
                              post=post)
        db.session.add(new_comment)
        db.session.commit()
        return redirect(url_for("show_post", post_id=post.id))

    return render_template("add-comment.html", form=comment_form)
Пример #4
0
def add_comment():
    form = AddCommentForm()
    if form.validate_on_submit():
        comment_body = form.comment_body.data
        post_id = form.post_id.data

        new_comment = Comments(comment_body, post_id)

        db.session.add(new_comment)
        db.session.commit()

        return redirect(url_for('posts'))

    return render_template('add_comment.html', form=form)
Пример #5
0
def front_comment(request):
    form = AddCommentForm(request.POST)
    if form.is_valid():
        article_id = form.cleaned_data.get('article_id')
        content = form.cleaned_data.get('content')
        article = ArticleModel.objects.filter(pk=article_id).first()
        if not article:
            return phjson.json_params_error(u'没有该文章')
        comment = CommentModel(article=article,
                               content=content,
                               author=request.front_user)
        comment.save()
        return redirect(
            reverse('front_article_detail', kwargs={'article_id': article_id}))
    else:
        return phjson.json_params_error(form.get_error())
Пример #6
0
def recipe(id):
    recipe = Recipe.query.get_or_404(id)
    enableComments = False
    commForm = AddCommentForm()

    if 'email' in session:
        enableComments = True
        if request.method == 'POST':
            if commForm.validate():
                newComment = Comment(commForm.commentdesc.data,
                                     session['email'])
                recipe.comments.append(newComment)
                db.session.commit()
    return render_template("recipe.html",
                           recipe=recipe,
                           enableComments=enableComments,
                           form=commForm)
Пример #7
0
def new_comment(request, storyID, projectID):
    if request.method == 'POST':
        form = AddCommentForm(request.POST)
        if form.is_valid():
            project = project_api.get_project(projectID)
            story = story.get_story(storyID)
            story_comment = models.story_comment.create_story_comment(request.user, story, request.POST)
            story_comment = form.save(commit=False)
            return redirect('/project/' + projectID)
    else:
        form = AddCommentForm()
        
    context = {'title' : 'New Story Comment',
               'form' : form, 
               'action' : '/newcomment/' + storyID , 
               'desc' : 'Create Story Comment' }
    return render(request, 'CommentForm.html', context )
Пример #8
0
def front_add_comment(request):
    if request.method == 'GET':
        article_id = request.GET.get('article_id')
        context = {
            'articles': ArticleModel.objects.filter('article_id').first()
        }
        return render(request, 'front_add_article.html', context=context)
    else:
        form = AddCommentForm(request.POST)
        if form.is_valid():
            article_id = form.cleaned_data.get('article_id')
            comment = form.cleaned_data.get('comment')
            comment_model = CommentModel(comment=comment)
            article_model = ArticleModel.objects.filter('article_id').first()
            comment_model.article = article_model
            comment_model.author = request.user.username
            comment_model.save()
            return myjson.json_result()
        else:
            return render(request, 'front_add_article.html',
                          {'errors': form.error})
Пример #9
0
def sale_detail(request,pk):
	user = User.objects.get(email = request.user.email)
	profile_name = UserProfile.objects.get(user = user)
	sale = UserSales.objects.get(id=pk)
	profile = UserProfile.objects.all()
	comment = Comments.objects.all()

	if request.POST.get("comment"):
		f = AddCommentForm(request.POST)
		if f.is_valid():
			c = f.save(commit = False)
			c.pub_date = timezone.now()
			c.user = user
			c.sale = sale
			c.save()

			return HttpResponseRedirect('/sale_detail/%s' % pk) 

	else:
		f = AddCommentForm()

	user1 = User.objects.get(email = request.user.email)
	user2 = UserSales.objects.get(id = pk)

	if request.POST.get("connect"):
		connectform = ConnectForm(request.POST)
		if connectform.is_valid():
			c = connectform.save(commit = False)
			c.send = user1
			c.receive = user2.user
			c.save()
			url = reverse('sale_detail', kwargs={ 'pk': user2.id })
			return HttpResponseRedirect(url)
			
	else:
		connectform = ConnectForm()


	args = {'sale':sale,'comment':comment,'profile':profile,'profiles': profile_name,'form':f,'connectform':connectform}
	return render_to_response('sales/sale_detail.html',args,context_instance=RequestContext(request))
Пример #10
0
def comments(request):
    """Страница с общими коментариями"""
    add_form = AddCommentForm()
    if request.method == "POST":
        add_form = AddCommentForm(request.POST)
        if add_form.is_valid():
            # сохраняем коментарий в базе
            add_comment = add_form.save(commit=False)
            add_comment.user_name = request.user.username
            add_comment.email = request.user.email
            add_comment.save()

    # извлекаем все коментарии
    all_comments = Comment.objects.all()
    prepare_comments = list()
    if all_comments.count():
        for comment in all_comments:
            prepare_comments.append({"user_name": comment.user_name, "message": comment.message})

    # делаем пагинацию коментариев по 3 на странице
    current_page_number = 1
    if request.GET.get("page"):
        current_page_number = int(request.GET.get("page"))
    comments_on_page = Paginator(prepare_comments, 3)
    current_page_comments = comments_on_page.page(current_page_number)

    context = {"form": add_form, "comments": current_page_comments,
               "next_page": current_page_comments.next_page_number() if current_page_comments.has_next() else current_page_number,
               "previous_page": current_page_comments.previous_page_number() if current_page_comments.has_previous() else current_page_number}

    return render(request, template_name='blog/comments.html', context=context)
Пример #11
0
def new_comment(request, storyID, projectID):
    if request.method == 'POST':
        form = AddCommentForm(request.POST)
        if form.is_valid():
            project = project_api.get_project(projectID)
            story = story.get_story(storyID)
            story_comment = models.story_comment.create_story_comment(
                request.user, story, request.POST)
            story_comment = form.save(commit=False)
            return redirect('/project/' + projectID)
    else:
        form = AddCommentForm()

    context = {
        'title': 'New Story Comment',
        'form': form,
        'action': '/newcomment/' + storyID,
        'desc': 'Create Story Comment'
    }
    return render(request, 'CommentForm.html', context)