def homePage(request): tblogSettings = blogSettings.objects.get(id=1) queryset = articles.objects.filter(type='article',status='Published').order_by('-publishTime') tstickys = queryset.filter(sticky=True) queryset = queryset.filter(sticky=False) page_result = Paginator(queryset, tblogSettings.articlesPerPage) 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 context = { 'prev_page': prev_page, 'next_page': next_page, 'object_result': object_result, 'page':page, 'ishome':True, 'tstickys':tstickys } vt = loader.get_template('themes/'+getBlogTheme()+'/home.html') return HttpResponse(vt.render(RequestContext(request, context)))
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) )
def articleUnderTag(request,tslug): try: ttag = tags.objects.get(name=tslug) queryset=articles.objects.filter(tags=ttag,type='article').order_by('-publishTime') search_fields = ['title'] return get_datatables_records( request, queryset, search_fields, 'themes/'+getBlogTheme()+'/tag.html', extra_context={ 'tag':ttag } ) except tags.DoesNotExist: return render_to_response( 'themes/'+getBlogTheme()+'/tag.html', {'message':_('Tag does not exist.')}, context_instance=RequestContext(request) )
def articleUnderCategory(request,tslug): try: tcategory = categories.objects.get(slug=tslug) queryset=articles.objects.filter(categories=tcategory,type='article').order_by('-publishTime') search_fields = ['title'] return get_datatables_records( request, queryset, search_fields, 'themes/'+getBlogTheme()+'/category.html', extra_context={ 'category':tcategory } ) except categories.DoesNotExist: return render_to_response( 'themes/'+getBlogTheme()+'/category.html', {'message':_('Category does not exist.')}, context_instance=RequestContext(request) )
def articleUnderArchive(request,year,month): queryset=articles.objects.filter(publishTime__year=year,publishTime__month=month,type='article').order_by('-publishTime') search_fields = ['title'] return get_datatables_records( request, queryset, search_fields, 'themes/'+getBlogTheme()+'/archive.html', extra_context={ 'year':year, 'month':month } )
def error404(request): vt = loader.get_template("themes/" + getBlogTheme() + "/404.html") c = RequestContext(request, {"page_title": _("404 Error")}) return HttpResponse(vt.render(c))