def delete_attribute_in_type(type_id=None): with argument_required("attr_id"): attr_ids = request.values.get("attr_id", "") attr_id_list = attr_ids.strip().split(",") manager = CITypeAttributeManager() manager.delete(type_id, attr_id_list) return jsonify(attributes=attr_id_list)
def update_attribute(attr_id=None): with argument_required("attr_name"): attr_name = request.values.get("attr_name") attr_alias = request.values.get("attr_alias", attr_name) choice_value = request.values.get("choice_value") is_multivalue = request.values.get("is_multivalue", False) is_uniq = request.values.get("is_uniq", False) value_type = request.values.get("value_type", "text") try: is_multivalue = int(is_multivalue) is_uniq = int(is_uniq) except ValueError: raise InvalidUsageError("argument format is error") attr_manager = AttributeManager() kwargs = { "choice_value": choice_value, "is_multivalue": is_multivalue, "is_uniq": is_uniq, "value_type": value_type } ret, res = attr_manager.update(attr_id, attr_name, attr_alias, **kwargs) if not ret: return abort(500, res) return jsonify(attr_id=res)
def create_attributes_to_citype(type_id=None): with argument_required("attr_id"): attr_ids = request.values.get("attr_id", "") is_required = request.values.get("is_required", False) attr_id_list = attr_ids.strip().split(",") if "" in attr_id_list: attr_id_list.remove("") attr_id_list = map(int, attr_id_list) try: is_required = int(is_required) except ValueError: abort(500, "argument format is error") manager = CITypeAttributeManager() manager.add(type_id, attr_id_list, is_required=is_required) return jsonify(attributes=attr_id_list)
def create_citype(): with argument_required("type_name"): type_name = request.values.get("type_name") type_alias = request.values.get("type_alias") if type_alias is None: type_alias = type_name _id = request.values.get("_id") unique = request.values.get("unique") enabled = request.values.get("enabled", True) icon_url = request.values.get("icon_url", "") manager = CITypeManager() ret, res = manager.add(type_name, type_alias, _id=_id, unique=unique, enabled=enabled, icon_url=icon_url) if ret: return jsonify(type_id=res) abort(500, res)
def query(): with argument_required("type"): _type = request.args.get("type") manager = CITypeManager() res = manager.query(_type) return jsonify(citype=res)