def validate_new_chain(chain_json): chain = chain_json['chain'] validation_error = NFTValidationError('chain') # JSON errors if not chain: raise abort(400, 'No "chain" field in chain json') if not chain['table']: raise abort(400, 'Chain has no table associated') if not chain['table'] in [ t['id'] for t in table_wrapper.list_all_tables() ]: raise abort( 400, 'The table {table_id} doesn\'t exist'.format(chain['table'])) # Validate hook and type? # Validation errors if not chain['name']: validation_error.add_error('name', 'Este campo es necesario.') # If no hook or type is specified, no priority is needed # if chain['priority'] == None: # Use this instead of "not" because 0 is true # validation_error.errors.append({'priority': 'Este campo es necesario.'}) # Return if validation_error.has_errors(): raise validation_error else: return chain
def tables(): ''' GET: List all tables in the system POST: Create a new table in the system ''' if request.method == 'POST': try: table_json = table_validator.validate_new_table(request.get_json()) table = table_wrapper.create_table(table_json) response = jsonify(table=table) response.status_code = 201 return response except NFTValidationError as e: return abort(400, e) except NFTError as e: return abort(500, e) else: return jsonify(tables=table_wrapper.list_all_tables())
def validate_new_chain(chain_json): chain = chain_json['chain'] validation_error = NFTValidationError('chain') # JSON errors if not chain: raise abort(400, 'No "chain" field in chain json') if not chain['table']: raise abort(400, 'Chain has no table associated') if not chain['table'] in [t['id'] for t in table_wrapper.list_all_tables()]: raise abort(400, 'The table {table_id} doesn\'t exist'.format(chain['table'])) # Validate hook and type? # Validation errors if not chain['name']: validation_error.add_error('name', 'Este campo es necesario.') # If no hook or type is specified, no priority is needed # if chain['priority'] == None: # Use this instead of "not" because 0 is true # validation_error.errors.append({'priority': 'Este campo es necesario.'}) # Return if validation_error.has_errors(): raise validation_error else: return chain