def get_form_config(item, formname): """Return the configuration for a given form. The function can handle usuall filebased form configurations and blobforms. The decision if the item is an instance of the a Blobform is done by checking the "fid" foreign key to a form definiton. If present we assume that the item is a blobform item. :item: Item or class for which the want to get the form :formname: name of the form which should be returned :returns: Formconfig """ if inspect.isclass(item): is_blobform = issubclass(item, Blobform) cachename = "%s.%s" % (item.__name__, formname) filename = "%s.xml" % item.__tablename__ else: is_blobform = isinstance(item, Blobform) cachename = "%s.%s" % (item.__class__.__name__, formname) filename = "%s.xml" % item.__class__.__tablename__ name = item.__module__.split(".")[0] with form_lock: if not CACHE_FORM_CONFIG.get(cachename): if is_blobform: config = get_form_config_from_db(item.fid, formname) else: config = get_form_config_from_file(name, filename, formname) CACHE_FORM_CONFIG.set(cachename, config) return CACHE_FORM_CONFIG.get(cachename)
def get_form_config(item, formname): """Return the configuration for a given form. The function can handle usuall filebased form configurations and blobforms. The decision if the item is an instance of the a Blobform is done by checking the "fid" foreign key to a form definiton. If present we assume that the item is a blobform item. :item: Item or class for which the want to get the form :formname: name of the form which should be returned :returns: Formconfig """ if inspect.isclass(item): cachename = "%s.%s" % (item.__name__, formname) filename = "%s.xml" % item.__tablename__ else: cachename = "%s.%s" % (item.__class__.__name__, formname) filename = "%s.xml" % item.__class__.__tablename__ name = item.__module__.split(".")[0] if not CACHE_FORM_CONFIG.get(cachename): if hasattr(item, 'fid'): config = get_form_config_from_db(item.fid, formname) else: config = get_form_config_from_file(name, filename, formname) CACHE_FORM_CONFIG.set(cachename, config) return CACHE_FORM_CONFIG.get(cachename)
def test_clear_cache(): from ringo.lib.cache import CACHE_TABLE_CONFIG, CACHE_FORM_CONFIG CACHE_TABLE_CONFIG.clear() CACHE_FORM_CONFIG.clear()