def get(self, attr_name=None, attr_id=None): attr_manager = AttributeManager() attr_dict = None if attr_name is not None: attr_dict = attr_manager.get_attribute_by_name(attr_name) if attr_dict is None: attr_dict = attr_manager.get_attribute_by_alias(attr_name) elif attr_id is not None: attr_dict = attr_manager.get_attribute_by_id(attr_id) if attr_dict is not None: return self.jsonify(attribute=attr_dict) abort(404, "Attribute is not found")
def get_show_attributes(type_id): if not isinstance(type_id, six.integer_types): type_id = CITypeCache.get(type_id).id attrs = db.session.query( PreferenceShowAttributes, CITypeAttribute.order).join( CITypeAttribute, CITypeAttribute.attr_id == PreferenceShowAttributes.attr_id ).filter(PreferenceShowAttributes.uid == g.user.uid).filter( PreferenceShowAttributes.type_id == type_id).filter( PreferenceShowAttributes.deleted.is_(False)).filter( CITypeAttribute.deleted.is_(False)).filter( CITypeAttribute.type_id == type_id).order_by( CITypeAttribute.order).all() result = [i.PreferenceShowAttributes.attr.to_dict() for i in attrs] is_subscribed = True if not attrs: attrs = db.session.query(CITypeAttribute).filter( CITypeAttribute.type_id == type_id).filter( CITypeAttribute.deleted.is_(False)).filter( CITypeAttribute.default_show.is_(True)).order_by( CITypeAttribute.order) result = [i.attr.to_dict() for i in attrs] is_subscribed = False for i in result: if i["is_choice"]: i.update( dict(choice_value=AttributeManager.get_choice_values( i["id"], i["value_type"]))) return is_subscribed, result
def put(self, attr_id): choice_value = handle_arg_list(request.values.get("choice_value")) params = request.values params["choice_value"] = choice_value current_app.logger.debug(params) AttributeManager().update(attr_id, **params) return self.jsonify(attr_id=attr_id)
def post(self): choice_value = handle_arg_list(request.values.get("choice_value")) params = request.values params["choice_value"] = choice_value current_app.logger.debug(params) attr_id = AttributeManager.add(**params) return self.jsonify(attr_id=attr_id)
def get_attributes_by_type_id(type_id): attrs = CITypeAttributesCache.get(type_id) result = list() for attr in sorted(attrs, key=lambda x: (x.order, x.id)): attr_dict = AttributeManager().get_attribute(attr.attr_id) attr_dict["is_required"] = attr.is_required attr_dict["order"] = attr.order attr_dict["default_show"] = attr.default_show result.append(attr_dict) return result
def get(self): name = request.values.get("name") alias = request.values.get("alias") page = get_page(request.values.get("page", 1)) page_size = get_page_size(request.values.get("page_size")) numfound, res = AttributeManager.search_attributes(name=name, alias=alias, page=page, page_size=page_size) return self.jsonify(page=page, page_size=page_size, numfound=numfound, total=len(res), attributes=res)
def delete(self, attr_id): attr_name = AttributeManager.delete(attr_id) return self.jsonify(message="attribute {0} deleted".format(attr_name))
def get(self): q = request.values.get("q") attrs = AttributeManager().get_attributes(name=q) count = len(attrs) return self.jsonify(numfound=count, attributes=attrs)
def __check_is_choice(attr, value_type, value): choice_values = AttributeManager.get_choice_values(attr.id, value_type) if value not in choice_values: return abort(400, "{0} does not existed in choice values".format(value))