diff --git a/dynastie/sites/blog.soutade.fr/_base.html b/dynastie/sites/blog.soutade.fr/_base.html index 5eba06e..a89831c 100755 --- a/dynastie/sites/blog.soutade.fr/_base.html +++ b/dynastie/sites/blog.soutade.fr/_base.html @@ -6,6 +6,7 @@ Blog de Grégory Soutadé + diff --git a/dynastie/sites/blog.soutade.fr/_base_post.html b/dynastie/sites/blog.soutade.fr/_base_post.html index ac30ed1..9e87521 100644 --- a/dynastie/sites/blog.soutade.fr/_base_post.html +++ b/dynastie/sites/blog.soutade.fr/_base_post.html @@ -8,6 +8,7 @@ Blog de Grégory Soutadé + diff --git a/dynastie/templates/view_blog.html b/dynastie/templates/view_blog.html index ee1e985..4079ee7 100755 --- a/dynastie/templates/view_blog.html +++ b/dynastie/templates/view_blog.html @@ -15,6 +15,10 @@

Add a post Generate blog Generate search index

+
+{% csrf_token %} + +
{% if posts|length == 0 %}

Any post available

diff --git a/dynastie/urls.py b/dynastie/urls.py index 73ee258..101f9d8 100755 --- a/dynastie/urls.py +++ b/dynastie/urls.py @@ -40,6 +40,7 @@ urlpatterns = patterns('', url(r'^blog/add$', 'dynastie.views.add_blog', name='add_blog'), url(r'^blog/(\d+)$', 'dynastie.views.view_blog', name='view_blog'), url(r'^blog/edit/(\d+)$', 'dynastie.views.edit_blog', name='edit_blog'), + url(r'^blog/search/(\d+)$', 'dynastie.views.search_blog', name='search_blog'), url(r'^post/add/(\d+)$', 'dynastie.views.add_post', name='add_post'), url(r'^post/edit/(\d+)$', 'dynastie.views.edit_post', name='edit_post'), url(r'^post/delete/(\d+)$', 'dynastie.views.delete_post', name='delete_post'), diff --git a/dynastie/views.py b/dynastie/views.py index c7d4f5f..28843cb 100755 --- a/dynastie/views.py +++ b/dynastie/views.py @@ -416,6 +416,43 @@ def edit_blog(request, blog_id): return render(request, 'view_blog.html', c) +@login_required +def search_blog(request, blog_id): + from dynastie.generators import search + b,_ = have_I_right(request, blog_id) + + text = request.POST['text'] + + if text is None or text == '': + return HttpResponseRedirect('/blog') + + s = Search() + post_list = s.search(b, text) + + posts = [] + if not post_list is None: + post_list = post_list[:50] + for post_id in post_list: + try: + post = Post.objects.get(pk=post_id) + except: + continue + if not post is None: + posts.append(post) + + comments = Comment.objects.all() + dict_comments = {} + for comment in comments: + key = comment.post.id + if not key in dict_comments: + dict_comments[key] = 1 + else: + dict_comments[key] = dict_comments[key] + 1 + + c = {'blog' : b, 'posts' : posts, 'comments' : dict_comments} + + return render(request, 'search_blog.html', c) + @login_required def add_post(request, blog_id): (b,_) = have_I_right(request, blog_id)