2013-06-24 13:36:54 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
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-07-02 16:03:05 +00:00
|
|
|
from urllib import quote_plus
|
2013-06-24 13:36:54 +00:00
|
|
|
from openerp.addons.web.http import request
|
|
|
|
|
2013-07-02 11:04:39 +00:00
|
|
|
def template_values():
|
|
|
|
script = "\n".join(['<script type="text/javascript" src="%s"></script>' % i for i in manifest_list('js', db=request.db)])
|
2013-07-22 14:21:30 +00:00
|
|
|
css = "\n".join('<link rel="stylesheet" href="%s">' % i for i in manifest_list('css', db=request.db))
|
2013-07-02 16:46:37 +00:00
|
|
|
try:
|
|
|
|
request.session.check_security()
|
|
|
|
loggued = True
|
|
|
|
uid = request.session._uid
|
|
|
|
except http.SessionExpiredException:
|
2013-07-02 19:45:40 +00:00
|
|
|
loggued = False
|
2013-07-02 16:46:37 +00:00
|
|
|
uid = openerp.SUPERUSER_ID
|
2013-07-02 11:04:39 +00:00
|
|
|
values = {
|
2013-07-02 16:46:37 +00:00
|
|
|
'loggued': loggued,
|
|
|
|
'editable': loggued,
|
2013-07-02 11:04:39 +00:00
|
|
|
'request': request,
|
|
|
|
'registry': request.registry,
|
|
|
|
'cr': request.cr,
|
2013-07-02 16:46:37 +00:00
|
|
|
'uid': uid,
|
2013-07-22 14:21:30 +00:00
|
|
|
'script': script,
|
|
|
|
'css': css,
|
2013-07-02 11:04:39 +00:00
|
|
|
}
|
|
|
|
return values
|
|
|
|
|
2013-06-24 13:36:54 +00:00
|
|
|
class Website(openerp.addons.web.controllers.main.Home):
|
2013-07-10 15:33:52 +00:00
|
|
|
@http.route('/', type='http', auth="admin")
|
2013-06-24 13:36:54 +00:00
|
|
|
def index(self, **kw):
|
2013-07-01 00:20:54 +00:00
|
|
|
return self.page("website.homepage")
|
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)
|
|
|
|
|
2013-07-10 15:33:52 +00:00
|
|
|
@http.route('/pagenew/<path:path>', type='http', auth="admin")
|
2013-07-02 19:11:30 +00:00
|
|
|
def pagenew(self, path):
|
|
|
|
values = template_values()
|
|
|
|
uid = values['uid']
|
|
|
|
imd = request.registry['ir.model.data']
|
|
|
|
view_model, view_id = imd.get_object_reference(request.cr, uid, 'website', 'default_page')
|
|
|
|
newview_id = request.registry['ir.ui.view'].copy(request.cr, uid, view_id)
|
|
|
|
if '.' in path:
|
|
|
|
module, idname = path.split('.')
|
|
|
|
else:
|
|
|
|
module = False
|
|
|
|
idname = path
|
|
|
|
imd.create(request.cr, uid, {
|
|
|
|
'name': idname,
|
|
|
|
'module': module,
|
|
|
|
'model': 'ir.ui.view',
|
|
|
|
'res_id': newview_id,
|
|
|
|
})
|
|
|
|
# TODO: replace by a redirect
|
|
|
|
return self.page(path)
|
|
|
|
|
2013-07-10 15:33:52 +00:00
|
|
|
@http.route('/page/<path:path>', type='http', auth="admin")
|
2013-07-02 19:11:30 +00:00
|
|
|
def page(self, path):
|
2013-07-01 00:20:54 +00:00
|
|
|
#def get_html_head():
|
|
|
|
# head += ['<link rel="stylesheet" href="%s">' % i for i in manifest_list('css', db=request.db)]
|
|
|
|
#modules = request.registry.get("ir.module.module").search_read(request.cr, openerp.SUPERUSER_ID, fields=['id', 'shortdesc', 'summary', 'icon_image'], limit=50)
|
2013-07-02 16:46:37 +00:00
|
|
|
values = template_values()
|
|
|
|
uid = values['uid']
|
2013-07-01 00:20:54 +00:00
|
|
|
context = {
|
2013-07-02 16:46:37 +00:00
|
|
|
'inherit_branding': values['editable'],
|
2013-07-01 00:20:54 +00:00
|
|
|
}
|
2013-07-02 16:03:05 +00:00
|
|
|
company = request.registry['res.company'].browse(request.cr, uid, 1, context=context)
|
2013-07-02 11:04:39 +00:00
|
|
|
values.update({
|
2013-07-02 16:03:05 +00:00
|
|
|
'res_company': company,
|
2013-07-02 19:04:49 +00:00
|
|
|
'path': path
|
2013-07-02 11:04:39 +00:00
|
|
|
})
|
2013-07-02 16:03:05 +00:00
|
|
|
values['google_map_url'] = "http://maps.googleapis.com/maps/api/staticmap?center=%s&sensor=false&zoom=8&size=298x298" \
|
|
|
|
% quote_plus('%s, %s %s, %s' % (company.street, company.city, company.zip, company.country_id and company.country_id.name_get()[0][1] or ''))
|
2013-07-02 19:04:49 +00:00
|
|
|
try:
|
|
|
|
html = request.registry.get("ir.ui.view").render(request.cr, uid, path, values, context)
|
|
|
|
except ValueError, e:
|
|
|
|
html = request.registry.get("ir.ui.view").render(request.cr, uid, 'website.404', values, context)
|
2013-06-27 09:14:09 +00:00
|
|
|
return html
|
|
|
|
|
2013-06-24 13:36:54 +00:00
|
|
|
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
|