[imp]:improve post history
authorSunil Sharma (OpenERP) <sunilsharma.sharma07@gmail.com>
Fri, 28 Mar 2014 13:34:04 +0000 (19:04 +0530)
committerSunil Sharma (OpenERP) <sunilsharma.sharma07@gmail.com>
Fri, 28 Mar 2014 13:34:04 +0000 (19:04 +0530)
bzr revid: sunilsharma.sharma07@gmail.com-20140328133404-e6vkg9f4rjm6qmp8

addons/website_forum/controllers/main.py
addons/website_forum/models/forum.py
addons/website_forum/static/src/js/website_forum.js
addons/website_forum/views/website_forum.xml

index d056010..408ca00 100644 (file)
@@ -467,9 +467,13 @@ class website_forum(http.Controller):
 
     @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):
+        post_history_obj = request.registry['website.forum.post.history'];
         tags = ""
         for tag_name in post.tags:
             tags += tag_name.name + ","
+        
+        ids = post_history_obj.search(request.cr, request.uid, [('post_id','=', post.id)], context=request.context)
+        post_history = post_history_obj.browse(request.cr, request.uid, ids, context=request.context)
 
         values = {
             'post': post,
@@ -477,6 +481,7 @@ class website_forum(http.Controller):
             'forum': forum,
             'searches': kwarg,
             'notifications': self._get_notifications(),
+            'history': post_history,
         }
         return request.website.render("website_forum.edit_question", values)
 
@@ -637,3 +642,9 @@ class website_forum(http.Controller):
         post_ids.append(post.id)
         request.registry['website.forum.post'].message_unsubscribe( cr, uid, post_ids, [partner_id], context=context)
         return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.id))
+
+    @http.route('/forum/change_question/', type='json', auth="user", multilang=True, methods=['POST'], website=True)
+    def correct_answer(self, **kwarg):
+        cr, uid, context = request.cr, request.uid, request.context
+        return True
+
index f0f14d4..72544b1 100644 (file)
@@ -227,9 +227,9 @@ class Post(osv.Model):
         return post_id
 
     def write(self, cr, uid, ids, vals, context=None):
-        self.create_history(cr, uid, ids, vals, context=context)
         #NOTE: to avoid message post on write of last comment time
         if not vals.get('message_last_post'):
+            self.create_history(cr, uid, ids, vals, context=context)
             for post in self.browse(cr, uid, ids, context=context):
                 body, subtype = "Edited question", "website_forum.mt_question_edit"
                 if post.parent_id:
index 4dd3b66..7981e76 100644 (file)
@@ -116,4 +116,13 @@ $(document).ready(function () {
         });
     };
 
+    $('.change_question').change(function (ev) {
+        var $option = $(ev.currentTarget);
+        openerp.jsonRpc("/forum/change_question/", 'call', {
+            'option': $option.attr("id")})
+            .then(function (data) {
+            })
+        return true;
+    });
+
 });
\ No newline at end of file
index 34cf953..1c4de93 100644 (file)
             <t t-call="website_forum.header">
                 <h3>Edit question</h3>
                 <form t-attf-action="/forum/#{ slug(forum) }/question/savequestion/" method="post" role="form" class="tag_text">
+                    <select class="form-control change_question" id="change_que">
+                        <t t-foreach="history" t-as="history_post">
+                            <option t-att-value="history_post.id"><t t-esc="history_post.name"/></option>
+                        </t>
+                     </select>
                     <input type="text" name="question_name" required="True" t-attf-value="#{post.name or ''}"
                         class="form-control" placeholder="Edit your Question"/>
                     <h5 class="mt20">Please enter a descriptive question (should finish by a '?')</h5>