[IMP] home controller
bzr revid: chs@openerp.com-20120808114110-b7x8b3e4pfn20ie5
This commit is contained in:
parent
d34fec4471
commit
1d75045294
|
@ -455,7 +455,6 @@ class Root(object):
|
|||
by the server, will be filtered by this pattern
|
||||
"""
|
||||
def __init__(self, options, openerp_addons_namespace=True):
|
||||
self.root = '/web/webclient/home'
|
||||
self.config = options
|
||||
|
||||
if not hasattr(self.config, 'connector'):
|
||||
|
@ -495,11 +494,7 @@ class Root(object):
|
|||
request.parameter_storage_class = werkzeug.datastructures.ImmutableDict
|
||||
request.app = self
|
||||
|
||||
if request.path == '/':
|
||||
params = urllib.urlencode(request.args)
|
||||
return werkzeug.utils.redirect(self.root + '?' + params, 301)(
|
||||
environ, start_response)
|
||||
elif request.path == '/mobile':
|
||||
if request.path == '/mobile': # FIXME move to web_mobile module
|
||||
return werkzeug.utils.redirect(
|
||||
'/web_mobile/static/src/web_mobile.html', 301)(environ, start_response)
|
||||
|
||||
|
|
|
@ -163,16 +163,13 @@ def sass2scss(src):
|
|||
return out
|
||||
return write(sass)
|
||||
|
||||
class WebClient(openerpweb.Controller):
|
||||
_cp_path = "/web/webclient"
|
||||
|
||||
def server_wide_modules(self, req):
|
||||
def server_wide_modules(req):
|
||||
addons = [i for i in req.config.server_wide_modules if i in openerpweb.addons_manifest]
|
||||
return addons
|
||||
|
||||
def manifest_glob(self, req, addons, key):
|
||||
def manifest_glob(req, addons, key):
|
||||
if addons is None:
|
||||
addons = self.server_wide_modules(req)
|
||||
addons = server_wide_modules(req)
|
||||
else:
|
||||
addons = addons.split(',')
|
||||
r = []
|
||||
|
@ -188,32 +185,21 @@ class WebClient(openerpweb.Controller):
|
|||
r.append((path, path[len(addons_path):]))
|
||||
return r
|
||||
|
||||
def manifest_list(self, req, mods, extension):
|
||||
def manifest_list(req, mods, extension):
|
||||
if not req.debug:
|
||||
path = '/web/webclient/' + extension
|
||||
if mods is not None:
|
||||
path += '?mods=' + mods
|
||||
return [path]
|
||||
no_sugar = req.httprequest.environ["QUERY_STRING"].count("no_sugar") >= 1
|
||||
no_sugar = no_sugar or req.httprequest.environ.get('HTTP_REFERER', '').count("no_sugar") >= 1
|
||||
if not no_sugar:
|
||||
return ['%s?debug=%s' % (wp, os.path.getmtime(fp)) for fp, wp in self.manifest_glob(req, mods, extension)]
|
||||
files = manifest_glob(req, mods, extension)
|
||||
i_am_diabetic = req.httprequest.environ["QUERY_STRING"].count("no_sugar") >= 1 or \
|
||||
req.httprequest.environ.get('HTTP_REFERER', '').count("no_sugar") >= 1
|
||||
if i_am_diabetic:
|
||||
return [wp for _fp, wp in files]
|
||||
else:
|
||||
return [el[1] for el in self.manifest_glob(req, mods, extension)]
|
||||
return ['%s?debug=%s' % (wp, os.path.getmtime(fp)) for fp, wp in files]
|
||||
|
||||
@openerpweb.jsonrequest
|
||||
def csslist(self, req, mods=None):
|
||||
return self.manifest_list(req, mods, 'css')
|
||||
|
||||
@openerpweb.jsonrequest
|
||||
def jslist(self, req, mods=None):
|
||||
return self.manifest_list(req, mods, 'js')
|
||||
|
||||
@openerpweb.jsonrequest
|
||||
def qweblist(self, req, mods=None):
|
||||
return self.manifest_list(req, mods, 'qweb')
|
||||
|
||||
def get_last_modified(self, files):
|
||||
def get_last_modified(files):
|
||||
""" Returns the modification time of the most recently modified
|
||||
file provided
|
||||
|
||||
|
@ -227,7 +213,7 @@ class WebClient(openerpweb.Controller):
|
|||
for f in files)
|
||||
return datetime.datetime(1970, 1, 1)
|
||||
|
||||
def make_conditional(self, req, response, last_modified=None, etag=None):
|
||||
def make_conditional(req, response, last_modified=None, etag=None):
|
||||
""" Makes the provided response conditional based upon the request,
|
||||
and mandates revalidation from clients
|
||||
|
||||
|
@ -251,10 +237,52 @@ class WebClient(openerpweb.Controller):
|
|||
response.set_etag(etag)
|
||||
return response.make_conditional(req.httprequest)
|
||||
|
||||
class Home(openerpweb.Controller):
|
||||
_cp_path = '/'
|
||||
|
||||
@openerpweb.httprequest
|
||||
def index(self, req, s_action=None, **kw):
|
||||
js = "\n ".join('<script type="text/javascript" src="%s"></script>' % i for i in manifest_list(req, None, 'js'))
|
||||
css = "\n ".join('<link rel="stylesheet" href="%s">' % i for i in manifest_list(req, None, 'css'))
|
||||
|
||||
r = html_template % {
|
||||
'js': js,
|
||||
'css': css,
|
||||
'modules': simplejson.dumps(server_wide_modules(req)),
|
||||
'init': 'var wc = new s.web.WebClient();wc.appendTo($(document.body));'
|
||||
}
|
||||
return r
|
||||
|
||||
@openerpweb.httprequest
|
||||
def login(self, req, db, login, key):
|
||||
return self._login(req, db, login, key)
|
||||
|
||||
def _login(self, req, db, login, key, redirect_url='/'):
|
||||
req.session.authenticate(db, login, key, {})
|
||||
redirect = werkzeug.utils.redirect(redirect_url, 303)
|
||||
cookie_val = urllib2.quote(simplejson.dumps(req.session_id))
|
||||
redirect.set_cookie('instance0|session_id', cookie_val)
|
||||
return redirect
|
||||
|
||||
class WebClient(openerpweb.Controller):
|
||||
_cp_path = "/web/webclient"
|
||||
|
||||
@openerpweb.jsonrequest
|
||||
def csslist(self, req, mods=None):
|
||||
return manifest_list(req, mods, 'css')
|
||||
|
||||
@openerpweb.jsonrequest
|
||||
def jslist(self, req, mods=None):
|
||||
return manifest_list(req, mods, 'js')
|
||||
|
||||
@openerpweb.jsonrequest
|
||||
def qweblist(self, req, mods=None):
|
||||
return manifest_list(req, mods, 'qweb')
|
||||
|
||||
@openerpweb.httprequest
|
||||
def css(self, req, mods=None):
|
||||
files = list(self.manifest_glob(req, mods, 'css'))
|
||||
last_modified = self.get_last_modified(f[0] for f in files)
|
||||
files = list(manifest_glob(req, mods, 'css'))
|
||||
last_modified = get_last_modified(f[0] for f in files)
|
||||
if req.httprequest.if_modified_since and req.httprequest.if_modified_since >= last_modified:
|
||||
return werkzeug.wrappers.Response(status=304)
|
||||
|
||||
|
@ -287,57 +315,36 @@ class WebClient(openerpweb.Controller):
|
|||
|
||||
content, checksum = concat_files((f[0] for f in files), reader)
|
||||
|
||||
return self.make_conditional(
|
||||
return make_conditional(
|
||||
req, req.make_response(content, [('Content-Type', 'text/css')]),
|
||||
last_modified, checksum)
|
||||
|
||||
@openerpweb.httprequest
|
||||
def js(self, req, mods=None):
|
||||
files = [f[0] for f in self.manifest_glob(req, mods, 'js')]
|
||||
last_modified = self.get_last_modified(files)
|
||||
files = [f[0] for f in manifest_glob(req, mods, 'js')]
|
||||
last_modified = get_last_modified(files)
|
||||
if req.httprequest.if_modified_since and req.httprequest.if_modified_since >= last_modified:
|
||||
return werkzeug.wrappers.Response(status=304)
|
||||
|
||||
content, checksum = concat_files(files, intersperse=';')
|
||||
|
||||
return self.make_conditional(
|
||||
return make_conditional(
|
||||
req, req.make_response(content, [('Content-Type', 'application/javascript')]),
|
||||
last_modified, checksum)
|
||||
|
||||
@openerpweb.httprequest
|
||||
def qweb(self, req, mods=None):
|
||||
files = [f[0] for f in self.manifest_glob(req, mods, 'qweb')]
|
||||
last_modified = self.get_last_modified(files)
|
||||
files = [f[0] for f in manifest_glob(req, mods, 'qweb')]
|
||||
last_modified = get_last_modified(files)
|
||||
if req.httprequest.if_modified_since and req.httprequest.if_modified_since >= last_modified:
|
||||
return werkzeug.wrappers.Response(status=304)
|
||||
|
||||
content, checksum = concat_xml(files)
|
||||
|
||||
return self.make_conditional(
|
||||
return make_conditional(
|
||||
req, req.make_response(content, [('Content-Type', 'text/xml')]),
|
||||
last_modified, checksum)
|
||||
|
||||
@openerpweb.httprequest
|
||||
def home(self, req, s_action=None, **kw):
|
||||
js = "\n ".join('<script type="text/javascript" src="%s"></script>'%i for i in self.manifest_list(req, None, 'js'))
|
||||
css = "\n ".join('<link rel="stylesheet" href="%s">'%i for i in self.manifest_list(req, None, 'css'))
|
||||
|
||||
r = html_template % {
|
||||
'js': js,
|
||||
'css': css,
|
||||
'modules': simplejson.dumps(self.server_wide_modules(req)),
|
||||
'init': 'var wc = new s.web.WebClient();wc.appendTo($(document.body));'
|
||||
}
|
||||
return r
|
||||
|
||||
@openerpweb.httprequest
|
||||
def login(self, req, db, login, key):
|
||||
req.session.authenticate(db, login, key, {})
|
||||
redirect = werkzeug.utils.redirect('/web/webclient/home', 303)
|
||||
cookie_val = urllib2.quote(simplejson.dumps(req.session_id))
|
||||
redirect.set_cookie('instance0|session_id', cookie_val)
|
||||
return redirect
|
||||
|
||||
@openerpweb.jsonrequest
|
||||
def translations(self, req, mods, lang):
|
||||
lang_model = req.session.model('res.lang')
|
||||
|
|
Loading…
Reference in New Issue