Exemplo n.º 1
0
def get_template_lookup():
    """Return the Template Lookup for the current database"""

    lookup = pooler.get_pool().get(None, TEMPLATE_LOOKUP_GROUP)
    if not lookup:
        lookup = TemplateLookup(
                directories=[paths.root(), paths.addons()],
                default_filters=filters,
                imports=imports,
                preprocessor=templating.edition_preprocessor)
        pooler.get_pool().get_group(TEMPLATE_LOOKUP_GROUP)[None] = lookup

    return lookup
def get_template_lookup():
    """Return the Template Lookup for the current database"""

    lookup = pooler.get_pool().get(None, TEMPLATE_LOOKUP_GROUP)
    if not lookup:
        lookup = TemplateLookup(directories=[paths.root(),
                                             paths.addons()],
                                default_filters=filters,
                                imports=imports,
                                preprocessor=templating.edition_preprocessor)
        pooler.get_pool().get_group(TEMPLATE_LOOKUP_GROUP)[None] = lookup

    return lookup
Exemplo n.º 3
0
def load_module_graph(db_name, graph, config):

    pool = pooler.get_pool()

    for package in graph:

        if package.name in _loaded_addons:
            continue

        cherrypy.log("Loading module '%s'" % package.name, "INFO")

        imp_module(package.name)

        static = paths.addons(package.name, 'static')
        if os.path.isdir(static):
            from openobject.widgets import register_resource_directory
            register_resource_directory(config, package.name, static)

        addon_path = paths.addons(package.name)
        if os.path.isdir(paths.addons(package.name, 'po')):
            i18n.load_translations(addon_path)
            i18n.load_translations(addon_path, domain="javascript")

        _loaded_addons[package.name] = True

    for package in graph:
        pool.load(package.name)
        _loaded[db_name][package.name] = True
Exemplo n.º 4
0
def load_module_graph(db_name, graph, config):

    pool = pooler.get_pool()

    for package in graph:

        if package.name in _loaded_addons:
            continue

        cherrypy.log("Loading module '%s'" % package.name, "INFO")

        imp_module(package.name)

        static = paths.addons(package.name, 'static')
        if os.path.isdir(static):
            from openobject.widgets import register_resource_directory
            register_resource_directory(config, package.name, static)

        addon_path = paths.addons(package.name)
        if os.path.isdir(paths.addons(package.name, 'po')):
            i18n.load_translations(addon_path)
            i18n.load_translations(addon_path, domain="javascript")

        _loaded_addons[package.name] = True

    for package in graph:
        pool.load(package.name)
        _loaded[db_name][package.name] = True
Exemplo n.º 5
0
    def default(self, *args, **kw):
        # If we don't set it to a `False` default, we're probably going to
        # throw *a lot* which we don't want.
        cherrypy.request.loading_addons = False
        autoreloader_enabled = bool(getattr(cherrypy.engine.autoreload, "thread", None))
        if autoreloader_enabled:
            # stop (actually don't listen to) the auto-reloader the process
            # doesn't restart due to downloading new add-ons or refreshing
            # existing ones
            cherrypy.engine.autoreload.unsubscribe()
        try:
            obj = pooler.get_pool().get_controller("/openerp/modules")
            if not obj:
                raise RuntimeError("Cannot find controller for /openerp/modules")
            if obj.has_new_modules():
                pooler.restart_pool()
        except AuthenticationError:
            pass

        if autoreloader_enabled:
            # re-enable auto-reloading if it was enabled before
            cherrypy.engine.autoreload.subscribe()

        request = cherrypy.request
        self.clean_headers_params(request)
        func, vpath = self.find_handler()

        if func:
            # Decode any leftover %2F in the virtual_path atoms.
            vpath = [x.replace("%2F", "/") for x in vpath]
            request.handler = cherrypy.dispatch.LateParamPageHandler(func, *vpath)
        else:
            request.handler = cherrypy.NotFound()

        return request.handler()
Exemplo n.º 6
0
def get_registered_widgets(view="form"):
    """Get all the registered widgets for the given view type.

    @param view: the view
    @returns: dict of all the registered widgets
    """
    pool = pooler.get_pool()
    return pool.get_group(view)
Exemplo n.º 7
0
def get_registered_widgets(view="form"):
    """Get all the registered widgets for the given view type.

    @param view: the view
    @returns: dict of all the registered widgets
    """
    pool = pooler.get_pool()
    return pool.get_group(view)
Exemplo n.º 8
0
def get_registered_views():
    pool = pooler.get_pool()
    Views = pool.get_group("view_types")

    views = [(kind, ViewType()) for kind, ViewType in Views.iteritems()]
    views.sort(lambda a, b: cmp(a[1].priority, b[1].priority))

    return views
Exemplo n.º 9
0
def get_registered_views():
    pool = pooler.get_pool()
    Views = pool.get_group("view_types")

    views = [(kind, ViewType()) for kind, ViewType in Views.iteritems()]
    views.sort(lambda a, b: cmp(a[1].priority, b[1].priority))

    return views
Exemplo n.º 10
0
def get_view_widget(kind, screen):

    pool = pooler.get_pool()
    Views = pool.get_group("view_types")

    try:
        view = Views[kind]()
    except KeyError, e:
        raise Exception("view '%s' not supported." % kind)
Exemplo n.º 11
0
def get_widget(type, view="form"):
    """Get the widget of the given type for the given view.

    @param view: the view
    @param type: the widget type
    """

    pool = pooler.get_pool()
    return pool.get(type, group=view)
Exemplo n.º 12
0
def get_view_widget(kind, screen):

    pool = pooler.get_pool()
    Views = pool.get_group("view_types")

    try:
        view = Views[kind]()
    except KeyError, e:
        raise Exception("view '%s' not supported." % kind)
Exemplo n.º 13
0
def get_widget(type, view="form"):
    """Get the widget of the given type for the given view.

    @param view: the view
    @param type: the widget type
    """

    pool = pooler.get_pool()
    return pool.get(type, group=view)
Exemplo n.º 14
0
    def end(self, **kw):

        if 'wizard_parent_params' in cherrypy.session:
            frm = cherrypy.session['wizard_parent_form']
            params = cherrypy.session['wizard_parent_params']
            try:
                return pooler.get_pool().get_controller(frm).create(params)
            except:
                pass

        import actions
        return actions.close_popup()
Exemplo n.º 15
0
    def end(self, **kw):

        if 'wizard_parent_params' in cherrypy.session:
            frm = cherrypy.session['wizard_parent_form']
            params = cherrypy.session['wizard_parent_params']
            try:
                return pooler.get_pool().get_controller(frm).create(params)
            except:
                pass

        import actions
        return actions.close_popup()
Exemplo n.º 16
0
def load_addons(db_name, config):
    if db_name in _loaded:
        return
    cherrypy.request.loading_addons = True
    _loaded[db_name] = {}
    pooler.get_pool().load('openobject')

    base_addons = [m for m in get_local_addons() if get_info(m).get("active")]

    graph = create_graph(base_addons)
    load_module_graph(db_name, graph, config)

    try:
        new_modules = get_new_modules()
    except errors.AuthenticationError:
        new_modules = []

    new_modules_in_graph = upgrade_graph(graph, new_modules)
    if new_modules_in_graph:
        load_module_graph(db_name, graph, config)

    cherrypy.request.loading_addons = False
Exemplo n.º 17
0
    def find_handler(self):
        request = cherrypy.request
        path = request.path_info

        pool = request.pool = pooler.get_pool()

        names = [x for x in path.strip("/").split("/") if x] + ["index"]
        node = pool.get_controller("/openerp")
        trail = [["/", node]]

        curpath = ""

        for name in names:
            objname = name.replace(".", "_")
            curpath = "/".join((curpath, name))
            next = pool.get_controller(curpath)
            if next is not None:
                node = next
            else:
                node = getattr(node, objname, None)
            trail.append([curpath, node])

        # Try successive objects (reverse order)
        num_candidates = len(trail) - 1
        for i in xrange(num_candidates, -1, -1):
            curpath, candidate = trail[i]
            if candidate is None:
                continue

            # Try a "default" method on the current leaf.
            if hasattr(candidate, "default"):
                defhandler = candidate.default
                if getattr(defhandler, "exposed", False):
                    request.is_index = path.endswith("/")
                    return defhandler, names[i:-1]

            # Try the current leaf.
            if getattr(candidate, "exposed", False):
                if i == num_candidates:
                    # We found the extra ".index". Mark request so tools
                    # can redirect if path_info has no trailing slash.
                    request.is_index = True
                else:
                    # We're not at an 'index' handler. Mark request so tools
                    # can redirect if path_info has NO trailing slash.
                    # Note that this also includes handlers which take
                    # positional parameters (virtual paths).
                    request.is_index = False
                return candidate, names[i:-1]

        return None, []
Exemplo n.º 18
0
    def find_handler(self):
        request = cherrypy.request
        path = request.path_info

        pool = request.pool = pooler.get_pool()

        names = [x for x in path.strip("/").split("/") if x] + ["index"]
        node = pool.get_controller("/openerp")
        trail = [["/", node]]

        curpath = ""

        for name in names:
            objname = name.replace(".", "_")
            curpath = "/".join((curpath, name))
            next = pool.get_controller(curpath)
            if next is not None:
                node = next
            else:
                node = getattr(node, objname, None)
            trail.append([curpath, node])

        # Try successive objects (reverse order)
        num_candidates = len(trail) - 1
        for i in xrange(num_candidates, -1, -1):
            curpath, candidate = trail[i]
            if candidate is None:
                continue

            # Try a "default" method on the current leaf.
            if hasattr(candidate, "default"):
                defhandler = candidate.default
                if getattr(defhandler, 'exposed', False):
                    request.is_index = path.endswith("/")
                    return defhandler, names[i:-1]

            # Try the current leaf.
            if getattr(candidate, 'exposed', False):
                if i == num_candidates:
                    # We found the extra ".index". Mark request so tools
                    # can redirect if path_info has no trailing slash.
                    request.is_index = True
                else:
                    # We're not at an 'index' handler. Mark request so tools
                    # can redirect if path_info has NO trailing slash.
                    # Note that this also includes handlers which take
                    # positional parameters (virtual paths).
                    request.is_index = False
                return candidate, names[i:-1]

        return None, []
Exemplo n.º 19
0
def load_addons(db_name, config):
    if db_name in _loaded:
        return
    cherrypy.request.loading_addons = True
    _loaded[db_name] = {}

    base_addons = [m for m in get_local_addons() if get_info(m).get("active")]

    graph = create_graph(base_addons)
    load_module_graph(db_name, graph, config)

    try:
        obj = pooler.get_pool().get_controller("/openerp/modules")
        new_modules = obj.get_new_modules()
    except errors.AuthenticationError:
        new_modules = []

    new_modules_in_graph = upgrade_graph(graph, new_modules)
    if new_modules_in_graph:
        load_module_graph(db_name, graph, config)

    cherrypy.request.loading_addons = False
Exemplo n.º 20
0
    def default(self, *args, **kw):
        # If we don't set it to a `False` default, we're probably going to
        # throw *a lot* which we don't want.
        cherrypy.request.loading_addons = False
        autoreloader_enabled = bool(
            getattr(cherrypy.engine.autoreload, 'thread', None))
        if autoreloader_enabled:
            # stop (actually don't listen to) the auto-reloader the process
            # doesn't restart due to downloading new add-ons or refreshing
            # existing ones
            cherrypy.engine.autoreload.unsubscribe()
        try:
            obj = pooler.get_pool().get_controller("/openerp/modules")
            if not obj:
                raise RuntimeError(
                    "Cannot find controller for /openerp/modules")
            if obj.has_new_modules():
                pooler.restart_pool()
        except AuthenticationError:
            pass

        if autoreloader_enabled:
            # re-enable auto-reloading if it was enabled before
            cherrypy.engine.autoreload.subscribe()

        request = cherrypy.request
        self.clean_headers_params(request)
        func, vpath = self.find_handler()

        if func:
            # Decode any leftover %2F in the virtual_path atoms.
            vpath = [x.replace("%2F", "/") for x in vpath]
            request.handler = cherrypy.dispatch.LateParamPageHandler(
                func, *vpath)
        else:
            request.handler = cherrypy.NotFound()

        return request.handler()