summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorFabien Pinckaers <fp@tinyerp.com>2014-02-23 19:12:05 +0100
committerFabien Pinckaers <fp@tinyerp.com>2014-02-23 19:12:05 +0100
commitfcbd203ee004fe83de8db4cdc206302caeab3fec (patch)
tree7b8490b00bc7131f14a994df78fff68c57feaeb2 /addons
parent0f29d1951f9307075304c4551be57bfad52c7142 (diff)
[FIX] next pos algorythm
bzr revid: fp@tinyerp.com-20140223181205-u9xdiprgpov50pe1
Diffstat (limited to 'addons')
-rw-r--r--addons/website_blog/controllers/main.py34
-rw-r--r--addons/website_blog/static/src/css/website_blog.css4
-rw-r--r--addons/website_blog/static/src/css/website_blog.sass4
-rw-r--r--addons/website_blog/views/website_blog_templates.xml20
4 files changed, 26 insertions, 36 deletions
diff --git a/addons/website_blog/controllers/main.py b/addons/website_blog/controllers/main.py
index 1242a9d7cfe..9e20b85f486 100644
--- a/addons/website_blog/controllers/main.py
+++ b/addons/website_blog/controllers/main.py
@@ -150,22 +150,6 @@ class WebsiteBlog(http.Controller):
response.set_cookie('unvisited', json.dumps(blog_post_ids))
return response
- def get_next_post(self, cr, uid, blog_post, context):
- """ Get next blog post display in footer of current post """
- blog_post_obj = request.registry.get('blog.post')
- unvisited = eval(request.httprequest.cookies.get('unvisited'))
- if blog_post.id in unvisited:
- # if post is not visited yet return a random post
- unvisited.remove(blog_post.id)
- post_list = blog_post_obj.search(cr, uid, [('id', '!=', blog_post.id)],context=context)
- next_post_id = post_list[random.randint(0, (len(post_list)-1))]
- else:
- # if post is visited return a most visited(count) and post share same keywords
- post_list = blog_post_obj.search(cr, uid, [('id', '!=', blog_post.id),('website_meta_keywords', 'ilike', blog_post.website_meta_keywords)], order='visits',context=context)
- next_post_id = post_list and post_list[0] or (unvisited and unvisited[0] or False)
- next_post = next_post_id and blog_post_obj.browse(cr, uid, next_post_id, context=context) or False
- return (next_post,unvisited)
-
@http.route([
'/blogpost/<model("blog.post"):blog_post>/',
], type='http', auth="public", website=True, multilang=True)
@@ -222,12 +206,20 @@ class WebsiteBlog(http.Controller):
request.httprequest.session[blog_post.id] = True
counter = blog_post.visits + 1;
blog_post_obj.write(cr, SUPERUSER_ID, [blog_post.id], {'visits':counter},context=context)
-
+
MONTHS = [None, _('January'), _('February'), _('March'), _('April'),
_('May'), _('June'), _('July'), _('August'), _('September'),
_('October'), _('November'), _('December')]
-
- next_post, unvisited = self.get_next_post(cr, uid, blog_post, context)
+
+ # Find next Post
+ visited_blogs = request.httprequest.cookies.get('visited_blogs') or ''
+ visited_ids = map(lambda x: int(x or blog_post.id), visited_blogs.split(',')) + [blog_post.id]
+ if blog_post.id not in visited_ids:
+ visited_ids.append(blog_post.id)
+ next_post_id = blog_post_obj.search(cr, uid, [
+ ('id', 'not in', visited_ids),
+ ], order='visits 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
values = {
'blog': blog_post.blog_id,
@@ -244,9 +236,9 @@ class WebsiteBlog(http.Controller):
'next_post' : next_post,
}
response = request.website.render("website_blog.blog_post_complete", values)
- response.set_cookie('unvisited', json.dumps(unvisited))
+ response.set_cookie('visited_blogs', ','.join(map(str, visited_ids)))
return response
-
+
def _blog_post_message(self, blog_post_id=0, **post):
cr, uid, context = request.cr, request.uid, request.context
if post.get('comment'):
diff --git a/addons/website_blog/static/src/css/website_blog.css b/addons/website_blog/static/src/css/website_blog.css
index a63793aea1f..484540c9eae 100644
--- a/addons/website_blog/static/src/css/website_blog.css
+++ b/addons/website_blog/static/src/css/website_blog.css
@@ -46,6 +46,7 @@ p.post-meta {
.cover_footer {
color: white;
+ background-color: grey;
min-height: 200px;
height: 50vh;
padding-top: 5vh;
@@ -54,9 +55,6 @@ p.post-meta {
.cover_footer h1 {
font-weight: bold;
}
-.cover_footer h2.text-muted {
- color: white;
-}
/*Inline Discussion */
.discussion {
diff --git a/addons/website_blog/static/src/css/website_blog.sass b/addons/website_blog/static/src/css/website_blog.sass
index 63184125cb6..8022dc13f2a 100644
--- a/addons/website_blog/static/src/css/website_blog.sass
+++ b/addons/website_blog/static/src/css/website_blog.sass
@@ -1,5 +1,4 @@
@charset "utf-8"
-
@import "compass/css3"
.css_website_mail
@@ -40,14 +39,13 @@ p.post-meta
.cover_footer
color: white
+ background-color: grey
min-height : 200px
height: 50vh
padding-top: 5vh
cursor: pointer
h1
font-weight: bold
- h2.text-muted
- color: white
/*Inline Discussion
diff --git a/addons/website_blog/views/website_blog_templates.xml b/addons/website_blog/views/website_blog_templates.xml
index 342505f485a..c9728c4b48b 100644
--- a/addons/website_blog/views/website_blog_templates.xml
+++ b/addons/website_blog/views/website_blog_templates.xml
@@ -221,16 +221,18 @@
</ul>
</section>
- <div class="cover cover_footer mb0 text-center" t-attf-style="background-image: url(#{next_post.content_image})" t-if="next_post" t-ignore="True">
- <p>Read Next</p>
- <a class="hidden js_next" t-attf-href="/blogpost/#{ slug(next_post) }#wrap"/>
- <h1 t-field="next_post.name"/>
- <h2 t-field="next_post.sub_title"/>
- <div>
- <img class="img-circle" t-att-src="'/website/image?model=res.users&amp;field=image_small&amp;id='+str(next_post.create_uid.id)" style="width: 30px; margin-right: 10px;"/>
- <small id="blog_author" t-field="next_post.create_uid.name"/>
+ <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">
+ <p>Read Next</p>
+ <a class="hidden js_next" t-attf-href="/blogpost/#{ slug(next_post) }#wrap"/>
+ <h1 t-field="next_post.name"/>
+ <h2 t-field="next_post.sub_title"/>
+ <div>
+ <img class="img-circle" t-att-src="'/website/image?model=res.users&amp;field=image_small&amp;id='+str(next_post.create_uid.id)" style="width: 30px; margin-right: 10px;"/>
+ <small id="blog_author" t-field="next_post.create_uid.name"/>
+ </div>
</div>
- </div>
+ </t>
</t>
</template>