2013-07-26 12:33:17 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import openerp
|
2013-08-05 16:16:00 +00:00
|
|
|
from openerp.osv import osv
|
2013-07-26 12:33:17 +00:00
|
|
|
from openerp.addons.web import http
|
|
|
|
from openerp.addons.web.controllers import main
|
|
|
|
from openerp.addons.web.http import request
|
|
|
|
|
|
|
|
|
2013-08-01 12:48:50 +00:00
|
|
|
def auth_method_public():
|
|
|
|
registry = openerp.modules.registry.RegistryManager.get(request.db)
|
2013-08-06 14:06:36 +00:00
|
|
|
if not request.session.uid:
|
2013-08-07 13:01:27 +00:00
|
|
|
request.uid = registry['website'].get_public_user().id
|
2013-08-06 14:06:36 +00:00
|
|
|
else:
|
|
|
|
request.uid = request.session.uid
|
2013-08-01 12:48:50 +00:00
|
|
|
http.auth_methods['public'] = auth_method_public
|
|
|
|
|
|
|
|
|
2013-08-05 16:16:00 +00:00
|
|
|
class website(osv.osv):
|
|
|
|
_name = "website" # Avoid website.website convention for conciseness (for new api). Got a special authorization from xmo and rco
|
|
|
|
_description = "Website"
|
|
|
|
|
2013-08-07 13:01:27 +00:00
|
|
|
public_user = None
|
2013-08-06 14:06:36 +00:00
|
|
|
|
2013-08-07 13:01:27 +00:00
|
|
|
def get_public_user(self):
|
|
|
|
if not self.public_user:
|
|
|
|
ref = request.registry['ir.model.data'].get_object_reference(request.cr, openerp.SUPERUSER_ID, 'website', 'public_user')
|
|
|
|
self.public_user = request.registry[ref[0]].browse(request.cr, openerp.SUPERUSER_ID, ref[1])
|
|
|
|
return self.public_user
|
2013-08-06 14:06:36 +00:00
|
|
|
|
2013-08-05 16:16:00 +00:00
|
|
|
def get_rendering_context(self, additional_values=None):
|
2013-08-05 08:26:38 +00:00
|
|
|
debug = 'debug' in request.params
|
2013-08-07 13:01:27 +00:00
|
|
|
is_public_user = request.uid == self.get_public_user().id
|
2013-08-05 16:16:00 +00:00
|
|
|
values = {
|
|
|
|
'debug': debug,
|
2013-08-07 13:01:27 +00:00
|
|
|
'is_public_user': is_public_user,
|
|
|
|
'editable': not is_public_user,
|
2013-07-26 12:33:17 +00:00
|
|
|
'request': request,
|
|
|
|
'registry': request.registry,
|
2013-08-01 12:48:50 +00:00
|
|
|
'cr': request.cr,
|
|
|
|
'uid': request.uid,
|
2013-07-26 12:33:17 +00:00
|
|
|
'host_url': request.httprequest.host_url,
|
2013-08-01 14:33:47 +00:00
|
|
|
'res_company': request.registry['res.company'].browse(request.cr, openerp.SUPERUSER_ID, 1),
|
2013-07-26 12:33:17 +00:00
|
|
|
}
|
2013-08-07 13:01:27 +00:00
|
|
|
if values['editable']:
|
2013-08-05 16:16:00 +00:00
|
|
|
values.update({
|
|
|
|
'script': "\n".join(['<script type="text/javascript" src="%s"></script>' % i for i in main.manifest_list('js', db=request.db, debug=debug)]),
|
|
|
|
'css': "\n".join('<link rel="stylesheet" href="%s">' % i for i in main.manifest_list('css', db=request.db, debug=debug))
|
|
|
|
})
|
|
|
|
if additional_values:
|
|
|
|
values.update(additional_values)
|
|
|
|
return values
|
|
|
|
|
|
|
|
def render(self, template, values={}):
|
2013-08-07 10:01:42 +00:00
|
|
|
context = {
|
|
|
|
'inherit_branding': values.get('editable', False),
|
|
|
|
}
|
|
|
|
return request.registry.get("ir.ui.view").render(request.cr, request.uid, template, values, context=context)
|