def save_body(path, d, m, env): if d['type'] == 'leaf': original = copy.copy(m) model.check(path, m) errors = [] if m['to'] and m['from'] and m['to'] < m['from']: errors.extend(('to', 'from')) if (not 'load' in original or original['load'] == '') and (not 'effort' in original or original['effort'] == ''): errors.extend(('load', 'effort')) if len(errors) > 0: raise model.ParseException(original, errors) model.create(path) model.save(path, m) return "\n", model.parent(path) if d['type'] == 'list' and 'name' in m: name = m['name'] name = name.replace('?', '') name = name.replace('/', '') name = name.replace('#', '') new_path = path + "/" + name if path.strip() == '': return "\n", path model.create(new_path) if model.describe(new_path)['type'] == 'leaf' or model.describe( new_path)['type'] == 'render': model.save(new_path, {'name': m['name']}) return "\n", new_path return None, path
def save_body(path, d, m, env): if d['type'] == 'leaf': original=copy.copy(m) model.check(path, m) errors = [] if m['to'] and m['from'] and m['to'] < m['from']: errors.extend( ('to','from') ) if (not 'load' in original or original['load'] == '') and (not 'effort' in original or original['effort'] == ''): errors.extend( ('load', 'effort') ) if len(errors) > 0: raise model.ParseException(original, errors) model.create(path) model.save(path, m) return "\n", model.parent(path) if d['type'] == 'list' and 'name' in m: name = m['name'] name = name.replace('?', '') name = name.replace('/', '') name = name.replace('#', '') new_path = path+"/"+name if path.strip() == '': return "\n", path model.create(new_path) if model.describe(new_path)['type'] == 'leaf' or model.describe(new_path)['type'] == 'render': model.save(new_path, { 'name': m['name'] }) return "\n", new_path return None, path
def get_body(path, d, m, env): parent_type = None parent = model.parent(path) qs = urlparse.parse_qs(env['QUERY_STRING']) refreshable = 0 if parent: parent_type = model.describe(parent)['type'] if 'cache' in d: refreshable = 1 variables = { 'context': '/', 'path':path, 'parent_type': parent_type, 'qs': qs, 'refreshable': refreshable, 'url' : path+"/"} if d['type'] == 'leaf': for k,v in m.iteritems(): if v and type(v) == datetime.date: m[k]=v.strftime('%d.%m.%Y') if type(v) == float and v == int(v): m[k] = int(v) if v == 0 or v == 0.0: m[k] = '' errors = () if 'e' in qs: errors = qs['e'] for k in m.keys(): if k in qs: m[k] = qs[k][0] variables.update({ 'attributes': m, 'errors': errors }) return str(task_template(searchList=[ variables ])), None else: variables.update( { 'list' : m, 'type': d['type'] }) return str(list_template(searchList=[ variables ])), None
def handle(env, start_response, handler, m=None): path = get_path(env) if len(path) > 0 and not path[-1] == '/': start_response('302 Redirect', [('Location', model.normalize(path) + "/")]) return path = model.normalize(path) try: d = model.describe(path) qs = urlparse.parse_qs(env['QUERY_STRING']) if not m and 'cache' in d: if 'r' in qs and qs['r'][0] == '1': if d['cache'] == 'normal': model.invalidate_cache(path) if d['cache'] == 'parent': model.invalidate_cache(model.parent(path)) if d and d['type'] == 'render' and env['REQUEST_METHOD'] == 'GET': parameters = {} if 'parameters' in d: parameters = d['parameters'] content, mime = render_handlers[d['function']](path, parameters, env) start_response('200 OK', [('Content-Type', mime), ('Content-Length', str(len(content)))]) return content if not m: m = model.load(path) content, redirect = handler(path, d, m, env) if redirect: redirect = model.normalize(redirect) close = '' if 'c' in qs: if qs['c'][0] == '0': close = '?c=1' if qs['c'][0] == '1': close = '?c=2' start_response('302 Redirect', [('Location', redirect + "/" + close)]) return else: start_response('200 OK', [('Content-Type', 'text/html;charset=utf-8'), ('Content-Length', str(len(content)))]) return content except model.NotFoundException as e: import traceback traceback.print_exc() raise restlite.Status, '404 Not Found' except model.ParseException as e: d = {} d.update({'e': e.errors}) d.update(e.attributes) start_response('302 Redirect', [('Location', model.normalize(path) + "/?" + urllib.urlencode(d, True))]) return
def handle(env, start_response, handler, m=None): path = get_path(env) if len(path) > 0 and not path[-1] == '/': start_response('302 Redirect', [('Location', model.normalize(path)+"/")]) return path = model.normalize(path) try: d = model.describe(path) qs = urlparse.parse_qs(env['QUERY_STRING']) if not m and 'cache' in d: if 'r' in qs and qs['r'][0]=='1': if d['cache'] == 'normal': model.invalidate_cache(path) if d['cache'] == 'parent': model.invalidate_cache(model.parent(path)) if d and d['type'] == 'render' and env['REQUEST_METHOD'] == 'GET': parameters = {} if 'parameters' in d: parameters = d['parameters'] content, mime = render_handlers[d['function']](path, parameters, env) start_response('200 OK', [('Content-Type', mime), ('Content-Length', str(len(content)))]) return content if not m: m = model.load(path) content, redirect = handler(path, d, m, env) if redirect: redirect = model.normalize(redirect) close='' if 'c' in qs: if qs['c'][0]=='0': close='?c=1' if qs['c'][0]=='1': close='?c=2' start_response('302 Redirect', [('Location', redirect+"/"+close)]) return else: start_response('200 OK', [('Content-Type', 'text/html;charset=utf-8'), ('Content-Length', str(len(content)))]) return content except model.NotFoundException as e: import traceback traceback.print_exc() raise restlite.Status, '404 Not Found' except model.ParseException as e: d = {} d.update( { 'e': e.errors } ) d.update(e.attributes) start_response('302 Redirect', [('Location', model.normalize(path)+"/?"+urllib.urlencode(d, True))]) return
def get_body(path, d, m, env): parent_type = None parent = model.parent(path) qs = urlparse.parse_qs(env['QUERY_STRING']) refreshable = 0 if parent: parent_type = model.describe(parent)['type'] if 'cache' in d: refreshable = 1 variables = { 'context': '/', 'path': path, 'parent_type': parent_type, 'qs': qs, 'refreshable': refreshable, 'url': path + "/" } if d['type'] == 'leaf': for k, v in m.iteritems(): if v and type(v) == datetime.date: m[k] = v.strftime('%d.%m.%Y') if type(v) == float and v == int(v): m[k] = int(v) if v == 0 or v == 0.0: m[k] = '' errors = () if 'e' in qs: errors = qs['e'] for k in m.keys(): if k in qs: m[k] = qs[k][0] variables.update({'attributes': m, 'errors': errors}) return str(task_template(searchList=[variables])), None else: variables.update({'list': m, 'type': d['type']}) return str(list_template(searchList=[variables])), None