def __check_item(self, ent_str, act_str): from germ.erm.helper import get_entity entity = get_entity(ent_str, self._session, globals()) from germ.erm.helper import get_action action = get_action(act_str, False) from germ.error.error import error try: import cf if not cf.ht_check_items: from germ.error.do_not_exec import do_not_exec raise do_not_exec() entity.accept(action) except error, e: from germ.error.no_valid_keys import no_valid_keys from germ.error.perm_denied import perm_denied from germ.error.do_not_exec import do_not_exec from germ.error.missing_lock import missing_lock from germ.error.missing_pk_lock import missing_pk_lock if isinstance(e, no_valid_keys) or isinstance(e, perm_denied): self._hide += 1 return None elif not (isinstance(e, do_not_exec) or \ isinstance(e, missing_lock) or \ isinstance(e, missing_pk_lock)): import sys exctype, exc, tb = sys.exc_info() raise exctype, exc, tb
def get_content(form, session): import cf # First we get the action object and an entity, then the parameters. # No action means 'just display the page', i.e. we need the 'page' # parameter. p_action = form.getfirst('action', None) p_entity = form.getfirst('entity', None) p_page = form.getfirst('page', None) fullpage = form.has_key('fullpage') if p_action is None: if p_entity is not None: raise error(error.fail, "Request for an entity without an " + "action to act on it", "entity: %s" % p_entity) if p_page is None: p_page = cf.ht_default_page p_action = cf.ht_default_action p_entity = cf.ht_default_entity elif p_entity is None: raise error(error.fail, "Request for an action without an " \ "entity to act on", "action: %s" % p_action) # Get page. page = None if p_page is not None: page = get_page(p_page) if page is None and p_entity is not None: page = get_page(p_entity) if p_action is None: pagetext = '' if page is not None: while True: text = page.read() if not len(text) > 0: break pagetext += text return pagetext # Parse GET parameters. from sets import Set attr_map = {} attr_locks = Set() attr_to_lock = Set() do_exec = False for name, val in [(parm.name, parm_val(parm)) for parm in form.list]: if name.startswith(cf.ht_parm_prefix_attr): # Handle multivalued parameters. pos = name.find('__', len(cf.ht_parm_prefix_attr)) if pos < 0: attr = name[len(cf.ht_parm_prefix_attr):] if attr_map.has_key(attr): if isinstance(attr_map[attr], dict): raise error(error.error, "Multi-valued parameter " \ "overwritten with single-valued parameter", "attribute: %s" % attr) else: # If a single-valued parameter is specified multiple # times, the last occurence counts. pass attr_map[attr] = val else: attr = name[len(cf.ht_parm_prefix_attr):pos] if not attr_map.has_key(attr): attr_map[attr] = {} elif not isinstance(attr_map[attr], dict): raise error(error.error, "Single-valued parameter " \ "overwritten with multi-valued parameter", "attribute: %s" % attr) attr_map[attr][name[pos+2:]] = val elif name == 'lock': attr_locks.add(val) elif name.startswith('to_lock'): attr_to_lock.add(val) elif name == 'do_exec': do_exec = True from germ.erm.helper import get_entity entity = get_entity(p_entity, session, globals()) found_invalid_parm = False for attr, value in attr_map.iteritems(): from germ.error.invalid_parm import invalid_parm try: a = entity.get_attr(attr, p_action) from attr_act_set import attr_act_set a.accept(attr_act_set(value)) except invalid_parm, e: found_invalid_parm = True if attr in attr_locks: raise error(error.fail, "Locked attribute has invalid value", "attr: %s, error: %s" % (attr, e)) elif attr in attr_to_lock: attr_to_lock.remove(attr)