[IMP] improved code to show url instead of id use slug.

bzr revid: tpa@tinyerp.com-20140304125350-zib1hxzvq1lr9bky
This commit is contained in:
Turkesh Patel (Open ERP) 2014-03-04 18:23:50 +05:30
parent 5471b1ba96
commit 09c005df51
2 changed files with 28 additions and 27 deletions

View File

@ -31,6 +31,7 @@ from openerp.addons.web.http import request
from dateutil.relativedelta import relativedelta
from openerp.addons.website.controllers.main import Website as controllers
from openerp.addons.website.models.website import slug
controllers = controllers()
@ -88,7 +89,7 @@ class website_forum(http.Controller):
step = 10
question_count = forum_obj.search(cr, uid, domain, count=True, context=context)
pager = request.website.pager(url="/forum/%s/" % forum.id, total=question_count, page=page, step=step, scope=10)
pager = request.website.pager(url="/forum/%s/" % slug(forum), total=question_count, page=page, step=step, scope=10)
obj_ids = forum_obj.search(cr, uid, domain, limit=step, offset=pager['offset'], context=context)
question_ids = forum_obj.browse(cr, uid, obj_ids, context=context)
@ -168,7 +169,7 @@ class website_forum(http.Controller):
'state': 'active',
'active': True,
}, context=create_context)
return werkzeug.utils.redirect("/forum/%s/question/%s" % (forum.id,new_question_id))
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),new_question_id))
@http.route('/forum/<model("website.forum"):forum>/question/postanswer/', type='http', auth="user", multilang=True, methods=['POST'], website=True)
def post_answer(self, forum ,post_id, **question):
@ -185,7 +186,7 @@ class website_forum(http.Controller):
'state': 'active',
'active': True,
}, context=create_context)
return werkzeug.utils.redirect("/forum/%s/question/%s" % (forum.id,post_id))
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post_id))
@http.route(['/forum/<model("website.forum"):forum>/question/editanswer'], type='http', auth="user", website=True, multilang=True)
def edit_answer(self, forum, post_id, **kwargs):
@ -211,7 +212,7 @@ class website_forum(http.Controller):
new_question_id = request.registry['website.forum.post'].write( cr, uid, [answer_id], {
'content': post.get('answer_content'),
}, context=context)
return werkzeug.utils.redirect("/forum/%s/question/%s" % (forum.id,post.get('post_id')))
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.get('post_id')))
@http.route(['/forum/<model("website.forum"):forum>/tag/<model("website.forum.tag"):tag>'], type='http', auth="public", website=True, multilang=True)
def tag_questions(self, forum, tag, page=1, **kwargs):

View File

@ -46,17 +46,17 @@
</div>
<div style="margin-left: 95px;">
<div class="question-name">
<a t-attf-href="/forum/#{ forum.id }/question/#{ slug(question) }" t-field="question.name"/>
<a t-attf-href="/forum/#{ slug(forum) }/question/#{ slug(question) }" t-field="question.name"/>
</div>
<div class="text-muted">
by <a t-attf-href="/forum/#{ forum.id }/user/#{ question.create_uid.id }" t-field="question.create_uid"/>,
by <a t-attf-href="/forum/#{ slug(forum) }/user/#{ question.create_uid.id }" t-field="question.create_uid"/>,
on <span t-field="question.write_date"/>
<div t-if="len(question.vote_ids)">
<strong>with <span t-esc="len(question.vote_ids)"/> votes</strong>
</div>
</div>
<t t-foreach="question.tags" t-as="tag">
<a t-attf-href="/forum/#{ forum.id }/tag/#{ tag.id }" class="badge" t-field="tag.name"/>
<a t-attf-href="/forum/#{ slug(forum) }/tag/#{ tag.id }" class="badge" t-field="tag.name"/>
</t>
</div>
</div>
@ -87,19 +87,19 @@
<div class="collapse navbar-collapse" id="oe-help-navbar-collapse">
<ul class="nav navbar-nav">
<li>
<a t-attf-href="/forum/#{ forum.id }">Questions</a>
<a t-attf-href="/forum/#{ slug(forum) }">Questions</a>
</li>
<li t-att-class="searches.get('users') and 'active' or '' ">
<a t-attf-href="/forum/#{ forum.id }/users">People</a>
<a t-attf-href="/forum/#{ slug(forum) }/users">People</a>
</li>
<li t-att-class="searches.get('tags') and 'active' or '' ">
<a t-attf-href="/forum/#{ forum.id }/tags">Tags</a>
<a t-attf-href="/forum/#{ slug(forum) }/tags">Tags</a>
</li>
<li t-att-class="searches.get('badge') and 'active' or '' ">
<a t-attf-href="/forum/#{ forum.id }/badge">Badges</a>
<a t-attf-href="/forum/#{ slug(forum) }/badge">Badges</a>
</li>
</ul>
<form class="navbar-form navbar-right" role="search" t-attf-action="/forum/#{ forum.id }" method="get">
<form class="navbar-form navbar-right" role="search" t-attf-action="/forum/#{ slug(forum) }" method="get">
<div class="form-group">
<input type="search" class="form-control"
name="search" placeholder="Search a question..."
@ -117,11 +117,11 @@
<div class="alert alert-success alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&amp;times;</button>
<strong>Congratulation!</strong> You received the <em>New Author</em> badge!<br/>
<a t-attf-href="/forum/#{ forum.id }/badge" class="fa fa-arrow-right">View Your Badges</a>
<a t-attf-href="/forum/#{ slug(forum) }/badge" class="fa fa-arrow-right">View Your Badges</a>
</div>
<t t-raw="0"/>
</div><div class="col-sm-3" id="right-column">
<a class="btn btn-primary btn-lg btn-block mb16" t-attf-href="/forum/#{ forum.id }/ask">Ask a Question</a>
<a class="btn btn-primary btn-lg btn-block mb16" t-attf-href="/forum/#{ slug(forum) }/ask">Ask a Question</a>
<div class="panel panel-default">
<div class="panel-heading">
@ -130,7 +130,7 @@
<div class="panel-body">
This community is for professional and enthusiast about our
products and services.<br/>
<a t-attf-href="/forum/#{ forum.id }/faq" class="fa fa-arrow-right"> Read Guidelines</a>
<a t-attf-href="/forum/#{ slug(forum) }/faq" class="fa fa-arrow-right"> Read Guidelines</a>
</div>
</div>
@ -153,7 +153,7 @@
<t t-call="website.layout">
<!--TODO: Improve template -->
<t t-foreach="forum_ids" t-as="forum">
<a t-attf-href="/forum/#{ forum.id }" class="box oe_green" t-field="forum.name"/>
<a t-attf-href="/forum/#{ slug(forum) }" class="box oe_green" t-field="forum.name"/>
</t>
<!--t t-call="website_forum.faq">
<div t-field="forum.faq"/>
@ -165,10 +165,10 @@
<t t-call="website.layout">
<!--TODO: Improve template -->
<div class="row">
<h1 class="text-center" t-attf-href="/forum/#{ forum.id }" t-field="forum.name"/>
<h1 class="text-center" t-attf-href="/forum/#{ slug(forum) }" t-field="forum.name"/>
</div>
<div class="row">
<h1 class="text-center" t-attf-href="/forum/#{ forum.id }/faq" t-field="forum.faq"/>
<h1 class="text-center" t-attf-href="/forum/#{ slug(forum) }/faq" t-field="forum.faq"/>
</div>
</t>
</template>
@ -188,13 +188,13 @@
<ul class="dropdown-menu">
<li class="dropdown-header">Filter on</li>
<li t-att-class="searches.get('type') == 'all' and 'active' or '' ">
<a t-attf-href="/forum/#{ forum.id }/?{{ keep_query( type='all') }}">All</a>
<a t-attf-href="/forum/#{ slug(forum) }/?{{ keep_query( type='all') }}">All</a>
</li>
<li t-att-class="searches.get('type') == 'unanswered' and 'active' or '' ">
<a t-attf-href="/forum/#{ forum.id }/?{{ keep_query( type='unanswered') }}">Unanswered</a>
<a t-attf-href="/forum/#{ slug(forum) }/?{{ keep_query( type='unanswered') }}">Unanswered</a>
</li>
<li t-att-class="searches.get('type') == 'followed' and 'active' or '' ">
<a t-attf-href="/forum/#{ forum.id }/?{{ keep_query( type='followed') }}">Followed</a>
<a t-attf-href="/forum/#{ slug(forum) }/?{{ keep_query( type='followed') }}">Followed</a>
</li>
<li class="dropdown-header">Sort by</li>
<li>
@ -231,7 +231,7 @@
<div>
<span t-field="user.image" t-field-options='{"widget": "image", "class":"pull-left img img-circle img-avatar"}' />
<div>
<a t-attf-href="/forum/#{ forum.id }/user/#{ slug(user) }" t-field="user.name"/>
<a t-attf-href="/forum/#{ slug(forum) }/user/#{ slug(user) }" t-field="user.name"/>
<t t-raw="separator or ', '"/>
<b>11 badges:</b>
<span class="fa fa-certificate badge-gold"></span>
@ -263,7 +263,7 @@
</li>
</ul>
<form t-attf-action="/forum/#{ forum.id }/question/ask/" method="post" role="form">
<form t-attf-action="/forum/#{ slug(forum) }/question/ask/" method="post" role="form">
<div class="col-xs-12">
<input type="text" name="question_name" required="True"
t-attf-value="#{question_name or ''}" id="textbox_user_question"
@ -319,7 +319,7 @@
</div>
</div>
<div class="row">
<form t-attf-action="/forum/#{ forum.id }/question/postanswer/" method="post" role="form">
<form t-attf-action="/forum/#{ slug(forum) }/question/postanswer/" method="post" role="form">
<div class="col-xs-12">
<div class="row">
<div class="col-xs-12">
@ -352,7 +352,7 @@
<h3>Edit answer</h3>
</div>
<div class="row">
<form t-attf-action="/forum/#{ forum.id }/question/saveanswer/" method="post" role="form">
<form t-attf-action="/forum/#{ slug(forum) }/question/saveanswer/" method="post" role="form">
<div >
<div class="row">
<div class="col-xs-12">
@ -403,7 +403,7 @@
<div class="mt16 clearfix">
<div class="pull-right">
<t t-foreach="question.tags" t-as="tag">
<a t-attf-href="/forum/#{ forum.id }/tag/#{ tag.id }" class="badge" t-field="tag.name"/>
<a t-attf-href="/forum/#{ slug(forum) }/tag/#{ tag.id }" class="badge" t-field="tag.name"/>
</t>
</div>
<t t-set="user" t-value="question.create_uid"/>
@ -467,7 +467,7 @@
</h1>
<div class="row">
<div class="col-sm-3 mt16" t-foreach="tags" t-as="tag">
<a t-attf-href="/forum/#{ forum.id }/tag/#{ slug(tag) }" class="badge">
<a t-attf-href="/forum/#{ slug(forum) }/tag/#{ slug(tag) }" class="badge">
<span t-field="tag.name" />
</a>
<span>