[FIX] website_forum: escape search by tag, quote char to search, don't create empty tag, only display alphanum first char in pager of tags, ...

This commit is contained in:
Jeremy Kersten
2016-01-08 19:14:31 +01:00
parent 774879a69c
commit e2925909b2
3 changed files with 5 additions and 8 deletions
+2 -3
View File
@@ -183,7 +183,7 @@ class WebsiteForum(http.Controller):
def tags(self, forum, tag_char=None, **post):
# build the list of tag first char, with their value as tag_char param Ex : [('All', 'all'), ('C', 'c'), ('G', 'g'), ('Z', z)]
first_char_tag = forum.get_tags_first_char()
first_char_list = [(t, t.lower()) for t in first_char_tag]
first_char_list = [(t, t.lower()) for t in first_char_tag if t.isalnum()]
first_char_list.insert(0, (_('All'), 'all'))
# get active first char tag
active_char_tag = first_char_list[1][1] if len(first_char_list) > 1 else 'all'
@@ -193,7 +193,7 @@ class WebsiteForum(http.Controller):
domain = [('forum_id', '=', forum.id), ('posts_count', '>', 0)]
order_by = 'name'
if active_char_tag and active_char_tag != 'all':
domain.append(('name', '=ilike', active_char_tag+'%'))
domain.append(('name', '=ilike', tools.escape_psql(active_char_tag)+'%'))
order_by = 'posts_count DESC'
tags = request.env['forum.tag'].search(domain, limit=None, order=order_by)
# prepare values and render template
@@ -205,7 +205,6 @@ class WebsiteForum(http.Controller):
})
return request.website.render("website_forum.tag", values)
@http.route('/forum/<model("forum.forum"):forum>/edit_welcome_message', auth="user", website=True)
def edit_welcome_message(self, forum, **kw):
return request.website.render("website_forum.edit_welcome_message", {'forum': forum})
+1 -1
View File
@@ -174,7 +174,7 @@ class Forum(models.Model):
else:
# check if user have Karma needed to create need tag
user = User.sudo().browse(self._uid)
if user.exists() and user.karma >= self.karma_retag and len(tag.strip('_').strip()) > 0:
if user.exists() and user.karma >= self.karma_retag and len(tag) and len(tag[1:].strip()):
post_tags.append((0, 0, {'name': tag[1:], 'forum_id': self.id}))
else:
existing_keep.append(int(tag))
+2 -4
View File
@@ -1081,18 +1081,16 @@
<ul class="pagination mt0 mb0">
<li class="disabled"><a><i class="fa fa-filter"></i></a></li>
<t t-foreach="pager_tag_chars" t-as="tuple_char">
<li t-attf-class="#{'active' if active_char_tag == tuple_char[1] else ''}"><a t-attf-href="/forum/#{slug(forum)}/tag/#{tuple_char[1]}"><t t-esc="tuple_char[0]"/></a></li>
<li t-attf-class="#{'active' if active_char_tag == tuple_char[1] else ''}"><a t-attf-href="/forum/#{slug(forum)}/tag/#{quote_plus(tuple_char[1])}"><t t-esc="tuple_char[0]"/></a></li>
</t>
</ul>
</nav>
<div class="row">
<div class="col-sm-3 mt16" t-foreach="tags" t-as="tag">
<span><t t-esc="tag.posts_count"/>&amp;nbsp;&amp;nbsp;<i class='fa fa-times'/>&amp;nbsp;&amp;nbsp;</span>
<a t-attf-href="/forum/#{ slug(forum) }/tag/#{ slug(tag) }/questions?{{ keep_query( filters='tag') }}" class="label label-default">
<span t-field="tag.name"/>
</a>
<span>
X <t t-esc="tag.posts_count"/>
</span>
</div>
</div>
</t>