[MERGE] : with trunk and resolve conflicts

bzr revid: aja@tinyerp.com-20140401132534-owbxvwqo6qpodw7e
This commit is contained in:
ajay javiya (OpenERP) 2014-04-01 18:55:34 +05:30
commit 7126bc5b50
3 changed files with 213 additions and 54 deletions

View File

@ -592,8 +592,57 @@
<link rel='stylesheet' href='/website/static/src/css/website.css'/>
<script type="text/javascript" src="/web/static/lib/jquery/jquery.js"></script>
<script type="text/javascript" src="/web/static/lib/bootstrap/js/bootstrap.js"></script>
<script>
$(document).ready(function() {
var button = $('#reset_templates_button');
button.click(function() {
var dialog = $('#reset_template_confirmation').modal('show');
var input = dialog.find('input[type="text"]').val('').focus();
var dialog_form = dialog.find('form');
dialog_form.submit(function() {
if (input.val() == dialog.find('.confirm_word').text()) {
dialog.modal('hide');
button.prop('disabled', true).text('Working...');
$('#reset_templates_form').trigger('submit');
} else {
input.val('').focus();
}
return false;
});
return false;
});
});
</script>
</head>
<body>
<div id="reset_template_confirmation" class="modal" tabindex="-1" role="dialog" aria-hidden="true" t-ignore="true">
<div class="modal-dialog">
<form class="form-horizontal" role="form">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 class="modal-title">Reset templates</h3>
</div>
<div class="modal-body">
<div class="form-group mb0">
<label for="page-name" class="col-sm-9">
<p>The selected templates will be reset to their factory settings.</p>
<p>Type '<i class="confirm_word">yes</i>' in the box below if you want to confirm.</p>
</label>
<div class="col-sm-3 mt16">
<input type="text" class="form-control" required="required" placeholder="yes"/>
</div>
</div>
</div>
<div class="modal-footer">
<input type="submit" value="Confirm" class="btn btn-primary"/>
<button type="button" class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
</div>
</div>
</form>
</div>
</div>
<div id="wrapwrap">
<div class="navbar navbar-default navbar-static-top">
<div class="container">
@ -615,7 +664,7 @@
<h4>Template fallback</h4>
<p>An error occured while rendering the template <code t-esc="qweb_exception.qweb['template']"/>.</p>
<p>If this error is caused by a change of yours in the templates, you have the possibility to reset one or more templates to their <strong>factory settings</strong>.</p>
<form action="/website/reset_templates" method="post">
<form action="/website/reset_templates" method="post" id="reset_templates_form">
<ul class="oe_template_fallback">
<li t-foreach="views" t-as="view">
<label>
@ -625,7 +674,7 @@
</li>
</ul>
<input type="hidden" name="redirect" t-att-value="request.httprequest.path"/>
<input type="submit" value="Reset selected templates"/>
<button id="reset_templates_button">Reset selected templates</button>
</form>
</div>
</div>

View File

@ -19,14 +19,49 @@
#
##############################################################################
import datetime
import werkzeug
from openerp import tools
from openerp.addons.web import http
from openerp.addons.web.http import request
from openerp.addons.website.models.website import slug
from openerp.osv.orm import browse_record
from openerp.tools.translate import _
from openerp import SUPERUSER_ID
from openerp.tools import html2plaintext
class QueryURL(object):
def __init__(self, path='', path_args=None, **args):
self.path = path
self.args = args
self.path_args = set(path_args or [])
def __call__(self, path=None, path_args=None, **kw):
path = path or self.path
for k, v in self.args.items():
kw.setdefault(k, v)
path_args = set(path_args or []).union(self.path_args)
paths, fragments = [], []
for key, value in kw.items():
if value and key in path_args:
if isinstance(value, browse_record):
paths.append((key, slug(value)))
else:
paths.append((key, value))
elif value:
if isinstance(value, list) or isinstance(value, set):
fragments.append(werkzeug.url_encode([(key, item) for item in value]))
else:
fragments.append(werkzeug.url_encode([(key, value)]))
for key, value in paths:
path += '/' + key + '/%s' % value
if fragments:
path += '?' + '&'.join(fragments)
return path
class WebsiteBlog(http.Controller):
_blog_post_per_page = 20
_post_comment_per_page = 10
@ -36,14 +71,17 @@ class WebsiteBlog(http.Controller):
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:
group['date'] = "%s_%s" % (group['__domain'][0][2], group['__domain'][1][2])
begin_date = datetime.datetime.strptime(group['__domain'][0][2], tools.DEFAULT_SERVER_DATETIME_FORMAT).date()
end_date = datetime.datetime.strptime(group['__domain'][1][2], tools.DEFAULT_SERVER_DATETIME_FORMAT).date()
group['date_begin'] = '%s' % datetime.date.strftime(begin_date, tools.DEFAULT_SERVER_DATE_FORMAT)
group['date_end'] = '%s' % datetime.date.strftime(end_date, tools.DEFAULT_SERVER_DATE_FORMAT)
return groups
@http.route([
'/blog',
'/blog/page/<int:page>',
], type='http', auth="public", website=True, multilang=True)
def blogs(self, page=1):
def blogs(self, page=1, **post):
cr, uid, context = request.cr, request.uid, request.context
blog_obj = request.registry['blog.post']
total = blog_obj.search(cr, uid, [], count=True, context=context)
@ -53,11 +91,13 @@ class WebsiteBlog(http.Controller):
page=page,
step=self._blog_post_per_page,
)
bids = blog_obj.search(cr, uid, [], offset=pager['offset'], limit=self._blog_post_per_page, context=context)
blogs = blog_obj.browse(cr, uid, bids, context=context)
post_ids = blog_obj.search(cr, uid, [], offset=(page-1)*self._blog_post_per_page, limit=self._blog_post_per_page, context=context)
posts = blog_obj.browse(cr, uid, post_ids, context=context)
blog_url = QueryURL('', ['blog', 'tag'])
return request.website.render("website_blog.latest_blogs", {
'blogs': blogs,
'pager': pager
'posts': posts,
'pager': pager,
'blog_url': blog_url,
})
@http.route([
@ -66,7 +106,7 @@ class WebsiteBlog(http.Controller):
'/blog/<model("blog.blog"):blog>/tag/<model("blog.tag"):tag>',
'/blog/<model("blog.blog"):blog>/tag/<model("blog.tag"):tag>/page/<int:page>',
], type='http', auth="public", website=True, multilang=True)
def blog(self, blog=None, tag=None, date=None, page=1, **opt):
def blog(self, blog=None, tag=None, page=1, **opt):
""" Prepare all values to display the blog.
:param blog: blog currently browsed.
@ -85,6 +125,8 @@ class WebsiteBlog(http.Controller):
- 'tag': current tag, if tag_id
- 'nav_list': a dict [year][month] for archives navigation
"""
date_begin, date_end = opt.get('date_begin'), opt.get('date_end')
cr, uid, context = request.cr, request.uid, request.context
blog_post_obj = request.registry['blog.post']
@ -92,29 +134,30 @@ class WebsiteBlog(http.Controller):
blog_ids = blog_obj.search(cr, uid, [], order="create_date asc", context=context)
blogs = blog_obj.browse(cr, uid, blog_ids, context=context)
path_filter = ""
domain = []
if blog:
path_filter += "%s" % blog.id
domain += [("blog_id", "in", [blog.id])]
domain += [('blog_id', '=', blog.id)]
if tag:
path_filter += 'tag/%s' % tag.id
domain += [("tag_ids", "in", [tag.id])]
if date:
path_filter += "date/%s" % date
domain += [("create_date", ">=", date.split("_")[0]), ("create_date", "<=", date.split("_")[1])]
domain += [('tag_ids', 'in', tag.id)]
if date_begin and date_end:
domain += [("create_date", ">=", date_begin), ("create_date", "<=", date_end)]
blog_url = QueryURL('', ['blog', 'tag'], blog=blog, tag=tag, date_begin=date_begin, date_end=date_end)
post_url = QueryURL('', ['blogpost'], tag_id=tag and tag.id or None, date_begin=date_begin, date_end=date_end)
blog_post_count = blog_post_obj.search(cr, uid, domain, count=True, context=context)
pager = request.website.pager(
url="/blog/%s" % path_filter,
total=blog_post_count,
page=page,
step=self._blog_post_per_page,
scope=10
)
blog_post_ids = blog_post_obj.search(cr, uid, domain, order="create_date asc", context=context)
blog_posts = blog_post_obj.browse(cr, uid, blog_post_ids, context=context)
pager = request.website.pager(
url=blog_url(),
total=len(blog_posts),
page=page,
step=self._blog_post_per_page,
)
pager_begin = (page - 1) * self._blog_post_per_page
pager_end = page * self._blog_post_per_page
blog_posts = blog_posts[pager_begin:pager_end]
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)
@ -127,8 +170,9 @@ class WebsiteBlog(http.Controller):
'blog_posts': blog_posts,
'pager': pager,
'nav_list': self.nav_list(),
'path_filter': path_filter,
'date': date,
'blog_url': blog_url,
'post_url': post_url,
'date': date_begin,
}
response = request.website.render("website_blog.blog_post_short", values)
return response
@ -136,7 +180,7 @@ class WebsiteBlog(http.Controller):
@http.route([
'/blog/<model("blog.blog"):blog>/post/<model("blog.post"):blog_post>',
], type='http', auth="public", website=True, multilang=True)
def blog_post(self, blog, blog_post, enable_editor=None, **post):
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
@ -161,11 +205,40 @@ class WebsiteBlog(http.Controller):
- 'nav_list': a dict [year][month] for archives navigation
- 'next_blog': next blog post , display in footer
"""
date_begin, date_end = post.get('date_begin'), post.get('date_end')
pager_url = "/blogpost/%s" % blog_post.id
pager = request.website.pager(
url=pager_url,
total=len(blog_post.website_message_ids),
page=page,
step=self._post_comment_per_page,
scope=7
)
pager_begin = (page - 1) * self._post_comment_per_page
pager_end = page * self._post_comment_per_page
blog_post.website_message_ids = blog_post.website_message_ids[pager_begin:pager_end]
tag = None
if tag_id:
tag = request.registry['blog.tag'].browse(request.cr, request.uid, int(tag_id), context=request.context)
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:
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)
# Find next Post
visited_blogs = request.httprequest.cookies.get('visited_blogs') or ''
visited_ids = filter(None, visited_blogs.split(','))
@ -179,10 +252,17 @@ class WebsiteBlog(http.Controller):
values = {
'blog': blog,
'blogs': blogs,
'tags': tags,
'tag': tag,
'blog_post': blog_post,
'main_object': blog_post,
'nav_list': self.nav_list(),
'enable_editor': enable_editor,
'next_post' : next_post,
'date': date_begin,
'post_url': post_url,
'blog_url': blog_url,
}
response = request.website.render("website_blog.blog_post_complete", values)
response.set_cookie('visited_blogs', ','.join(map(str, visited_ids)))

View File

@ -36,44 +36,48 @@
<t t-set="classname">pull-right</t>
</t>
</section>
<section class="container">
<h1 class="text-center">Latest Blogs</h1>
<section data-snippet-id="title" class="container">
<div class="row">
<div class="col-md-12 text-center">
<h1>Latest Posts</h1>
</div>
</div>
</section>
<section class="container">
<div class="row">
<t t-set="count" t-value="0"/>
<t t-foreach="blogs" t-as="blog">
<t t-foreach="posts" t-as="post">
<div class="col-md-4">
<h4>
<a t-attf-href="/blog/#{ slug(blog.blog_id) }/post/#{ slug(blog) }?#{ tag and 'tag=%s' % tag.id or '' }#{tag and date and '&amp;' or ''}#{ date and 'date=%s' % date or ''}" t-field="blog.name"></a>
<span t-if="not blog.website_published" class="text-warning">
<a t-attf-href="#{blog_url('', ['blogpost'], blogpost=post)}" t-field="post.name"></a>
<span t-if="not post.website_published" class="text-warning">
&amp;nbsp;
<span class="fa fa-warning" title="Not published"/>
</span>
</h4>
<div class="text-muted">
<span class="fa fa-calendar"> <span t-field="blog.create_date"/> &amp;nbsp;</span>
<span class="fa fa-calendar"> <span t-field="post.create_date"/> &amp;nbsp;</span>
<span class="fa fa-folder-open"> In
<a t-attf-href="/blog/#{ slug(blog.blog_id) }">
<span t-field="blog.blog_id"/>
<a t-attf-href="#{blog_url(blog=post.blog_id)}">
<span t-field="post.blog_id"/>
</a> &amp;nbsp;
</span>
</div>
<div class="text-muted fa fa-tags">
<span t-field="blog.website_meta_keywords"/>
<span t-if="editable and not blog.website_meta_keywords" class="label label-danger">
<span t-field="post.website_meta_keywords"/>
<span t-if="editable and not post.website_meta_keywords" class="label label-danger">
No keywords defined!
</span>
</div>
<div class="text-muted" t-if="len(blog.message_ids) &gt; 0">
<div class="text-muted" t-if="len(post.message_ids) &gt; 0">
<span class="fa fa-comment-o">
<a t-attf-href="/blog/#{ slug(blog.blog_id) }/post/#{ slug(blog) }/?#{ tag and 'tag=%s' % tag.id or '' }#{tag and date and '&amp;' or ''}#{ date and 'date=%s' % date or ''}#comments">
<t t-if="len(blog.message_ids) &lt;= 1" ><t t-esc="len(blog.message_ids)"/> comment</t>
<t t-if="len(blog.message_ids) > 1"><t t-esc="len(blog.message_ids)"/> comments</t>
<a t-attf-href="#{blog_url('', ['blogpost'], blogpost=post)}#comments">
<t t-if="len(post.message_ids) &lt;= 1" ><t t-esc="len(post.message_ids)"/> comment</t>
<t t-if="len(post.message_ids) > 1"><t t-esc="len(post.message_ids)"/> comments</t>
</a>
</span>
</div>
<div class="text-muted mb16" t-field="blog.website_meta_description"/>
<div class="text-muted mb16" t-field="post.website_meta_description"/>
</div>
<t t-set="count" t-value="count+1"/>
<div class="clearfix" t-if="(count % 3) == 0"/>
@ -154,6 +158,19 @@
</t>
</template>
<!-- Option: Blog Post Summary: 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">
<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">
<a t-attf-href="#{blog_url(tag=tag)}" t-esc="tag.name"/> &amp;nbsp;
</t>
</p>
</xpath>
</template>
<!-- Blog Post Complete -->
<template id="blog_post_complete" name="Blog Post">
<t t-call="website_blog.index">
@ -184,6 +201,7 @@
<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"/>
<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/>
@ -196,7 +214,7 @@
<div id="blog_content" t-field="blog_post.content" class="mt32"/>
<section id="comments" class="read_width" t-if="blog_post.website_message_ids">
<section id="comments" class="read_width">
<hr/>
<ul class="media-list" id="comments-list">
<li t-foreach="blog_post.website_message_ids" t-as="message" class="media">
@ -239,10 +257,9 @@
<div class="row">
<div class="col-sm-9">
<ol class="breadcrumb">
<li><a t-attf-href="/blog/#{ slug(blog) }"><span t-field="blog.name"/></a></li>
<li t-if="tag"><a t-attf-href="/blog/#{ slug(blog) }/tag/#{ slug(tag) }"><span t-field="tag.name"/></a></li>
<li t-if="tag and date"><a t-attf-href="/blog/#{ slug(blog) }/tag/#{ slug(tag) }/date/#{ date }" t-esc="date_name"/></li>
<li t-if="not tag and date"><a t-attf-href="/blog/#{ slug(blog) }/date/#{ date }" t-esc="date_name"/></li>
<li><a t-attf-href="#{blog_url(tag=None, date_begin=None, date_end=None)}"><span t-field="blog.name"/></a></li>
<li t-if="tag"><a t-attf-href="#{blog_url(date_begin=None, date_end=None)}"><span t-field="tag.name"/></a></li>
<li t-if="date"><a t-attf-href="#{blog_url(tag=None)}" t-esc="date"/></li>
<li class="active"><span t-field="blog_post.name"/></li>
</ol>
</div><div class="col-sm-3">
@ -293,6 +310,19 @@
</xpath>
</template>
<!-- Options: Blog Post: show tags -->
<template id="opt_blog_post_complete_tags" name="Tags"
inherit_option_id="website_blog.blog_post_complete" inherit_id="website_blog.blog_post_complete">
<xpath expr="//p[@name='blog_post_data']" position="after">
<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">
<a t-attf-href="#{blog_url(tag=tag)}" t-esc="tag.name"/> &amp;nbsp;
</t>
</p>
</xpath>
</template>
<!-- Page -->
<template id="index" name="Blog Navigation">
<t t-call="website.layout">
@ -327,9 +357,9 @@
<section class="mt32">
<h4>Tags</h4>
<ul class="nav nav-pills nav-stacked">
<t t-foreach="tags" t-as="tag_id">
<li t-att-class="tag and tag_id.id == tag.id and 'active' or None" style="display: inline-block;">
<a t-attf-href="/blog/#{ slug(blog) }/tag/#{ slug(tag_id) }"><span t-field="tag_id.name"/></a>
<t t-foreach="tags" t-as="nav_tag">
<li t-att-class="tag and tag.id == nav_tag.id and 'active' or None" style="display: inline-block;">
<a t-attf-href="#{blog_url(tag=nav_tag)}"><span t-field="nav_tag.name"/></a>
</li>
</t>
</ul>
@ -345,8 +375,8 @@
<h4>Archives</h4>
<ul class="nav nav-pills nav-stacked">
<t t-foreach="nav_list" t-as="months">
<li t-att-class="months['date'] == date and 'active' or None">
<a t-ignore="True" t-attf-href="/blog/#{ slug(blog) }/#{ tag and 'tag/%s/' % slug(tag) or '' }date/#{ months['date'] }"><t t-esc="months['create_date']"/><span class="pull-right badge" t-esc="months['create_date_count']"/></a>
<li t-att-class="months['date_begin'] == date and 'active' or None">
<a t-ignore="True" t-attf-href="#{blog_url(date_begin=months['date_begin'], date_end=months['date_end'])}"><t t-esc="months['create_date']"/><span class="pull-right badge" t-esc="months['create_date_count']"/></a>
</li>
</t>
</ul>
@ -407,7 +437,7 @@
<ul class="nav nav-pills nav-stacked">
<t t-foreach="blogs" t-as="nav_blog">
<li t-att-class="nav_blog.id == blog.id and 'active' or ''">
<a t-attf-href="/blog/#{ slug(nav_blog) }">
<a t-attf-href="#{blog_url(blog=nav_blog)}">
<span t-field="nav_blog.name"/>
</a>
</li>