|
|
|
@@ -55,6 +55,29 @@ def have_I_right(request, blog_id=None, post_id=None, must_be_superuser=False):
|
|
|
|
|
|
|
|
|
|
return (b, p)
|
|
|
|
|
|
|
|
|
|
def createNavigationBar(blog_id, cur_page, nb_pages):
|
|
|
|
|
navigation_bar = ''
|
|
|
|
|
if cur_page == 0:
|
|
|
|
|
navigation_bar += '<< <'
|
|
|
|
|
else:
|
|
|
|
|
navigation_bar += '<a href="/blog/%d?page=0"><<</a> ' % blog_id
|
|
|
|
|
navigation_bar += '<a href="/blog/%d?page=%d"><</a> ' % (blog_id, cur_page-1)
|
|
|
|
|
|
|
|
|
|
for i in range(nb_pages+1):
|
|
|
|
|
if i == cur_page:
|
|
|
|
|
navigation_bar += ' %d' % (i+1)
|
|
|
|
|
else:
|
|
|
|
|
navigation_bar += ' <a href="/blog/%d?page=%d">%d</a>' % (blog_id, i, i+1)
|
|
|
|
|
|
|
|
|
|
if cur_page == nb_pages:
|
|
|
|
|
navigation_bar += ' > >>'
|
|
|
|
|
else:
|
|
|
|
|
navigation_bar += ' <a href="/blog/%d?page=%d">></a>' % (blog_id, nb_pages)
|
|
|
|
|
navigation_bar += ' <a href="/blog/%d?page=%d">>></a>' % (blog_id, nb_pages)
|
|
|
|
|
|
|
|
|
|
return navigation_bar
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def index(request):
|
|
|
|
|
if request.user.is_authenticated():
|
|
|
|
|
return HttpResponseRedirect('/blog')
|
|
|
|
@@ -150,17 +173,17 @@ def edit_user(request, user_id):
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
def category(request, blog_id):
|
|
|
|
|
b = have_I_right(request, blog_id)
|
|
|
|
|
b,_ = have_I_right(request, blog_id)
|
|
|
|
|
|
|
|
|
|
categories = Category.objects.filter(blog_id=blog_id)
|
|
|
|
|
|
|
|
|
|
c = {'categories' : categories}
|
|
|
|
|
c = {'categories' : categories, 'blog' : b}
|
|
|
|
|
|
|
|
|
|
return render(request, 'templates/category.html', c)
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
def add_category(request, blog_id):
|
|
|
|
|
b = have_I_right(request, blog_id)[0]
|
|
|
|
|
b,_ = have_I_right(request, blog_id)
|
|
|
|
|
|
|
|
|
|
if request.method == 'POST': # If the form has been submitted...
|
|
|
|
|
if 'add' in request.POST:
|
|
|
|
@@ -187,7 +210,7 @@ def edit_category(request, category_id):
|
|
|
|
|
if category is None:
|
|
|
|
|
raise Http404
|
|
|
|
|
|
|
|
|
|
b = have_I_right(request, category.blog.id)[0]
|
|
|
|
|
b,_ = have_I_right(request, category.blog.id)
|
|
|
|
|
|
|
|
|
|
if request.method == 'POST': # If the form has been submitted...
|
|
|
|
|
if 'cancel' in request.POST:
|
|
|
|
@@ -215,7 +238,7 @@ def delete_category(request, category_id):
|
|
|
|
|
if category is None:
|
|
|
|
|
raise Http404
|
|
|
|
|
|
|
|
|
|
b = have_I_right(request, category.blog.id)[0]
|
|
|
|
|
b,_ = have_I_right(request, category.blog.id)
|
|
|
|
|
|
|
|
|
|
category.remove()
|
|
|
|
|
category.delete()
|
|
|
|
@@ -224,11 +247,11 @@ def delete_category(request, category_id):
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
def tag(request, blog_id):
|
|
|
|
|
b = have_I_right(request, blog_id)
|
|
|
|
|
b,_ = have_I_right(request, blog_id)
|
|
|
|
|
|
|
|
|
|
tags = Tag.objects.filter(blog_id=blog_id)
|
|
|
|
|
|
|
|
|
|
c = {'tags' : tags}
|
|
|
|
|
c = {'tags' : tags, 'blog' : b}
|
|
|
|
|
|
|
|
|
|
return render(request, 'templates/tag.html', c)
|
|
|
|
|
|
|
|
|
@@ -239,7 +262,7 @@ def edit_tag(request, tag_id):
|
|
|
|
|
if tag is None:
|
|
|
|
|
raise Http404
|
|
|
|
|
|
|
|
|
|
b = have_I_right(request, tag.blog.id)[0]
|
|
|
|
|
b,_ = have_I_right(request, tag.blog.id)
|
|
|
|
|
|
|
|
|
|
if request.method == 'POST': # If the form has been submitted...
|
|
|
|
|
if 'cancel' in request.POST:
|
|
|
|
@@ -266,7 +289,7 @@ def delete_tag(request, tag_id):
|
|
|
|
|
if tag is None:
|
|
|
|
|
raise Http404
|
|
|
|
|
|
|
|
|
|
b = have_I_right(request, tag.blog.id)[0]
|
|
|
|
|
b,_ = have_I_right(request, tag.blog.id)
|
|
|
|
|
|
|
|
|
|
tag.remove(b)
|
|
|
|
|
tag.delete()
|
|
|
|
@@ -307,16 +330,27 @@ def add_blog(request):
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
def view_blog(request, blog_id):
|
|
|
|
|
if not request.user.is_superuser:
|
|
|
|
|
b = Blog.objects.filter(id=blog_id).filter(writers=request.user.id)
|
|
|
|
|
b,_ = have_I_right(request, blog_id)
|
|
|
|
|
|
|
|
|
|
count = Post.objects.filter(blog=b).count()
|
|
|
|
|
nb_pages = int(count/50)
|
|
|
|
|
if 'page' in request.GET:
|
|
|
|
|
cur_page = int(request.GET['page'])
|
|
|
|
|
else:
|
|
|
|
|
b = Blog.objects.get(pk=blog_id)
|
|
|
|
|
if 'cur_page' in request.session:
|
|
|
|
|
cur_page = request.session['cur_page']
|
|
|
|
|
else:
|
|
|
|
|
cur_page = 0
|
|
|
|
|
|
|
|
|
|
if b is None:
|
|
|
|
|
raise Http404
|
|
|
|
|
if cur_page < 0 : cur_page = 0
|
|
|
|
|
if cur_page > nb_pages : cur_page = nb_pages-1
|
|
|
|
|
|
|
|
|
|
posts = Post.objects.filter(blog=b).order_by('-creation_date')
|
|
|
|
|
b = Blog.objects.get(pk=blog_id)
|
|
|
|
|
request.session['cur_page'] = cur_page
|
|
|
|
|
|
|
|
|
|
start = cur_page * 50
|
|
|
|
|
end = start + 50
|
|
|
|
|
|
|
|
|
|
posts = Post.objects.filter(blog=b).order_by('-creation_date')[start:end]
|
|
|
|
|
form = BlogForm(instance=b)
|
|
|
|
|
|
|
|
|
|
comments = Comment.objects.all()
|
|
|
|
@@ -328,7 +362,9 @@ def view_blog(request, blog_id):
|
|
|
|
|
else:
|
|
|
|
|
dict_comments[key] = dict_comments[key] + 1
|
|
|
|
|
|
|
|
|
|
c = {'blog' : b, 'posts' : posts, 'form' : form, 'comments' : dict_comments}
|
|
|
|
|
navigation_bar = createNavigationBar(b.id, cur_page, nb_pages)
|
|
|
|
|
|
|
|
|
|
c = {'blog' : b, 'posts' : posts, 'form' : form, 'comments' : dict_comments, 'navigation_bar' : navigation_bar}
|
|
|
|
|
|
|
|
|
|
return render(request, 'templates/view_blog.html', c)
|
|
|
|
|
|
|
|
|
@@ -389,7 +425,6 @@ def add_post(request, blog_id):
|
|
|
|
|
@login_required
|
|
|
|
|
def edit_post(request, post_id):
|
|
|
|
|
(b, post) = have_I_right(request, None, post_id)
|
|
|
|
|
post = Post.objects.get(pk=post_id)
|
|
|
|
|
|
|
|
|
|
title = post.title
|
|
|
|
|
blog_id = b.id
|
|
|
|
@@ -434,20 +469,20 @@ def edit_post(request, post_id):
|
|
|
|
|
def delete_post(request, post_id):
|
|
|
|
|
(b, post) = have_I_right(request, None, post_id)
|
|
|
|
|
|
|
|
|
|
blog_id = b.id
|
|
|
|
|
|
|
|
|
|
post.delete()
|
|
|
|
|
|
|
|
|
|
return HttpResponseRedirect('/blog/' + str(blog_id))
|
|
|
|
|
return HttpResponseRedirect('/blog/' + str(b.id))
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
def generate(request, blog_id):
|
|
|
|
|
(b, post) = have_I_right(request, blog_id)
|
|
|
|
|
b,_ = have_I_right(request, blog_id)
|
|
|
|
|
|
|
|
|
|
b.create_paths()
|
|
|
|
|
report = b.generate()
|
|
|
|
|
|
|
|
|
|
posts = Post.objects.filter(blog=b).order_by('-creation_date')
|
|
|
|
|
count = Post.objects.filter(blog=b).count()
|
|
|
|
|
nb_pages = int(count/50)
|
|
|
|
|
posts = Post.objects.filter(blog=b).order_by('-creation_date')[0:50]
|
|
|
|
|
b = Blog.objects.get(pk=blog_id)
|
|
|
|
|
form = BlogForm(instance=b)
|
|
|
|
|
|
|
|
|
@@ -460,7 +495,9 @@ def generate(request, blog_id):
|
|
|
|
|
else:
|
|
|
|
|
dict_comments[key] = dict_comments[key] + 1
|
|
|
|
|
|
|
|
|
|
c = {'blog' : b, 'posts' : posts, 'form' : form, 'report': report, 'comments' : dict_comments}
|
|
|
|
|
navigation_bar = createNavigationBar(b.id, 0, nb_pages)
|
|
|
|
|
|
|
|
|
|
c = {'blog' : b, 'posts' : posts, 'form' : form, 'report': report, 'comments' : dict_comments, 'navigation_bar' : navigation_bar}
|
|
|
|
|
|
|
|
|
|
return render(request, 'templates/generate.html', c)
|
|
|
|
|
|
|
|
|
|