Add internal post search to Dynastie
This commit is contained in:
parent
f7a3e3f9c9
commit
814fd6c667
|
@ -6,6 +6,7 @@
|
||||||
<meta content="Blog de Grégory Soutadé" name="description"/>
|
<meta content="Blog de Grégory Soutadé" name="description"/>
|
||||||
<meta content="Dynastie" name="generator"/>
|
<meta content="Dynastie" name="generator"/>
|
||||||
<title>Blog de Grégory Soutadé</title>
|
<title>Blog de Grégory Soutadé</title>
|
||||||
|
<link rel="icon" type="image/png" href="/images/favicon.png" />
|
||||||
<link href="/rss.xml" rel="alternate" type="application/rss+xml" title="RSS 2.0" />
|
<link href="/rss.xml" rel="alternate" type="application/rss+xml" title="RSS 2.0" />
|
||||||
<link href="/atom.xml" rel="alternate" type="application/atom+xml" title="Atom 1.0" />
|
<link href="/atom.xml" rel="alternate" type="application/atom+xml" title="Atom 1.0" />
|
||||||
<link href="/css/blog.css" rel="stylesheet" type="text/css"/>
|
<link href="/css/blog.css" rel="stylesheet" type="text/css"/>
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
<dyn:meta name="author"/>
|
<dyn:meta name="author"/>
|
||||||
<meta content="Dynastie" name="generator"/>
|
<meta content="Dynastie" name="generator"/>
|
||||||
<title>Blog de Grégory Soutadé</title>
|
<title>Blog de Grégory Soutadé</title>
|
||||||
|
<link rel="icon" type="image/png" href="/images/favicon.png" />
|
||||||
<link href="/rss.xml" rel="alternate" type="application/rss+xml" title="RSS 2.0" />
|
<link href="/rss.xml" rel="alternate" type="application/rss+xml" title="RSS 2.0" />
|
||||||
<link href="/atom.xml" rel="alternate" type="application/atom+xml" title="Atom 1.0" />
|
<link href="/atom.xml" rel="alternate" type="application/atom+xml" title="Atom 1.0" />
|
||||||
<link href="/css/blog.css" rel="stylesheet" type="text/css"/>
|
<link href="/css/blog.css" rel="stylesheet" type="text/css"/>
|
||||||
|
|
|
@ -15,6 +15,10 @@
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
<a href="/post/add/{{ blog.id }}">Add a post</a> <a href="/generate/{{ blog.id }}">Generate blog</a> <a href="/search/generate/{{ blog.id }}">Generate search index</a>
|
<a href="/post/add/{{ blog.id }}">Add a post</a> <a href="/generate/{{ blog.id }}">Generate blog</a> <a href="/search/generate/{{ blog.id }}">Generate search index</a>
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
|
<form action="/blog/search/{{ blog.id }}" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<input name="text"/><input type="submit" name="search" value="Search" />
|
||||||
|
</form>
|
||||||
{% if posts|length == 0 %}
|
{% if posts|length == 0 %}
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
<b>Any post available</b><br/><br/>
|
<b>Any post available</b><br/><br/>
|
||||||
|
|
|
@ -40,6 +40,7 @@ urlpatterns = patterns('',
|
||||||
url(r'^blog/add$', 'dynastie.views.add_blog', name='add_blog'),
|
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/(\d+)$', 'dynastie.views.view_blog', name='view_blog'),
|
||||||
url(r'^blog/edit/(\d+)$', 'dynastie.views.edit_blog', name='edit_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/add/(\d+)$', 'dynastie.views.add_post', name='add_post'),
|
||||||
url(r'^post/edit/(\d+)$', 'dynastie.views.edit_post', name='edit_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'),
|
url(r'^post/delete/(\d+)$', 'dynastie.views.delete_post', name='delete_post'),
|
||||||
|
|
|
@ -416,6 +416,43 @@ def edit_blog(request, blog_id):
|
||||||
|
|
||||||
return render(request, 'view_blog.html', c)
|
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
|
@login_required
|
||||||
def add_post(request, blog_id):
|
def add_post(request, blog_id):
|
||||||
(b,_) = have_I_right(request, blog_id)
|
(b,_) = have_I_right(request, blog_id)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user