def get_path_to_form_config(filename, app=None, location=None): """Returns the path to the given form configuration. The filename should be realtive to the default `location` for the configurations in the given `app`. :file: Name of the form condifguration. :app: You can define the name of the application from where the form should be loaded. If no name is provied the code will search along the inheritance path of the current application and return the first form configuration it can find. Returns None if no configuration can be found. :location: Default is 'views/forms' you can define an alternative location. :returns: Absolute path to the configuration file """ if location is None: location = "views/forms" if app is None: for app in get_app_inheritance_path(): path = get_path_to(os.path.join(location, filename), app) if os.path.exists(path): return path return path else: return get_path_to(os.path.join(location, filename), app)
def get_form_config_from_file(name, filename, formname): """Return the file based configuration for a given form. The configuration tried to be loaded from the current application first. If this fails it tries to load it from the extension or orign application and finally from the ringo application.""" loaded_config = None for appname in get_app_inheritance_path(): try: # Always first try to load from the current application. No # matter what the current name is as name can be different from # the appname in case of loading forms for an extension. In this # case first try to load the form configuration from the # application to be able to overwrite the forms. loaded_config = load(get_path_to_form_config(filename, appname)) break except IOError: # Silently ignore IOErrors here as is Ok when trying to load the # configurations files while iterating over the possible config # file locations. If the file can finally not be loaded an IOError # is raised at the end. pass else: if name.startswith("ringo_"): loaded_config = load(get_path_to_form_config(filename, name, location=".")) # If we can't load the config file after searching in all locations, raise # an IOError. Hint: Maybe you missed to set the app.base config variable? if loaded_config is None: raise IOError("Could not load form configuration for %s" % filename) return Config(loaded_config).get_form(formname)
def _load_overview_config(clazz): """Return a datastructure representing the overview configuration. The configuration is loaded from a JSON configuration file. The function will first try to load the application specific configuration. If this fails it will try to load it form the extension specific loaction or orign application and finally from ringo. If no configuration can be found an exception is raised.""" cfile = "%s.json" % clazz.__tablename__ config = None name = clazz.__module__.split(".")[0] for appname in get_app_inheritance_path(): try: # Always first try to load from the current application. No # matter what the current name is as name can be different from # the appname in case of loading forms for an extension. In this # case first try to load the form configuration from the # application to be able to overwrite the forms. config = open(get_path_to_overview_config(cfile, appname), "r") break except IOError: # Silently ignore IOErrors here as is Ok when trying to load the # configurations files while iterating over the possible config # file locations. If the file can finally not be loaded an IOError # is raised at the end. pass else: if name.startswith("ringo_"): config = open(get_path_to_overview_config(cfile, name, location="."), "r") # If we can't load the config file after searching in all locations, raise # an IOError. Hint: Maybe you missed to set the app.base config variable? if not config: raise IOError("Could not load table configuration for %s" % cfile) return json.load(config)