Ejemplo n.º 1
0
def articleView(request,tslug):
    try:
        tarticle = articles.objects.get(slug=tslug)
        tblogSettings = blogSettings.objects.get(id=1)
        tcomments = tarticle.article_comments.all()
        if tblogSettings.commentsOrder == 'descending':
            tcomments = tcomments.order_by('-submitTime')
        page_result = Paginator(tcomments, tblogSettings.commentsPerPage)
        page_range = page_result.page_range
        try:
            page = int(request.GET.get('page', '1'))
            if page not in page_range:
                page = 1
        except ValueError:
            page = 1
        t_page = page_result.page(page)
        object_result = t_page.object_list
        if t_page.has_previous():
            prev_page = page - 1
        else:
            prev_page = 0
        if t_page.has_next():
            next_page = page + 1
        else:
            next_page = 0
        if request.method == 'POST':
            number1 = int(request.POST['number1'])
            number2 = int(request.POST['number2'])
            arithmeticResult = number1 + number2
            form = commentsForm(arithmeticResult,request.POST)
            if form.is_valid():
                form.save(tarticle,'add')
                return HttpResponseRedirect('/%s.html' %tslug)
        else:
            number1 = random.randint(1, 10)
            number2 = random.randint(1, 10)
            arithmeticResult = number1 + number2
            form = commentsForm(arithmeticResult)
        vt = loader.get_template('themes/'+getBlogTheme()+'/article.html')
        c = RequestContext(
            request,
            {
                'article':tarticle,
                'tslug':tslug,
                'tcomments':object_result,
                'prev_page': prev_page,
                'page':page,
                'next_page': next_page,
                'form':form,
                'number1':number1,
                'number2':number2
            }
        )
        return HttpResponse(vt.render(c))
    except articles.DoesNotExist:
        return render_to_response(
            'themes/default/error.html',
                {'message':_('Article does not exist.')},
            context_instance=RequestContext(request)
        )
Ejemplo n.º 2
0
def editComment(request, tid, template_name):
    try:
        tcomments = comments.objects.get(id=tid)
        if request.method == "POST":
            form = commentsForm(request.POST, instance=tcomments)
            if form.is_valid():
                form.save(tcomments.article, "edit")
                return HttpResponseRedirect(reverse("getcommentlist"))
        else:
            form = commentsForm(instance=tcomments)
        vt = loader.get_template(template_name)
        c = RequestContext(
            request, {"form": form, "form_url": reverse("editcomment", args=[tid]), "page_title": _("Edit Comment")}
        )
        return HttpResponse(vt.render(c))
    except comments.DoesNotExist:
        return render_to_response(
            "error.html", {"message": _("Comment does not exist.")}, context_instance=RequestContext(request)
        )