[IMP] preprocess static @href|src|action, static url doesn't need t-href anymore

you need to pull server branch

bzr revid: fme@openerp.com-20131112144442-y9bw5q6kkoym8o1i
This commit is contained in:
Fabien Meghazi 2013-11-12 15:44:42 +01:00
parent b1b29acd4b
commit 557d887496
11 changed files with 61 additions and 58 deletions

View File

@ -21,6 +21,7 @@ from PIL import Image as I
from openerp.osv import orm, fields
from openerp.tools import ustr, DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
from openerp.addons.web.http import request
REMOTE_CONNECTION_TIMEOUT = 2.5
@ -32,6 +33,31 @@ class QWeb(orm.AbstractModel):
_name = 'website.qweb'
_inherit = 'ir.qweb'
URL_ATTRS = {
'form': 'action',
'a': 'href',
'link': 'href',
'frame': 'src',
'iframe': 'src',
'script': 'src',
}
def add_template(self, into, name, node, context):
# preprocessing for multilang static urls
if request and 'url_for' in context:
router = request.httprequest.app.get_db_router(request.db).bind('')
for tag, attr in self.URL_ATTRS.items():
for e in node.getElementsByTagName(tag):
url = e.getAttribute(attr)
if url:
try:
func = router.match(url)[0]
if func.multilang:
e.setAttribute(attr, context['url_for'](url))
except Exception, e:
pass
super(QWeb, self).add_template(into, name, node, context)
def get_converter_for(self, field_type):
return self.pool.get(
'website.qweb.field.' + field_type,

View File

@ -100,25 +100,6 @@ class view(osv.osv):
return arch
URL_ATTRS = {
'form': 'action',
'a': 'href',
'link': 'href',
'frame': 'src',
'iframe': 'src',
'script': 'src',
}
def _normalize_urls(self, root):
for element in root.iter():
attr = self.URL_ATTRS.get(element.tag)
if attr is None or attr not in element.attrib:
continue
value = element.get(attr)
if not urlparse(value).scheme:
element.attrib.pop(attr)
element.set('t-' + attr, value)
def save(self, cr, uid, res_id, value, xpath=None, context=None):
""" Update a view section. The view section may embed fields to write
@ -131,10 +112,6 @@ class view(osv.osv):
arch_section = html.fromstring(
value, parser=html.HTMLParser(encoding='utf-8'))
# TODO fme: Temporary desactivated because this breaks most of the snippets
# Need to find another way to normalize multilang urls (postprocessing) ?
# self._normalize_urls(arch_section)
if xpath is None:
# value is an embedded field on its own, not a view section
self.save_embedded_field(cr, uid, arch_section, context=context)

View File

@ -147,13 +147,13 @@
<div class="col-md-3" name="product">
<h4>Our products &amp; Services</h4>
<ul class="list-unstyled" name="products">
<li><a t-href="/">Home</a></li>
<li><a href="/">Home</a></li>
</ul>
</div>
<div class="col-md-3" name="info">
<h4 name="info_title">Connect with us</h4>
<ul class="list-unstyled">
<li><a t-href="/page/website.contactus">Contact us</a></li>
<li><a href="/page/website.contactus">Contact us</a></li>
</ul>
<ul class="list-unstyled">
<li><i class="icon-phone"></i> <span t-field="res_company.phone"></span></li>
@ -209,7 +209,7 @@
<a class="label label-danger" href="https://openerp.com/apps/website">OpenERP</a>
</div>
<div class="pull-left text-muted">
Copyright &amp;copy; <span t-field="res_company.name">Company name</span> - <a t-href="/sitemap">Sitemap</a>
Copyright &amp;copy; <span t-field="res_company.name">Company name</span> - <a href="/sitemap">Sitemap</a>
</div>
</div>
</footer>
@ -366,7 +366,7 @@
<div class="well mt32">
<p>This page does not exists, but you can create it as you are administrator of this site.</p>
<a class="btn btn-primary" t-att-href="'/pagenew/'+path">Create Page</a>
<span class="text-muted">or</span> <a t-href="/sitemap">Search a Page</a>
<span class="text-muted">or</span> <a href="/sitemap">Search a Page</a>
</div>
<div class="text-center text-muted">Edit the content bellow this line to adapt the default "page not found" page.</div>
</div>
@ -381,8 +381,8 @@
</p>
<p>Maybe you were looking for one of these popular pages ?</p>
<ul>
<li><a t-href="/">Homepage</a></li>
<li><a t-href="/page/website.contactus/">Contact Us</a></li>
<li><a href="/">Homepage</a></li>
<li><a href="/page/website.contactus/">Contact Us</a></li>
</ul>
</div>
</div>
@ -420,8 +420,8 @@
</p>
<pre t-if="editable" t-esc="error"/>
<ul>
<li><a t-href="/">Homepage</a></li>
<li><a t-href="/page/website.contactus/">Contact Us</a></li>
<li><a href="/">Homepage</a></li>
<li><a href="/page/website.contactus/">Contact Us</a></li>
</ul>
</div>
</div>

View File

@ -263,7 +263,7 @@
through your <b>blog entries</b>, referenced in Google.
</p>
<div>
<a t-href="/page/website.contactus"><button class="btn btn-primary">Contact us</button></a>
<a href="/page/website.contactus"><button class="btn btn-primary">Contact us</button></a>
</div>
</section>
</xpath>

View File

@ -4,7 +4,7 @@
<template id="contactus_form" name="Contact Form" inherit_id="website.contactus" inherit_option_id="website.contactus">
<xpath expr="//div[@name='mail_button']" position="replace">
<form t-action="/crm/contactus" method="post" class="form-horizontal mt32" >
<form action="/crm/contactus" method="post" class="form-horizontal mt32" >
<div t-attf-class="form-group #{error and 'contact_name' in error and 'has-error' or ''}">
<label class="col-md-3 col-sm-4 control-label" for="contact_name">Your Name</label>
<div class="col-md-7 col-sm-8">

View File

@ -6,7 +6,7 @@
<!-- Layout add nav and footer -->
<template id="footer_custom" inherit_id="website.layout" name="Footer Partners Link">
<xpath expr="//footer//div[@name='info']/ul" position="inside">
<li><a t-href="/partners/">Partners</a></li>
<li><a href="/partners/">Partners</a></li>
</xpath>
</template>
@ -52,7 +52,7 @@
<t t-call="website.pager">
<t t-set="classname">pull-left</t>
</t>
<form t-action="/partners/" method="get" class="navbar-search pull-right pagination form-inline">
<form action="/partners/" method="get" class="navbar-search pull-right pagination form-inline">
<div class="form-group">
<input type="text" name="search" class="search-query col-md-2 mt4 form-control" placeholder="Search" t-att-value="name_search"/>
</div>

View File

@ -5,7 +5,7 @@
<!-- Layout add nav and footer -->
<template id="footer_custom" inherit_id="website.layout" name="Footer Customer References Link">
<xpath expr="//footer//div[@name='info']/ul" position="inside">
<li><a t-href="/customers/">Customer References</a></li>
<li><a href="/customers/">Customer References</a></li>
</xpath>
</template>

View File

@ -5,7 +5,7 @@
<!-- Layout add nav and footer -->
<template id="header_footer_custom" inherit_id="website.layout" name="Footer Events Link">
<xpath expr="//footer//ul[@name='products']" position="inside">
<li><a t-href="/event">Events</a></li>
<li><a href="/event">Events</a></li>
</xpath>
</template>
@ -315,7 +315,7 @@
<li t-if="event_id.country_id">
<a t-href="/event?country=#{event_id.country_id.id}"><strong><span class="icon-double-angle-right"/> Other Events in <span t-esc="event_id.country_id.name"/></strong></a>
</li>
<li><a t-href="/event"><strong><span class="icon-double-angle-right"/> All Events</strong></a></li>
<li><a href="/event"><strong><span class="icon-double-angle-right"/> All Events</strong></a></li>
</ul>
</div>
</div>

View File

@ -9,7 +9,7 @@
<template id="job_footer_custom" inherit_id="website.layout" name="Footer Job Link">
<xpath expr="//footer//div[@name='info']/ul" position="inside">
<li><a t-href="/jobs">Jobs</a></li>
<li><a href="/jobs">Jobs</a></li>
</xpath>
</template>
@ -83,7 +83,7 @@
<div class="container">
<div class="row">
<div class="col-md-12 text-center mt16 mb16">
<a t-href="/job/apply" class="btn btn-primary btn-lg">Apply</a>
<a href="/job/apply" class="btn btn-primary btn-lg">Apply</a>
</div>
</div>
</div>
@ -102,7 +102,7 @@
<div class="row">
<div class="col-sm-5">
<ol class="breadcrumb mb0">
<li><a t-href="/jobs">Our Jobs</a></li>
<li><a href="/jobs">Our Jobs</a></li>
<li class="active"><span t-field="job.name"></span></li>
</ol>
</div><div class="col-sm-7">
@ -220,7 +220,7 @@
<div class="container">
<div class="row">
<div class="col-md-12 text-center mt16 mb16">
<a t-href="/" class="btn btn-primary btn-lg">Continue To Our Website</a>
<a href="/" class="btn btn-primary btn-lg">Continue To Our Website</a>
</div>
</div>
</div>
@ -233,7 +233,7 @@
<template id="job_departments" inherit_option_id="website_hr_recruitment.index" name="Filter on Departments">
<xpath expr="//div[@id='jobs_grid_left']" position="inside">
<ul class="nav nav-pills nav-stacked mb32">
<li t-att-class=" '' if active else 'active' "><a t-href="/jobs">All Departments</a></li>
<li t-att-class=" '' if active else 'active' "><a href="/jobs">All Departments</a></li>
<t t-foreach="departments" t-as="department">
<li t-att-class="department.id == active and 'active' or ''">
<a t-href="/jobs/department/#{ department.id }/" ><span t-field="department.name"/></a>
@ -249,7 +249,7 @@
<template id="job_offices" inherit_option_id="website_hr_recruitment.index" name="Filter on Offices">
<xpath expr="//div[@id='jobs_grid_left']" position="inside">
<ul class="nav nav-pills nav-stacked mb32">
<li t-att-class=" '' if office else 'active' "><a t-href="/jobs">All Offices</a></li>
<li t-att-class=" '' if office else 'active' "><a href="/jobs">All Offices</a></li>
<t t-foreach="offices" t-as="thisoffice">
<li t-att-class="thisoffice.id == office and 'active' or ''">
<a t-href="/jobs/office/#{ thisoffice.id }/" >

View File

@ -5,7 +5,7 @@
<!-- Layout add nav and footer -->
<template id="footer_custom" inherit_id="website.layout" name="Footer Associations Link">
<xpath expr="//footer//div[@name='info']/ul" position="inside">
<li><a t-href="/members/">Associations</a></li>
<li><a href="/members/">Associations</a></li>
</xpath>
</template>
@ -35,7 +35,7 @@
<div class="col-md-4" id="left_column">
<ul class="nav nav-pills nav-stacked mt16">
<li class="nav-header"><h3>Associations</h3></li>
<li t-att-class="membership and '' or 'active'"><a t-href="/members/">All</a></li>
<li t-att-class="membership and '' or 'active'"><a href="/members/">All</a></li>
<t t-foreach="memberships" t-as="membership_id">
<li t-att-class="membership and membership_id.id == membership.id and 'active' or ''">
<a t-href="/members/association/#{ membership_id.id }"><t t-esc="membership_id.name"/></a>
@ -48,7 +48,7 @@
<t t-call="website.pager">
<t t-set="classname">pull-left</t>
</t>
<form t-action="/members/" method="get" class="navbar-search pull-right pagination form-inline">
<form action="/members/" method="get" class="navbar-search pull-right pagination form-inline">
<div class="form-group">
<input type="text" name="name" class="search-query col-md-2 mt4 form-control" placeholder="Search" t-att-value="post.get('name', '')"/>
</div>

View File

@ -7,7 +7,7 @@
<template id="header" inherit_id="website.layout" name="Header Shop My Cart Link">
<xpath expr="//header//ul[@id='top_menu']/li" position="before">
<li t-att-class="(not website_sale_order or not website_sale_order.get_total_quantity()) and 'hidden' or ''">
<a t-href="/shop/mycart/">
<a href="/shop/mycart/">
<i class="icon-shopping-cart"></i>
My cart <sup t-attf-class="my_cart_quantity label label-primary"
t-esc="website_sale_order and website_sale_order.get_total_quantity() or ''"/>
@ -95,7 +95,7 @@
<t t-set="classname">pull-right</t>
<t t-set="style">padding-left: 5px;</t>
</t>
<form t-action="/shop/" method="get" class="pull-right pagination form-inline" style="padding-right: 5px;">
<form action="/shop/" method="get" class="pull-right pagination form-inline" style="padding-right: 5px;">
<t t-call="website_sale.search" />
</form>
</div>
@ -245,7 +245,7 @@
<div class="row">
<div class="col-sm-5">
<ol class="breadcrumb">
<li><a t-href="/shop">Products</a></li>
<li><a href="/shop">Products</a></li>
<li t-if="search.get('category')"><a t-href="/shop/" t-keep-query="category,search,facettes"><span t-field="category.name"/></a></li>
<li class="active"><span t-field="product.name"></span></li>
</ol>
@ -262,7 +262,7 @@
</li>
</t>
</div><div class="col-sm-3 col-sm-offset-1">
<form t-action="/shop/" method="get" class="pull-right">
<form action="/shop/" method="get" class="pull-right">
<t t-call="website_sale.search" />
</form>
</div>
@ -276,7 +276,7 @@
</div><div class="col-sm-5 col-md-5 col-lg-4 col-lg-offset-1">
<h1 t-field="product.name">Product Name</h1>
<form t-action="./add_cart/" class="js_add_cart_json">
<form action="./add_cart/" class="js_add_cart_json">
<input type="hidden" t-if="len(product.product_variant_ids) &lt;= 1" name="product_id" t-att-value="product.id"/>
<t t-if="len(product.product_variant_ids) &gt; 1">
<label label-default="label-default" class="radio" t-foreach="product.product_variant_ids" t-as="product">
@ -464,8 +464,8 @@
</thead>
</table>
<div class="clearfix"/>
<a t-href="/shop" class="btn btn-default mb32"><span class="icon-long-arrow-left"/> Continue Shopping</a>
<a t-if="website_sale_order and website_sale_order.order_line" t-href="/shop/checkout/" class="btn btn-primary pull-right mb32">Process Checkout <span class="icon-long-arrow-right"/></a>
<a href="/shop" class="btn btn-default mb32"><span class="icon-long-arrow-left"/> Continue Shopping</a>
<a t-if="website_sale_order and website_sale_order.order_line" href="/shop/checkout/" class="btn btn-primary pull-right mb32">Process Checkout <span class="icon-long-arrow-right"/></a>
<div class="oe_structure"/>
</div>
<div class="col-md-3 text-muted" id="right_column">
@ -493,7 +493,7 @@
<template id="products_categories" inherit_option_id="website_sale.products" name="Product Categories">
<xpath expr="//div[@id='products_grid_before']" position="inside">
<ul class="nav nav-pills nav-stacked mt16">
<li t-att-class=" '' if search.get('category') else 'active' "><a t-href="/shop/">All Products</a></li>
<li t-att-class=" '' if search.get('category') else 'active' "><a href="/shop/">All Products</a></li>
<t t-set="categ" t-value="Ecommerce.get_categories()"/>
<t t-foreach="categ[0]" t-as="category">
<t t-call="website_sale.categories_recursive"/>
@ -606,7 +606,7 @@
<p>
Have a coupon code? Fill in this field and apply.
</p>
<form t-if="website_sale_order and website_sale_order.order_line" t-action="/shop/mycart/" method="post" class="mb32">
<form t-if="website_sale_order and website_sale_order.order_line" action="/shop/mycart/" method="post" class="mb32">
<div class="input-group">
<input name="promo" class='form-control' type="text" placeholder="code..." t-att-value="website_sale_order.pricelist_id.code or ''"/>
<div class="input-group-btn">
@ -637,7 +637,7 @@
<li class="text-muted">Confirmation<span class="chevron"></span></li>
</ul>
<h1>Your Address</h1>
<form t-action="/shop/confirm_order/" method="post">
<form action="/shop/confirm_order/" method="post">
<div class="row">
<div class="col-md-8 oe_mycart">
@ -891,7 +891,7 @@
<t t-foreach="payments or []" t-as="payment">
<div t-att-data-id="payment.id" t-raw="payment._content" class="hidden"/>
</t>
<a t-href="/shop/payment_validate/" class="btn btn-primary mt16">Validate &amp; Pay <span class="icon-long-arrow-right"/></a>
<a href="/shop/payment_validate/" class="btn btn-primary mt16">Validate &amp; Pay <span class="icon-long-arrow-right"/></a>
</div>
</div>