[IMP] website_blog: update templates to use the contact widget, allowing to
authorThibault Delavallée <tde@openerp.com>
Wed, 2 Apr 2014 14:02:00 +0000 (16:02 +0200)
committerThibault Delavallée <tde@openerp.com>
Wed, 2 Apr 2014 14:02:00 +0000 (16:02 +0200)
display partner-related stuff without having to tweak the access rights.
Misc update of templates due to some filed renaming.
Added author field on the blog, allowing to avoid having issues with
create_uid field.

bzr revid: tde@openerp.com-20140402140200-a3g0750akro2n12v

addons/website_blog/__openerp__.py
addons/website_blog/controllers/main.py
addons/website_blog/models/website_blog.py
addons/website_blog/static/src/js/website_blog.editor.js
addons/website_blog/views/website_blog_templates.xml
addons/website_blog/views/website_blog_views.xml

index 97c1639..831c180 100644 (file)
@@ -30,7 +30,7 @@ OpenERP Blog
 
         """,
     'author': 'OpenERP SA',
-    'depends': ['knowledge', 'website_mail'],
+    'depends': ['knowledge', 'website_mail', 'website_partner'],
     'data': [
         'data/website_blog_data.xml',
         'views/website_blog_views.xml',
index 7192d56..5e4baf1 100644 (file)
@@ -1,23 +1,4 @@
 # -*- coding: utf-8 -*-
-##############################################################################
-#
-#    OpenERP, Open Source Management Solution
-#    Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>).
-#
-#    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU Affero General Public License as
-#    published by the Free Software Foundation, either version 3 of the
-#    License, or (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU Affero General Public License for more details.
-#
-#    You should have received a copy of the GNU Affero General Public License
-#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
-#
-##############################################################################
 
 import datetime
 import werkzeug
@@ -68,7 +49,8 @@ class WebsiteBlog(http.Controller):
 
     def nav_list(self):
         blog_post_obj = request.registry['blog.post']
-        groups = blog_post_obj.read_group(request.cr, request.uid, [], ['name', 'create_date'],
+        groups = blog_post_obj.read_group(
+            request.cr, request.uid, [], ['name', 'create_date'],
             groupby="create_date", orderby="create_date asc", context=request.context)
         for group in groups:
             begin_date = datetime.datetime.strptime(group['__domain'][0][2], tools.DEFAULT_SERVER_DATETIME_FORMAT).date()
@@ -109,21 +91,16 @@ class WebsiteBlog(http.Controller):
     def blog(self, blog=None, tag=None, page=1, **opt):
         """ Prepare all values to display the blog.
 
-        :param blog: blog currently browsed.
-        :param tag: tag that is currently used to filter blog posts
-        :param integer page: current page of the pager. Can be the blog or
-                            post pager.
-        :param date: date currently used to filter blog posts (dateBegin_dateEnd)
-
         :return dict values: values for the templates, containing
 
-         - 'blog_posts': list of browse records that are the posts to display
-                         in a given blog, if not blog_post_id
-         - 'blog': browse of the current blog, if blog_id
-         - 'blogs': list of browse records of blogs
-         - 'pager': the pager to display posts pager in a blog
-         - 'tag': current tag, if tag_id
+         - 'blog': current blog
+         - 'blogs': all blogs for navigation
+         - 'pager': pager of posts
+         - 'tag': current tag
+         - 'tags': all tags, for navigation
          - 'nav_list': a dict [year][month] for archives navigation
+         - 'date': date_begin optional parameter, used in archives navigation
+         - 'blog_url': help object to create URLs
         """
         date_begin, date_end = opt.get('date_begin'), opt.get('date_end')
 
@@ -183,28 +160,20 @@ class WebsiteBlog(http.Controller):
     def blog_post(self, blog, blog_post, tag_id=None, page=1, enable_editor=None, **post):
         """ Prepare all values to display the blog.
 
-        :param blog_post: blog post currently browsed. If not set, the user is
-                          browsing the blog and a post pager is calculated.
-                          If set the user is reading the blog post and a
-                          comments pager is calculated.
-        :param blog: blog currently browsed.
-        :param tag: tag that is currently used to filter blog posts
-        :param integer page: current page of the pager. Can be the blog or
-                            post pager.
-        :param date: date currently used to filter blog posts (dateBegin_dateEnd)
-
-         - 'enable_editor': editor control
-
         :return dict values: values for the templates, containing
 
-         - 'blog_post': browse of the current post, if blog_post_id
-         - 'blog': browse of the current blog, if blog_id
+         - 'blog_post': browse of the current post
+         - 'blog': browse of the current blog
          - 'blogs': list of browse records of blogs
-         - 'pager': the pager to display comments pager in a blog post
-         - 'tag': current tag, if tag_id
+         - 'tag': current tag, if tag_id in parameters
+         - 'tags': all tags, for tag-based navigation
+         - 'pager': a pager on the comments
          - 'nav_list': a dict [year][month] for archives navigation
-         - 'next_blog': next blog post , display in footer
+         - 'next_post': next blog post, to direct the user towards the next interesting post
         """
+        cr, uid, context = request.cr, request.uid, request.context
+        tag_obj = request.registry['blog.tag']
+        blog_post_obj = request.registry['blog.post']
         date_begin, date_end = post.get('date_begin'), post.get('date_end')
 
         pager_url = "/blogpost/%s" % blog_post.id
@@ -226,18 +195,10 @@ class WebsiteBlog(http.Controller):
         post_url = QueryURL('', ['blogpost'], blogpost=blog_post, tag_id=tag_id, date_begin=date_begin, date_end=date_end)
         blog_url = QueryURL('', ['blog', 'tag'], blog=blog_post.blog_id, tag=tag, date_begin=date_begin, date_end=date_end)
 
-        cr, uid, context = request.cr, request.uid, request.context
-        if not blog_post.blog_id.id==blog.id:
+        if not blog_post.blog_id.id == blog.id:
             return request.redirect("/blog/%s/post/%s" % (blog_post.blog_id.id, blog_post.id))
-        blog_post_obj = request.registry.get('blog.post')
-
-        blog_obj = request.registry['blog.blog']
-        blog_ids = blog_obj.search(cr, uid, [], context=context)
-        blogs = blog_obj.browse(cr, uid, blog_ids, context=context)
 
-        tag_obj = request.registry['blog.tag']
-        tag_ids = tag_obj.search(cr, uid, [], context=context)
-        tags = tag_obj.browse(cr, uid, tag_ids, context=context)
+        tags = tag_obj.browse(cr, uid, tag_obj.search(cr, uid, [], context=context), context=context)
 
         # Find next Post
         visited_blogs = request.httprequest.cookies.get('visited_blogs') or ''
@@ -247,19 +208,19 @@ class WebsiteBlog(http.Controller):
             visited_ids.append(blog_post.id)
         next_post_id = blog_post_obj.search(cr, uid, [
             ('id', 'not in', visited_ids),
-            ], order='ranking desc', limit=1, context=context)
+        ], order='ranking desc', limit=1, context=context)
         next_post = next_post_id and blog_post_obj.browse(cr, uid, next_post_id[0], context=context) or False
+        print next_post
 
         values = {
-            'blog': blog,
-            'blogs': blogs,
             'tags': tags,
             'tag': tag,
+            'blog': blog,
             'blog_post': blog_post,
             'main_object': blog_post,
             'nav_list': self.nav_list(),
             'enable_editor': enable_editor,
-            'next_post' : next_post,
+            'next_post': next_post,
             'date': date_begin,
             'post_url': post_url,
             'blog_url': blog_url,
@@ -369,7 +330,7 @@ class WebsiteBlog(http.Controller):
     def discussion(self, post_id=0, discussion=None, count=False, **post):
         cr, uid, context = request.cr, request.uid, request.context
         mail_obj = request.registry.get('mail.message')
-        domain = [('res_id', '=', int(post_id)) ,('model','=','blog.post'), ('discussion', '=', discussion)]
+        domain = [('res_id', '=', int(post_id)) ,('model','=','blog.post'), ('discussion_key', '=', discussion)]
         #check current user belongs to website publisher group
         publish = request.registry['res.users'].has_group(cr, uid, 'base.group_website_publisher')
         if not publish:
@@ -379,13 +340,11 @@ class WebsiteBlog(http.Controller):
             return ids
         return self._get_discussion_detail(ids, publish, **post)
 
-    @http.route('/blogpsot/change_background', type='json', auth="public", website=True)
+    @http.route('/blogpost/change_background', type='json', auth="public", website=True)
     def change_bg(self, post_id=0, image=None, **post):
-        post_obj = request.registry.get('blog.post')
-        values = {'content_image' : image}
-
-        ids = post_obj.write(request.cr, request.uid, [int(post_id)], values, request.context)
-        return []
+        if not post_id:
+            return False
+        return request.registry['blog.post'].write(request.cr, request.uid, [int(post_id)], {'background_image': image}, request.context)
 
     @http.route('/blog/get_user/', type='json', auth="public", website=True)
     def get_user(self, **post):
index 6b924b1..784c7bd 100644 (file)
@@ -49,6 +49,7 @@ class BlogPost(osv.Model):
     _columns = {
         'name': fields.char('Title', required=True, translate=True),
         'subtitle': fields.char('Sub Title', translate=True),
+        'author_id': fields.many2one('res.partner', 'Author'),
         'background_image': fields.binary('Background Image'),
         'blog_id': fields.many2one(
             'blog.blog', 'Blog',
@@ -99,6 +100,7 @@ class BlogPost(osv.Model):
     _defaults = {
         'name': _('Blog Post Title'),
         'subtitle': _('Subtitle'),
+        'author_id': lambda self, cr, uid, ctx=None: self.pool['res.users'].browse(cr, uid, uid, context=ctx).partner_id.id,
     }
 
     def create_history(self, cr, uid, ids, vals, context=None):
index 81a4011..103b2be 100644 (file)
@@ -38,8 +38,8 @@
         },
         save : function() {
             var res = this._super();
-            if ($('.cover').length){
-                openerp.jsonRpc("/blogpsot/change_background", 'call', {
+            if ($('.cover').length) {
+                openerp.jsonRpc("/blogpost/change_background", 'call', {
                     'post_id' : $('#blog_post_name').attr('data-oe-id'),
                     'image' : $('.cover').css('background-image').replace(/url\(|\)|"|'/g,''),
                 });
index 38486e3..121e497 100644 (file)
@@ -89,8 +89,7 @@
     </t>
 </template>
 
-
-<!-- Blog Post Summary -->
+<!-- Blog Post List: Displaying a list of Blog Posts -->
 <template id="blog_post_short" name="Blog Posts">
     <t t-call="website_blog.index">
         <div class="oe_structure">
                 <div t-foreach="blog_posts" t-as="blog_post" class="mb32">
 
                   <img class="img-circle pull-right mt16"
-                    t-att-src="'/website/image?model=res.partner&amp;field=image_small&amp;id='+str(blog_post.create_uid.partner_id.id)"
+                    t-att-src="'/website/image?model=res.partner&amp;field=image_small&amp;id='+str(blog_post.author_id.id)"
                     style="width: 50px;"/>
 
                   <a t-attf-href="/blog/#{ slug(blog_post.blog_id) }/post/#{ slug(blog_post) }">
 
                   <div class="text-muted">
                       <h4
-                        t-field="blog_post.sub_title"
+                        t-field="blog_post.subtitle"
                         class="mb4 mt4"/>
-                      <p name='blog_post_data' class="mb0">
-
-                        <span t-field="blog_post.create_uid.partner_id.name"/>
+                    <div name='blog_post_data' class='mb0'>
+                         <span t-field="blog_post.author_id" style="display: inline-block;" t-field-options='{
+                                "widget": "contact",
+                                "fields": ["name"]
+                            }'/>
                         &#5760; <span t-field="blog_post.create_date" t-field-options='{"format": "MMMM yyyy"}'/>
                         <span t-if="len(blog_post.message_ids) &gt; 0">
                             &#5760; <t t-esc="len(blog_post.message_ids)"/>
                         </span>
 
                         <span t-if="not blog_post.website_published" class="label label-danger">not published</span>
-                      </p>
+                    </div>
                   </div>
 
                 </div>
     </t>
 </template>
 
-<!-- Option: Blog Post Summary: show tags -->
+<!-- Option: Blog Post List: show tags -->
 <template id="opt_blog_post_short_tags" name="Tags"
         inherit_option_id="website_blog.blog_post_short" inherit_id="website_blog.blog_post_short">
-    <xpath expr="//p[@name='blog_post_data']" position="after">
+    <xpath expr="//div[@name='blog_post_data']" position="inside">
         <p class="post-meta text-muted text-center" t-if="len(blog_post.tag_ids)">
             <span class="fa fa-tags"/>
             <t t-foreach="blog_post.tag_ids" t-as="tag">
 <template id="blog_post_complete" name="Blog Post">
   <t t-call="website_blog.index">
 
-    <div class="cover js_fullheight" id="title" t-attf-style="background-image: url(#{blog_post.content_image})" t-ignore="True">
+    <div class="cover js_fullheight" id="title" t-attf-style="background-image: url(#{blog_post.background_image})" t-ignore="True">
         <div class="container">
           <div class="container text-right mt16">
             <div class="btn-group css_non_editable_mode_hidden">
         </div>
         <div class="blog_title">
             <h1 t-field="blog_post.name" id="blog_post_name" t-att-data-blog-id="blog_post.id"/>
-            <h2 t-field="blog_post.sub_title"/>
+            <h2 t-field="blog_post.subtitle"/>
             <p class="post-meta text-muted text-center" name="blog_post_data"/>
             <div>
-                <img class="img-circle" t-att-src="'/website/image?model=res.partner&amp;field=image_small&amp;id='+str(blog_post.create_uid.partner_id.id)" style="width: 30px; margin-right: 10px;"/>
-                <small id="blog_author" t-field="blog_post.create_uid.partner_id.name"/><br/>
+                <img class="img-circle" t-att-src="'/website/image?model=res.partner&amp;field=image_small&amp;id='+str(blog_post.author_id.id)" style="width: 30px; margin-right: 10px;"/>
+                <span t-field="blog_post.author_id" style="display: inline-block;" t-field-options='{
+                    "widget": "contact",
+                    "fields": ["name"]
+                }'/>
             </div>
-            <div t-if="blog_post.content_image" id="blog_angle_down">
+            <div t-if="blog_post.background_image" id="blog_angle_down">
                 <strong><a href="#blog_content" class="fa fa-angle-down fa-3x fa-inverse mt32"/></strong>
             </div>
         </div>
                     <t t-call="website.publish_short">
                         <t t-set="object" t-value="message"/>
                     </t>
-                    <strong t-field="message.author_id"/> <span class="text-muted">on <span t-field="message.date"/></span>
+                    <!-- <strong t-field="message.author_id"/> -->
+                    <span t-field="message.author_id" style="display: inline-block;" t-field-options='{
+                            "widget": "contact",
+                            "fields": ["name"]
+                        }'/>
+                    <span class="text-muted">on <span t-field="message.date"/></span>
                     <div t-field="message.body"/>
                 </div>
             </li>
     </section>
 
     <t t-if="next_post">
-        <div class="cover cover_footer mb0 text-center" t-attf-style="background-image: url(#{next_post.content_image})" t-ignore="True">
+        <div class="cover cover_footer mb0 text-center" t-attf-style="background-image: url(#{next_post.background_image})" t-ignore="True">
             <div class="blog_title">
                 <a class="hidden js_next" t-attf-href="/blog/#{ slug(next_post.blog_id) }/post/#{ slug(next_post) }/#wrap"/>
                 <h1 t-field="next_post.name"/>
-                <h2 t-field="next_post.sub_title"/>
+                <h2 t-field="next_post.subtitle"/>
                 <div>
-                    <img class="img-circle" t-att-src="'/website/image?model=res.partner&amp;field=image_small&amp;id='+str(next_post.create_uid.partner_id.id)" style="width: 30px; margin-right: 10px;"/>
-                    <small id="blog_author" t-field="next_post.create_uid.partner_id.name"/>
+                    <img class="img-circle" t-att-src="'/website/image?model=res.partner&amp;field=image_small&amp;id='+str(next_post.author_id.id)" style="width: 30px; margin-right: 10px;"/>
+                    <span t-field="next_post.author_id" style="display: inline-block;" t-field-options='{
+                            "widget": "contact",
+                            "fields": ["name"]
+                        }'/>
                 </div>
                 <p class="mt32">Read Next <span class="fa fa-long-arrow-right"/></p>
             </div>
   </t>
 </template>
 
+<!-- Options: Blog Post: breadcrumb -->
 <template id="blog_breadcrumb" name="Breadcrumb"
         inherit_option_id="website_blog.blog_post_complete">
     <xpath expr="//div[@id='title']" position="before">
index 52528dc..a3a359a 100644 (file)
@@ -56,9 +56,9 @@
                     <sheet>
                         <h1><field name="name" placeholder="Name"/></h1>
                         <field name="tag_ids" widget="many2many_tags"/>
-                        <field name="sub_title" placeholder="Blog Subtitle"/>
+                        <field name="subtitle" placeholder="Blog Subtitle"/>
                         <group>
-                            <field name="content_image"/>
+                            <field name="background_image"/>
                             <field name="blog_id"/>
                         </group>
                         <group>