2013-06-24 13:36:54 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2013-06-25 14:23:13 +00:00
|
|
|
from jinja2 import Template # WIP !
|
|
|
|
|
2013-06-24 13:36:54 +00:00
|
|
|
import openerp
|
|
|
|
from openerp.addons.web import http
|
2013-06-25 14:23:13 +00:00
|
|
|
from openerp.addons.web.controllers.main import manifest_list
|
2013-06-24 13:36:54 +00:00
|
|
|
from openerp.addons.web.http import request
|
|
|
|
|
2013-06-25 14:23:13 +00:00
|
|
|
def get_html_head():
|
|
|
|
head = ['<script type="text/javascript" src="%s"></script>' % i for i in manifest_list('js', db=request.db)]
|
|
|
|
head += ['<link rel="stylesheet" href="%s">' % i for i in manifest_list('css', db=request.db)]
|
|
|
|
head += ['<script type="text/javascript" src="/website/static/src/js/website_editor.js"></script>']
|
|
|
|
return "\n ".join(head)
|
|
|
|
|
|
|
|
# WIIIP !!
|
|
|
|
module_template = Template("""
|
|
|
|
{%- for module in modules %}
|
|
|
|
<a href='#' title='{{ module.shortdesc }}' class='oe_app ab_app_descr'>
|
|
|
|
<div class='ab_app_descr'>
|
|
|
|
<div class='oe_app_icon'>
|
|
|
|
<img src="data:image/png;base64,{{ module.icon_image }}" onerror="this.src = '/base/static/src/img/icon.png'">
|
|
|
|
</div>
|
|
|
|
</div>
|
2013-06-25 23:07:34 +00:00
|
|
|
<div
|
|
|
|
class='oe_app_name editable'
|
|
|
|
data-model='ir.module.module'
|
|
|
|
data-id='{{ module.id }}'
|
|
|
|
data-field='shortdesc'
|
|
|
|
>{{ module.shortdesc }}</div>
|
2013-06-25 14:23:13 +00:00
|
|
|
<div
|
|
|
|
class='oe_app_descr editable'
|
|
|
|
data-model='ir.module.module'
|
|
|
|
data-id='{{ module.id }}'
|
|
|
|
data-field='summary'
|
|
|
|
>{{ module.summary }}</div>
|
|
|
|
</a>
|
|
|
|
{%- endfor %}
|
|
|
|
""")
|
|
|
|
|
|
|
|
|
2013-06-24 13:36:54 +00:00
|
|
|
class Website(openerp.addons.web.controllers.main.Home):
|
|
|
|
|
|
|
|
@http.route('/', type='http', auth="db")
|
|
|
|
def index(self, **kw):
|
2013-06-24 16:23:27 +00:00
|
|
|
editable = bool(request.session._uid)
|
2013-06-25 14:23:13 +00:00
|
|
|
try:
|
|
|
|
request.session.check_security()
|
|
|
|
except http.SessionExpiredException:
|
|
|
|
editable = False
|
|
|
|
# WIIIIIIIP !!!
|
|
|
|
html = open(openerp.addons.get_module_resource('website', 'views', 'homepage.html'), 'rb').read().decode('utf8')
|
|
|
|
modules = request.registry.get("ir.module.module").search_read(request.cr, openerp.SUPERUSER_ID, fields=['id', 'shortdesc', 'summary', 'icon_image'], limit=50)
|
|
|
|
modules_html = module_template.render(modules=modules)
|
|
|
|
html = html.replace(u'<!--modules-->', modules_html)
|
2013-06-24 16:23:27 +00:00
|
|
|
if editable:
|
2013-06-25 14:23:13 +00:00
|
|
|
html = html.replace('<!--editable-->', get_html_head())
|
2013-06-24 16:23:27 +00:00
|
|
|
return html
|
2013-06-24 13:36:54 +00:00
|
|
|
|
|
|
|
@http.route('/admin', type='http', auth="none")
|
|
|
|
def admin(self, *args, **kw):
|
|
|
|
return super(Website, self).index(*args, **kw)
|
|
|
|
|
|
|
|
|
|
|
|
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
|