def exec_validation(name, col_value, _validation): errors = [] if _validation: for rule_str in _validation: value = col_value['value'] if col_value else None if not validation.validate(rule_str, value): error = u'[V]属性({0})验证规则({1})失败:{2}'.format(name, rule_str, value) errors.append(error) return errors
def collection_list(collection, number=1): limit = int(request.args.get('limit', 10)) offset = int(request.args.get('offset', 0)) data = validate(collection, mongo) query = request.args.get('query', None) order_by = request.args.get('orderBy', None) sort_order = request.args.get('sortOrder', 1) key = request.args.get('key', None) value = request.args.get('value', None) results = db_general.search_collection(mongo, collection, limit, offset, order_by=order_by, sort_order=sort_order, filter_key=key, filter_value=value, query=query) return json_render(results)
def collection_byid(collection, object_id=None): data = validate(collection, mongo) if request.method == 'GET': results = db_general.get_collection_byid(mongo, collection, object_id) ret = {'objects': results} elif request.method == 'PUT': results = db_general.put_collection_byid(mongo, collection, data) ret = results elif request.method == 'DELETE': results = db_general.delete_collection_byid(mongo, collection, object_id) ret = {'result': results} return json_render(ret)
def collection_bykey(collection, key=None): data = validate(collection, mongo) if request.method == 'GET': results = db_general.get_collection_bykey(mongo, collection, key) ret = results elif request.method == 'PUT': results = db_general.put_collection_bykey(mongo, collection, key, data) ret = {'objects': results} elif request.method == 'PATCH': results = db_general.patch_collection_bykey(mongo, collection, key, data) ret = {'results': results} elif request.method == 'DELETE': results = db_general.delete_collection_bykey(mongo, collection, key) ret = {'results': results} return json_render(ret)
def collection_bypage_ordered(collection, number, order_by, sort_order = 1): data = validate(collection, mongo) results = db_general.get_collection_bypage_ordered(mongo, collection, number, order_by, sort_order) ret = {'objects': results, 'page_size': settings.PAGE_SIZE} return json_render(ret)