[FIX] Promote to doc flow
authorFabien Pinckaers <fp@tinyerp.com>
Mon, 21 Apr 2014 20:23:50 +0000 (22:23 +0200)
committerFabien Pinckaers <fp@tinyerp.com>
Mon, 21 Apr 2014 20:23:50 +0000 (22:23 +0200)
bzr revid: fp@tinyerp.com-20140421202350-n6uzooo9mvty07i7

addons/website_forum/models/forum.py
addons/website_forum/views/website_forum.xml
addons/website_forum_doc/controllers/main.py
addons/website_forum_doc/models/documentation.py
addons/website_forum_doc/views/website_doc.xml

index eba94a2..166fdb8 100644 (file)
@@ -111,7 +111,7 @@ class Post(osv.Model):
         'state': fields.selection([('active', 'Active'), ('close', 'Close'), ('offensive', 'Offensive')], 'Status'),
         'views': fields.integer('Number of Views'),
         'active': fields.boolean('Active'),
-        'is_correct': fields.boolean('Valid Answer', help='Correct Answer/ Answer on this question accepted.'),
+        'is_correct': fields.boolean('Valid Answer', help='Correct Answer or Answer on this question accepted.'),
         'website_message_ids': fields.one2many(
             'mail.message', 'res_id',
             domain=lambda self: [
index fe0c5c1..be46170 100644 (file)
 <!-- Specific Post Layout -->
 <template id="post_description_full" name="Question Navigation">
     <t t-call="website_forum.header">
-
         <div t-attf-class="question #{not question.active and 'alert alert-danger' or ''}">
             <div class="text-center pull-left">
                 <t t-call="website_forum.vote">
                                 <a t-attf-href="/forum/#{ slug(forum) }/tag/#{ tag.id }/questions" class="badge" t-field="tag.name"/>
                             </t>
                         </div>
-                        <ul class="list-inline">
+                        <ul class="list-inline" id="options">
                             <li t-if="user.id == question.create_uid.id or user.karma&gt;=50">
                                 <a style="cursor: pointer" data-toggle="collapse" class="text-muted fa fa-comment-o"
                                       t-attf-data-target="#comment#{ question._name.replace('.','') + '-' + str(question.id) }">
index 466f015..6741c64 100644 (file)
@@ -38,24 +38,32 @@ class WebsiteDoc(http.Controller):
         }
         return request.website.render("website_forum_doc.documentation_post", value)
 
+    @http.route('/forum/<model("forum.forum"):forum>/question/<model("forum.post"):post>/promote', type='http', auth="user", multilang=True, website=True)
+    def post_toc(self, forum, post, **kwargs):
+        cr, uid, context, toc_id = request.cr, request.uid, request.context, False
+        toc_obj = request.registry['forum.documentation.toc']
+        obj_ids = toc_obj.search(cr, uid, [], context=context)
+        tocs = toc_obj.browse(cr, uid, obj_ids, context=context)
+        value = {
+            'post': post,
+            'forum': post.forum_id,
+            'chapters': filter(lambda x: not x.child_ids, tocs)
+        }
+        return request.website.render("website_forum_doc.promote_question", value)
+
+    @http.route('/forum/<model("forum.forum"):forum>/promote_ok', type='http', auth="user", multilang=True, website=True)
+    def post_toc_ok(self, forum, post_id, toc_id, **kwargs):
+        cr, uid, context = request.cr, request.uid, request.context
+        user = request.registry['res.users'].browse(cr, uid, uid, context=context)
+        assert user.karma > 10, 'Not enough karma'
+
+        toc_obj = request.registry['forum.documentation.toc']
+        stage_ids = toc_obj.search(cr, uid, [], limit=1, context=context)
+
+        post_obj = request.registry['forum.post']
+        post_obj.write(cr, uid, [int(post_id)], {
+            'documentation_toc_id': toc_id and int(toc_id) or False,
+            'documentation_stage_id': stage_ids and stage_ids[0] or False
+        }, context=context)
+        return request.redirect('/forum/'+str(forum.id)+'/question/'+str(post_id))
 
-#---------------------
-# Forum Posts
-# --------------------
-# 
-# class WebsiteForum(WebsiteForum):
-# 
-#     def prepare_question_values(self, forum, **kwargs):
-#         cr, uid, context = request.cr, request.uid, request.context
-#         TOC = request.registry['documentation.toc']
-#         obj_ids = TOC.search(cr, uid, [('child_ids', '=', False)], context=context)
-#         toc = TOC.browse(cr, uid, obj_ids, context=context)
-#         values = super(WebsiteForum, self).prepare_question_values(forum=forum, kwargs=kwargs)
-#         values.update({'documentaion_toc': toc})
-#         return values
-# 
-#     @http.route('/forum/<model("forum.forum"):forum>/question/<model("forum.post"):post>/toc', type='http', auth="user", multilang=True, website=True)
-#     def post_toc(self, forum, post, **kwargs):
-#         toc_id = int(kwargs.get('content')) if kwargs.get('content') else False
-#         request.registry['forum.post'].write(request.cr, request.uid, [post.id], {'toc_id': toc_id}, context=request.context)
-#         return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(post)))
index 9563679..40ca400 100644 (file)
@@ -10,8 +10,27 @@ class Documentation(osv.Model):
     _order = "parent_left"
     _parent_order = "sequence, name"
     _parent_store = True
+    def name_get(self, cr, uid, ids, context=None):
+        if isinstance(ids, (list, tuple)) and not len(ids):
+            return []
+        if isinstance(ids, (long, int)):
+            ids = [ids]
+        reads = self.read(cr, uid, ids, ['name','parent_id'], context=context)
+        res = []
+        for record in reads:
+            name = record['name']
+            if record['parent_id']:
+                name = record['parent_id'][1]+' / '+name
+            res.append((record['id'], name))
+        return res
+
+    def _name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None):
+        res = self.name_get(cr, uid, ids, context=context)
+        return dict(res)
+
     _columns = {
         'sequence': fields.integer('Sequence'),
+        'display_name': fields.function(_name_get_fnc, type="char", string='Full Name'),
         'name': fields.char('Name', required=True, translate=True),
         'introduction': fields.html('Introduction', translate=True),
         'parent_id': fields.many2one('forum.documentation.toc', 'Parent Table Of Content'),
index 5be0dc3..efc842d 100644 (file)
 
 
         <!--TOC ON FORUM POST-->
-        <template id="forum_question_right_column" inherit_id="website_forum.header" name="Table of Content">
-            <xpath expr="//script[@src='/website_forum/static/src/js/website_forum.js']" position="after">
-                <script type="text/javascript" src="/website_doc/static/src/js/website_doc.js"/>
+        <template id="forum_question_doc" inherit_id="website_forum.post_description_full" name="Forum Post to Doc">
+            <xpath expr="//ul[@id='options']" position="inside">
+                <li t-if="(not question.documentation_stage_id) and user.karma&gt;=10">
+                    <a t-attf-href="/forum/#{ slug(forum) }/question/#{slug(question)}/promote" class="text-muted fa fa-bookmark-o">
+                        Promote to Doc
+                    </a>
+                </li>
             </xpath>
-            <xpath expr="//div[@id='about_forum']" position="before">
-                <div t-if="header.get('question_data')" groups="website_doc.group_documentaion_moderator">
-                    <div class="panel panel-default">
-                        <div class="panel-heading" id="about_forum">
-                            <h3 class="panel-title">Documentation</h3>
-                        </div>
-                        <div class="panel-body">
-                            <form t-attf-action="/forum/#{ slug(forum) }/question/#{ slug(question) }/toc" role="form" method="post">
-                                <div class="input-group navbar-right">
-                                    <select class="form-control" name="content">
-                                        <option value=""></option>
-                                        <t t-foreach="documentaion_toc or []" t-as="toc">
-                                            <option t-att-value="toc.id" t-att-selected="toc.id == question.toc_id.id"><t t-esc="toc.name"/></option>
+        </template>
+
+        <template id="promote_question">
+            <t t-call="website.layout">
+                <section class="container">
+                    <h1 class="page-header">Promote question to documentation</h1>
+                    <p>
+                        To be promoted in the official documentation the question
+                        and answer must satisfy the following criteria:
+                    </p>
+                    <ul>
+                        <li>The question title is short and descriptive</li>
+                        <li>The question describes a real business problem, not a software problem</li>
+                        <li>The answer is understandable for someone who does not know Odoo</li>
+                    </ul>
+                    <p>
+                        Before submiting the question, help us improve its quality by
+                        editing the question and the main answer.
+                    </p>
+                </section>
+                <div class="container">
+                    <div class="well">
+                        <form t-attf-action="/forum/#{ slug(forum) }/promote_ok" method="post" role="form" class="form-horizontal">
+                            <input name="post_id" t-att-value="post.id" type="hidden"/>
+                            <div class="form-group">
+                                <label class="col-md-3 control-label" for="reason">Question:</label>
+                                <div class="col-md-8 mt8">
+                                    <span t-field="post.name"/>
+                                </div>
+                            </div>
+                            <div class="form-group">
+                                <label class="col-md-3 control-label" for="reason">Publish in Chapter:</label>
+                                <div class="col-md-8">
+                                    <select class="form-control" name="toc_id">
+                                        <option/>
+                                        <t t-foreach="chapters or []" t-as="chapter">
+                                            <option t-att-value="chapter.id"><t t-esc="chapter.display_name"/></option>
                                         </t>
                                     </select>
-                                    <span class="input-group-btn">
-                                        <button class="btn btn-primary ">save</button>
-                                    </span>
                                 </div>
-                            </form>
-                        </div>
+                            </div>
+                            <div class="form-group">
+                                <div class="col-md-offset-3 col-md-8">
+                                    <button class="btn btn-primary">Push to documentation</button>
+                                    <span class="text-muted">or</span>
+                                    <a class="btn btn-link" t-attf-href="/forum/#{ slug(forum) }/question/#{ slug(post) }">cancel</a>
+                                </div>
+                            </div>
+                        </form>
                     </div>
                 </div>
-            </xpath>
+                <section class="container">
+                    <h2 class="page-header">Samples</h2>
+                    <div class="row">
+                        <div class="col-sm-6">
+                            <h4>Good question titles</h4>
+                            <ul>
+                                <li>How to forecast sales revenues?</li>
+                                <li>How to compute future inventories for a product?</li>
+                            </ul>
+
+                        </div>
+                        <div class="col-sm-6">
+                            <h4>Bad questions</h4>
+                            <ul>
+                                <li>What report should I use to compute probabilities per stage?</li>
+                                <li>What's the available stock field?</li>
+                            </ul>
+                        </div>
+                    </div>
+                    <div class="row mb64">
+                        <div class="col-sm-6">
+                            <h4>Good answer structure</h4>
+                            <ol>
+                                <li>Describe the business solution</li>
+                                <li>Explain how to implement it in OpenERP</li>
+                                <li>Benefits of having done this setup</li>
+                            </ol>
+                        </div>
+                        <div class="col-sm-6">
+                            <h4>Bad answer structure</h4>
+                            <ol>
+                                <li>Explain how to configure in OpenERP</li>
+                                <li>No business benefit</li>
+                            </ol>
+                        </div>
+                    </div>
+                </section>
+            </t>
         </template>
 
+
     </data>
 </openerp>