[FIX] next pos algorythm

bzr revid: fp@tinyerp.com-20140223181205-u9xdiprgpov50pe1
This commit is contained in:
Fabien Pinckaers 2014-02-23 19:12:05 +01:00
parent 0f29d1951f
commit fcbd203ee0
4 changed files with 26 additions and 36 deletions

View File

@ -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'):

View File

@ -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 {

View File

@ -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

View File

@ -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>