diff --git a/addons/base/__openerp__.py b/addons/base/__openerp__.py new file mode 100644 index 00000000000..da2b345d217 --- /dev/null +++ b/addons/base/__openerp__.py @@ -0,0 +1,6 @@ +{ + "name" : "OpenERP Web base", + "version" : "2.0", + "depends" : [], + 'active': True, +} diff --git a/addons/base/controllers/main.py b/addons/base/controllers/main.py index 9fa3990a0be..4551615f9a6 100644 --- a/addons/base/controllers/main.py +++ b/addons/base/controllers/main.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- -import json, os, sys, traceback +import glob,json,os,sys,traceback + +#import simplejson as json import openerpweb @@ -64,12 +66,9 @@ class Hello(openerpweb.Controller): class Connection(openerpweb.Controller): _cp_path = "/base/connection" - - def filesofmodulemap(self, module_file_map): + def filesofmodulemap(self, ): # TODO root should be a global config - root = os.path.join(os.path.dirname(__file__),'..','..') files=[] - for i in mods.split(','): for j in cssfiles.get(i,[]): files.append(j) @@ -79,6 +78,7 @@ class Connection(openerpweb.Controller): concat: concatenation of file content timestamp: max(os.path.getmtime of file_list) """ + root = openerpweb.path_root files_content = [] files_timestamp = 0 for i in file_list: @@ -92,7 +92,15 @@ class Connection(openerpweb.Controller): def css(self, req): # TODO http get argument mods is a comma seprated value of modules - mods = 'base,base_calendar' + mods = 'base,base_hello' + files = [] + for i in mods.split(','): + globlist = openerpweb.addons_manifest.get(i,{}) + for j in globlist: + tmp = glob.glob(os.path.join(path_addons,i,j)) + print tmp + files.append(tmp) + # TODO modules should list their css and js in __openerp__ # TODO cssfiles should be a global registry of files cssfiles = { @@ -130,6 +138,12 @@ class Session(openerpweb.Controller): } return res + def modules(self, req): + # TODO return the list of all modules + res={} + res["modules"] = ["base","base_hello"] + return res + class Menu(openerpweb.Controller): _cp_path = "/base/menu" diff --git a/openerpweb/openerpweb.py b/openerpweb/openerpweb.py index 04f97982f37..601599f35d0 100644 --- a/openerpweb/openerpweb.py +++ b/openerpweb/openerpweb.py @@ -135,7 +135,7 @@ def jsonrequest(f): l.exposed=1 return l -class BasicRequest(object): +class HttpRequest(object): """ Regular GET/POST request """ def __init__(self): @@ -148,10 +148,10 @@ class BasicRequest(object): r=f(controller, self, request) return r -def basicrequest(f): +def httprequest(f): # check cleaner wrapping: # functools.wraps(f)(lambda x: JsonRequest().dispatch(x, f)) - l=lambda self, request: BasicRequest().dispatch(self, f, request) + l=lambda self, request: HttpRequest().dispatch(self, f, request) l.exposed=1 return l @@ -162,17 +162,20 @@ def basicrequest(f): path_root = os.path.dirname(os.path.dirname(os.path.normpath(__file__))) path_addons = os.path.join(path_root,'addons') cherrypy_root = None -openerp_addons = {} -openerp_controllers_class = {} -openerp_controllers_object = {} -openerp_controllers_path = {} + +# globals might move into a pool if needed +addons_module = {} +addons_manifest = {} +controllers_class = {} +controllers_object = {} +controllers_path = {} class ControllerType(type): def __init__(cls, name, bases, attrs): super(ControllerType, cls).__init__(name, bases, attrs) # TODO forgive me this hack and find me a clean way to get the absolute name of a class cls.fullname = re.search("'(.+)'",repr(cls)).group(1) - openerp_controllers_class[cls.fullname] = cls + controllers_class[cls.fullname] = cls class Controller(object): __metaclass__ = ControllerType @@ -186,15 +189,19 @@ class Root(object): sys.path.insert(0,path_addons) for i in os.listdir(path_addons): if i not in sys.modules: - print "Loading",i - m = __import__(i) - openerp_addons[i] = m - for k,v in openerp_controllers_class.items(): - if k not in openerp_controllers_object: + manifest_path = os.path.join(path_addons,i,'__openerp__.py') + if os.path.isfile(manifest_path): + manifest = eval(open(manifest_path).read()) + print "Loading",i + m = __import__(i) + addons_module[i] = m + addons_manifest[i] = manifest + for k,v in controllers_class.items(): + if k not in controllers_object: o = v() - openerp_controllers_object[k] = o + controllers_object[k] = o if hasattr(o,'_cp_path'): - openerp_controllers_path[o._cp_path] = o + controllers_path[o._cp_path] = o def default(self, *l, **kw): #print "default",l,kw @@ -206,13 +213,14 @@ class Root(object): elif len(l) > 1: for i in range(1,len(l)+1): ps = "/" + "/".join(l[0:i]) - if ps in openerp_controllers_path: - c = openerp_controllers_path[ps] + if ps in controllers_path: + c = controllers_path[ps] rest = l[i:] or ['index'] meth = rest[0] m = getattr(c,meth) - print "Calling",ps,c,meth,m - return m(**kw) + if getattr(m,'exposed',0): + print "Calling",ps,c,meth,m + return m(**kw) else: return '/base/static/openerp/base.html'