def data(id=None): if request.method == "GET": fields = Field.query.all() json_lists = [field.serialize() for field in fields] return jsonify(json_lists), 200 if request.method == "POST": field = Field() field.title = request.json.get("title") field.price = request.json.get("price") field.address = request.json.get("address") field.players_capacity = request.json.get("players_capacity") field.type_of_soil = request.json.get("type_of_soil") field.type_of_sport = request.json.get("type_of_sport") field.description = request.json.get("description") field.schedule = request.json.get("schedule") field.service_selected = request.json.get("service_selected") db.session.add(field) db.session.commit() return jsonify(field.serialize()), 201 if request.method == "DELETE": if id is not None: field = Field.query.get(id) db.session.delete(field) db.session.commit() return jsonify({"msg": "Field has been deleted"}), 201
def _getFields(self, xml): if xml.nodeName != "table": raise ValueError("Is not a table") fields = [] for field in xml.getElementsByTagName("field"): tmp = Field() domain = Domain() for attributeName, attributeValue in field.attributes.items(): if attributeName.lower() == "name": tmp.name = attributeValue elif attributeName.lower() == "rname": tmp.rname = attributeValue elif attributeName == "domain": tmp.domain = attributeValue elif attributeName.lower() == "domain.name": domain.name = attributeValue elif attributeName.lower() == "domain.char_length": domain.char_length = attributeValue elif attributeName.lower() == "domain.precision": domain.precision = attributeValue elif attributeName.lower() == "domain.scale": domain.scale = attributeValue elif attributeName.lower() == "domain.type": domain.type = attributeValue elif attributeName.lower() == "description": tmp.description = attributeValue elif attributeName.lower() == "props": for prop in attributeValue.split(", "): if prop == "input": tmp.input = True elif prop == "edit": tmp.edit = True elif prop == "show_in_grid": tmp.show_in_grid = True elif prop == "show_in_details": tmp.show_in_details = True elif prop == "is_mean": tmp.is_mean = True elif prop == "autocalculated": tmp.autocalculated = True elif prop == "required": tmp.required = True else: raise ValueError( "Invalid format of props string: {}".format( attributeValue)) else: raise ValueError( "Incorrect attribute name \"{}\" in tag \"{}\" ". format(attributeName, field.nodeName)) if tmp.domain is None: tmp.domain = domain fields.append(tmp) return fields