def commit(): # New entry mime = CTK.post.pop('new_mime') exts = CTK.post.pop('new_exts') mage = CTK.post.pop('new_mage') if mime: if mage: CTK.cfg['mime!%s!max-age'%(mime)] = mage if exts: CTK.cfg['mime!%s!extensions'%(mime)] = exts return CTK.cfg_reply_ajax_ok() # Modifications updates = {} for k in CTK.post: if k.endswith('!extensions'): new = CTK.post[k] try: val = validations.is_safe_mime_exts (new, CTK.cfg.get_val(k)) if util.lists_differ (val, new): updates[k] = val except ValueError, e: return { "ret": "error", "errors": { k: str(e) }} CTK.cfg[k] = CTK.post[k]
def modify(): updates = {} for k in CTK.post: # Presses 'submit' without changing anything if k in ('icons!default', 'icons!directory', 'icons!parent_directory'): if not CTK.post.get_val(k): return {'ret': "error"} # Validations for files and suffixes validator = None if k.startswith('icons!suffix') and CTK.post[k]: validator = validations.is_safe_icons_suffix elif k.startswith ('icons!file') and CTK.post[k]: validator = validations.is_safe_icons_file if validator: new = CTK.post[k] try: val = validator (new, CTK.cfg.get_val(k)) if util.lists_differ (val, new): updates[k] = val except ValueError as e: return {'ret': "error", 'errors': {k: str(e)}} if updates: return {'ret': 'unsatisfactory', 'updates': updates}
def modify(): updates = {} for k in CTK.post: validator = None if k.startswith('icons!suffix') and CTK.post['k']: validator = validations.is_safe_icons_suffix elif k.startswith ('icons!file') and CTK.post['k']: validator = validations.is_safe_icons_file if validator: new = CTK.post[k] try: val = validator (new, CTK.cfg.get_val(k)) if util.lists_differ (val, new): updates[k] = val except ValueError, e: return { "ret": "error", "errors": { k: str(e) }} CTK.cfg[k] = CTK.post[k]
def modify(): updates = {} for k in CTK.post: # Presses 'submit' without changing anything if k in ('icons!default', 'icons!directory', 'icons!parent_directory'): if not CTK.post.get_val(k): return {'ret': "error"} # Validations for files and suffixes validator = None if k.startswith('icons!suffix') and CTK.post[k]: validator = validations.is_safe_icons_suffix elif k.startswith ('icons!file') and CTK.post[k]: validator = validations.is_safe_icons_file if validator: new = CTK.post[k] try: val = validator (new, CTK.cfg.get_val(k)) if util.lists_differ (val, new): updates[k] = val except ValueError, e: return {'ret': "error", 'errors': {k: str(e)}}