Example #1
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)
Example #2
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())
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 )
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)
Example #5
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})
Example #6
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))