diff options
| author | Turkesh Patel (Open ERP) <tpa@tinyerp.com> | 2014-03-25 14:42:40 +0530 |
|---|---|---|
| committer | Turkesh Patel (Open ERP) <tpa@tinyerp.com> | 2014-03-25 14:42:40 +0530 |
| commit | a9d192da242f48bf4b342027f18f4f0528c61550 (patch) | |
| tree | 21de8c8ce5cb701eaa4ae373ec47fc88fc9b5ccb | |
| parent | ff76d9ff8aa75242b208786240adc10b06a02ec6 (diff) | |
[IMP] improved code to show some items based on user.
bzr revid: tpa@tinyerp.com-20140325091240-ie606wjojnfakgno
| -rw-r--r-- | addons/website_forum/controllers/main.py | 25 | ||||
| -rw-r--r-- | addons/website_forum/views/website_forum.xml | 43 |
2 files changed, 32 insertions, 36 deletions
diff --git a/addons/website_forum/controllers/main.py b/addons/website_forum/controllers/main.py index 02d4c21213d..c0addfd6343 100644 --- a/addons/website_forum/controllers/main.py +++ b/addons/website_forum/controllers/main.py @@ -248,7 +248,6 @@ class website_forum(http.Controller): @http.route('/forum/<model("website.forum"):forum>/question/ask/', type='http', auth="user", multilang=True, methods=['POST'], website=True) def register_question(self, forum, **question): cr, uid, context = request.cr, request.uid, request.context - create_context = dict(context) tags = question.get('question_tags').strip('[]').replace('"','').split(",") @@ -273,6 +272,7 @@ class website_forum(http.Controller): def post_answer(self, forum ,post_id, **question): if not request.session.uid: return login_redirect() + cr, uid, context = request.cr, request.uid, request.context request.registry['res.users'].write(cr, uid, uid, {'forum': True}, context=context) @@ -408,10 +408,8 @@ class website_forum(http.Controller): request.registry['website.forum.post'].unlink(request.cr, request.uid, [int(kwarg.get('post_id'))], context=request.context) return True - @http.route('/forum/<model("website.forum"):forum>/delete/question/<model("website.forum.post"):post>', type='http', auth="public", multilang=True, website=True) + @http.route('/forum/<model("website.forum"):forum>/delete/question/<model("website.forum.post"):post>', type='http', auth="user", multilang=True, website=True) def delete_question(self, forum, post, **kwarg): - if not request.session.uid: - return login_redirect() #instead of unlink record just change 'active' to false so user can undelete it. request.registry['website.forum.post'].write( request.cr, request.uid, [post.id], { 'active': False, @@ -430,11 +428,8 @@ class website_forum(http.Controller): request.registry['mail.message'].unlink(request.cr, request.uid, [int(kwarg.get('message_id'))], context=request.context) return True - @http.route('/forum/<model("website.forum"):forum>/edit/question/<model("website.forum.post"):post>', type='http', auth="public", multilang=True, website=True) + @http.route('/forum/<model("website.forum"):forum>/edit/question/<model("website.forum.post"):post>', type='http', auth="user", multilang=True, website=True) def edit_question(self, forum, post, **kwarg): - if not request.session.uid: - return login_redirect() - tags = "" for tag_name in post.tags: tags += tag_name.name + "," @@ -491,10 +486,8 @@ class website_forum(http.Controller): }, context=context) return correct - @http.route('/forum/<model("website.forum"):forum>/close/question/<model("website.forum.post"):post>', type='http', auth="public", multilang=True, website=True) + @http.route('/forum/<model("website.forum"):forum>/close/question/<model("website.forum.post"):post>', type='http', auth="user", multilang=True, website=True) def close_question(self, forum, post, **kwarg): - if not request.session.uid: - return login_redirect() cr, uid, context = request.cr, request.uid, request.context Reason = request.registry['website.forum.post.reason'] reason_ids = Reason.search(cr, uid, [], context=context) @@ -521,8 +514,6 @@ class website_forum(http.Controller): @http.route('/forum/<model("website.forum"):forum>/reopen/question/<model("website.forum.post"):post>', type='http', auth="user", multilang=True, website=True) def reopen(self, forum, post, **kwarg): - if not request.session.uid: - return login_redirect() request.registry['website.forum.post'].write( request.cr, request.uid, [post.id], { 'state': 'active', }, context=request.context) @@ -561,20 +552,14 @@ class website_forum(http.Controller): @http.route('/forum/<model("website.forum"):forum>/post/<model("website.forum.post"):post>/commet/<model("mail.message"):comment>/converttoanswer', type='http', auth="public", multilang=True, website=True) def convert_to_answer(self, forum, post, comment, **kwarg): - if not request.session.uid: - return login_redirect() - values = { 'answer_content': comment.body, } request.registry['mail.message'].unlink(request.cr, request.uid, [comment.id], context=request.context) return self.post_answer(forum, post.parent_id and post.parent_id.id or post.id, **values) - @http.route('/forum/<model("website.forum"):forum>/post/<model("website.forum.post"):post>/converttocomment', type='http', auth="public", multilang=True, website=True) + @http.route('/forum/<model("website.forum"):forum>/post/<model("website.forum.post"):post>/converttocomment', type='http', auth="user", multilang=True, website=True) def convert_to_comment(self, forum, post, **kwarg): - if not request.session.uid: - return login_redirect() - values = { 'comment': html2plaintext(post.content), } diff --git a/addons/website_forum/views/website_forum.xml b/addons/website_forum/views/website_forum.xml index b487b31ed54..7606ac474ab 100644 --- a/addons/website_forum/views/website_forum.xml +++ b/addons/website_forum/views/website_forum.xml @@ -384,16 +384,21 @@ comment </a> </li> - <li><a class="text-muted fa fa-times" t-if="question.state != 'close'" - t-attf-href="/forum/#{ slug(forum) }/close/question/#{ question.id }">close</a></li> - <li><a class="text-muted fa fa-undo" t-if="question.state == 'close'" - t-attf-href="/forum/#{ slug(forum) }/reopen/question/#{ question.id }">reopen</a></li> - <li><a class="text-muted fa fa-edit" - t-attf-href="/forum/#{ slug(forum) }/edit/question/#{ question.id }">edit</a></li> - <li><a class="text-muted fa fa-trash-o" t-if="question.active" - t-attf-href="/forum/#{ slug(forum) }/delete/question/#{ question.id }">delete</a></li> - <li><a class="text-muted fa fa-trash-o" t-if="not question.active" - t-attf-href="/forum/#{ slug(forum) }/undelete/question/#{ question.id }">undelete</a></li> + <li t-if="question.state != 'close' and uid"> + <a class="text-muted fa fa-times" t-attf-href="/forum/#{ slug(forum) }/close/question/#{ question.id }">close</a> + </li> + <li t-if="question.state == 'close' and uid"> + <a class="text-muted fa fa-undo" t-attf-href="/forum/#{ slug(forum) }/reopen/question/#{ question.id }">reopen</a> + </li> + <li t-if="uid"> + <a class="text-muted fa fa-edit" t-attf-href="/forum/#{ slug(forum) }/edit/question/#{ question.id }">edit</a> + </li> + <li t-if="question.active and uid == question.user_id.id"> + <a class="text-muted fa fa-trash-o" t-attf-href="/forum/#{ slug(forum) }/delete/question/#{ question.id }">delete</a> + </li> + <li t-if="uid == question.user_id.id and not question.active"> + <a class="text-muted fa fa-trash-o" t-attf-href="/forum/#{ slug(forum) }/undelete/question/#{ question.id }">undelete</a> + </li> <li><a class="text-muted fa fa-share" href="">share</a></li> </ul> </div> @@ -440,13 +445,18 @@ <ul class="list-inline pull-right"> <li> <a style="cursor: pointer" data-toggle="collapse" class="text-muted fa fa-comment-o" - t-attf-data-target="#comment#{ answer._name.replace('.','') + '-' + str(answer.id) }"> - comment + t-attf-data-target="#comment#{ answer._name.replace('.','') + '-' + str(answer.id) }">comment </a> </li> - <li><a class="text-muted fa fa-edit" t-attf-href="/forum/#{ slug(forum) }/answer/#{ question.id }/edit/#{ answer.id }">edit</a></li> - <li><a class="text-muted delete fa fa-trash-o" href="" t-attf-id="#{answer.id}">delete</a></li> - <li><a class="text-muted fa fa-magic" t-attf-href="/forum/#{ slug(forum) }/post/#{ answer.id }/converttocomment">Convert as a comment</a></li> + <li t-if="uid"> + <a class="text-muted fa fa-edit" t-attf-href="/forum/#{ slug(forum) }/answer/#{ question.id }/edit/#{ answer.id }">edit</a> + </li> + <li t-if="uid == answer.user_id.id"> + <a class="text-muted delete fa fa-trash-o" href="" t-attf-id="#{answer.id}">delete</a> + </li> + <li t-if="uid == answer.user_id.id"> + <a class="text-muted fa fa-magic" t-attf-href="/forum/#{ slug(forum) }/post/#{ answer.id }/converttocomment">Convert as a comment</a> + </li> <li><a class="text-muted fa fa-share" t-attf-href="/forum/#{ slug(forum) }/question/#{ question.id }/#answer-#{ answer.id }">share</a></li> </ul> <t t-set="user" t-value="answer.user_id"/> @@ -478,7 +488,8 @@ <span t-field="message.body"/> <a t-attf-href="/forum/#{ slug(forum) }/user/#{ message.create_uid.id }" t-field="message.create_uid"/> on <span t-field="message.date" t-field-options='{"format":"short"}'/> - <a class="fa fa-magic text-muted pull-right" t-attf-href="/forum/#{ slug(forum) }/post/#{ object.id }/commet/#{ message.id }/converttoanswer">Convert as an answer</a> + <a class="fa fa-magic text-muted pull-right" t-if="uid == message.create_uid.id" + t-attf-href="/forum/#{ slug(forum) }/post/#{ object.id }/commet/#{ message.id }/converttoanswer">Convert as an answer</a> </small> </div> <div class="css_editable_mode_hidden oe_grey"> |
