[IMP] Themes as a separate page, need to load all bootswatch themes when moving to BS3

bzr revid: fp@tinyerp.com-20130827095658-22jfyowv3bq3wfa1
This commit is contained in:
Fabien Pinckaers 2013-08-27 11:56:58 +02:00
parent 5ddbdeac96
commit 8f64dd7f65
5 changed files with 172 additions and 11 deletions

View File

@ -13,6 +13,7 @@ OpenERP Website CMS
'installable': True,
'data': [
'views/views.xml',
'views/themes.xml',
'views/res_config.xml',
'website_data.xml',
],

View File

@ -66,6 +66,26 @@ class Website(openerp.addons.web.controllers.main.Home):
})
return werkzeug.utils.redirect("/page/%s" % path)
@http.route('/website/theme_change', type='http', auth="admin")
def theme_change(self, theme_id=False, **kwargs):
imd = request.registry['ir.model.data']
view = request.registry['ir.ui.view']
view_model, view_option_id = imd.get_object_reference(request.cr, request.uid, 'website', 'theme')
views = view.search(request.cr, request.uid, [('inherit_id','=',view_option_id)])
view.write(request.cr, request.uid, views, {'inherit_id': False})
if theme_id:
module, xml_id = theme_id.split('.')
view_model, view_id = imd.get_object_reference(request.cr, request.uid, module, xml_id)
view.write(request.cr, request.uid, [view_id], {'inherit_id':view_option_id})
website = request.registry.get("website")
values = website.get_rendering_context({
'theme_changed': True
})
return website.render('website.themes', values)
@http.route('/page/<path:path>', type='http', auth="admin")
def page(self, path, **kwargs):
website = request.registry.get("website")
@ -83,25 +103,25 @@ class Website(openerp.addons.web.controllers.main.Home):
view_obj = request.registry.get("ir.ui.view")
view = view_obj.browse(request.cr, request.uid, int(view_id), context=request.context)
if view.inherit_id:
print '*', view.inherit_id
value = False
else:
value = view.inherit_option_id and view.inherit_option_id.id or False
print '*', view.inherit_id, 'no', value, view
view_obj.write(request.cr, request.uid, [view_id], {
'inherit_id': value
}, context=request.context)
print 'Wrote', value, 'on', view_id
return True
@http.route('/website/customize_template_get', type='json', auth='admin') # FIXME: auth
def customize_template_get(self, xml_id):
imd = request.registry['ir.model.data']
view_model, view_theme_id = imd.get_object_reference(request.cr, request.uid, 'website', 'theme')
view = request.registry.get("ir.ui.view")
views = view._views_get(request.cr, request.uid, xml_id, request.context)
done = {}
result = []
for v in views:
if v.inherit_option_id:
if v.inherit_option_id and v.inherit_option_id.id<>view_theme_id:
if v.inherit_option_id.id not in done:
result.append({
'name': v.inherit_option_id.name,

View File

@ -65,6 +65,8 @@
item.id, item.active ? '' : '-empty', item.name));
}
});
// Adding Static Menus
menu.append('<li class="divider"></li><li><a href="/page/website.themes">Change Theme</a></li>');
}
);
});

View File

@ -0,0 +1,145 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!--
Theme Selector
-->
<template id="website.themes" name="Themes">
<t t-call="website.layout">
<div class="container" t-if="editable">
<div class="alert alert-block mt32" t-if="theme_changed">
<button type="button" class="close" data-dismiss="alert">&amp;times;</button>
<p>
<h4>Theme Changed!</h4>
Have a look at <a href="/">your homepage</a> or try another theme bellow.
</p>
</div>
<h1 class="text-center mt32">Change Your Theme</h1>
<div class="row mt32" id="themes-list">
<div class="span4">
<div class="well text-center">
<div class="image">
<img class="img-responsive" src="http://bootswatch.com/flatly/thumbnail.png" alt="Flatly"/>
</div>
<div class="options">
<h3>Flatly</h3>
<p>Flat and modern</p>
<a class="btn btn-info" href="/website/theme_change?theme_id=website.theme_flatly">Apply</a>
</div>
</div>
</div>
<div class="span4">
<div class="well text-center">
<div class="image">
<img src="http://bootswatch.com/amelia/thumbnail.png" class="img-responsive" alt="Amelia"/>
</div>
<div class="options">
<h3>Default</h3>
<p>Sweet and cheery</p>
<a class="btn btn-info" href="/website/theme_change">Apply</a>
</div>
</div>
</div>
<div class="span4">
<div class="well text-center">
<div class="image">
<img src="http://bootswatch.com/cerulean/thumbnail.png" class="img-responsive" alt="Cerulean"/>
</div>
<div class="options">
<h3>Cerulean</h3>
<p>A calm, blue sky</p>
<a class="btn btn-info" href="/website/theme_change">Apply</a>
</div>
</div>
</div>
<div class="span4">
<div class="well text-center">
<div class="image">
<img class="img-responsive" src="http://bootswatch.com/cosmo/thumbnail.png" alt="Cosmo"/>
</div>
<div class="options">
<h3>Cosmo</h3>
<p>An ode to Metro</p>
<a class="btn btn-info" href="/website/theme_change">Apply</a>
</div>
</div>
</div>
<div class="span4">
<div class="well text-center">
<div class="image">
<img class="img-responsive" src="http://bootswatch.com/cyborg/thumbnail.png" alt="Cyborg"/>
</div>
<div class="options">
<h3>Cyborg</h3>
<p>Jet black and electric blue</p>
<a class="btn btn-info" href="/website/theme_change">Apply</a>
</div>
</div>
</div>
<div class="span4">
<div class="well text-center">
<div class="image">
<img class="img-responsive" src="http://bootswatch.com/journal/thumbnail.png" alt="Journal"/>
</div>
<div class="options">
<h3>Journal</h3>
<p>Crisp like a new sheet of paper</p>
<a class="btn btn-info" href="/website/theme_change">Apply</a>
</div>
</div>
</div>
<div class="span4">
<div class="well text-center">
<div class="image">
<img class="img-responsive" src="http://bootswatch.com/readable/thumbnail.png" alt="Readable"/>
</div>
<div class="options">
<h3>Readable</h3>
<p>Optimized for legibility</p>
<a class="btn btn-info" href="/website/theme_change">Apply</a>
</div>
</div>
</div>
<div class="span4">
<div class="well text-center">
<div class="image">
<img class="img-responsive" src="http://bootswatch.com/simplex/thumbnail.png" alt="Simplex"/>
</div>
<div class="options">
<h3>Simplex</h3>
<p>Mini and minimalist</p>
<a class="btn btn-info" href="/website/theme_change">Apply</a>
</div>
</div>
</div>
</div>
</div>
</t>
</template>
<!--
All Default Themes
-->
<template id="website.theme_flatly" name="Flat Theme" inherit_option_id="website.theme">
<xpath expr="//link[@id='bootstrap_css']" position="replace">
<link rel='stylesheet' href='/website/static/lib/bootstrap/css/bootstrap-flatly.css' t-ignore="true"/>
<link rel='stylesheet' href='/website/static/src/css/website-flatly.css' t-ignore="true"/>
</xpath>
</template>
</data>
</openerp>

View File

@ -11,13 +11,6 @@
<link id="website_css" rel='stylesheet' href='/website/static/src/css/website.css' t-ignore="true"/>
</template>
<template id="website.theme_flatly" name="Flat Theme" inherit_option_id="website.theme">
<xpath expr="//link[@id='bootstrap_css']" position="replace">
<link rel='stylesheet' href='/website/static/lib/bootstrap/css/bootstrap-flatly.css' t-ignore="true"/>
<link rel='stylesheet' href='/website/static/src/css/website-flatly.css' t-ignore="true"/>
</xpath>
</template>
<template id="layout">
&lt;!DOCTYPE html&gt;
<html t-att-data-view-xmlid="__stack__[0]" t-att-data-editable="'1' if editable else '0'">