本文整理汇总了Python中inbox.models.Tag.name_available方法的典型用法代码示例。如果您正苦于以下问题:Python Tag.name_available方法的具体用法?Python Tag.name_available怎么用?Python Tag.name_available使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inbox.models.Tag
的用法示例。
在下文中一共展示了Tag.name_available方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tag_update_api
# 需要导入模块: from inbox.models import Tag [as 别名]
# 或者: from inbox.models.Tag import name_available [as 别名]
def tag_update_api(public_id):
try:
valid_public_id(public_id)
tag = g.db_session.query(Tag).filter(
Tag.public_id == public_id,
Tag.namespace_id == g.namespace.id).one()
except NoResultFound:
raise NotFoundError('No tag found')
data = request.get_json(force=True)
if not ('name' in data.keys() and isinstance(data['name'], basestring)):
raise InputError('Malformed tag update request')
if 'namespace_id' in data.keys():
ns_id = data['namespace_id']
valid_public_id(ns_id)
if ns_id != g.namespace.public_id:
raise InputError('Cannot change the namespace on a tag.')
if not tag.user_created:
raise InputError('Cannot modify tag {}'.format(public_id))
# Lowercase tag name, regardless of input casing.
new_name = data['name'].lower()
if new_name != tag.name: # short-circuit rename to same value
if not Tag.name_available(new_name, g.namespace.id, g.db_session):
return err(409, 'Tag name already used')
tag.name = new_name
g.db_session.commit()
return g.encoder.jsonify(tag)
示例2: tag_update_api
# 需要导入模块: from inbox.models import Tag [as 别名]
# 或者: from inbox.models.Tag import name_available [as 别名]
def tag_update_api(public_id):
try:
valid_public_id(public_id)
tag = g.db_session.query(Tag).filter(
Tag.public_id == public_id,
Tag.namespace_id == g.namespace.id).one()
except InputError:
return err(400, '{} is not a valid id'.format(public_id))
except NoResultFound:
return err(404, 'No tag found')
data = request.get_json(force=True)
if 'name' not in data.keys():
return err(400, 'Malformed tag update request')
if 'namespace_id' in data.keys():
ns_id = data['namespace_id']
valid_public_id(ns_id)
if ns_id != g.namespace.id:
return err(400, 'Cannot change the namespace on a tag.')
if not tag.user_created:
return err(403, 'Cannot modify tag {}'.format(public_id))
new_name = data['name']
if new_name != tag.name: # short-circuit rename to same value
if not Tag.name_available(new_name, g.namespace.id, g.db_session):
return err(409, 'Tag name already used')
tag.name = new_name
g.db_session.commit()
# TODO(emfree) also support deleting user-created tags.
return g.encoder.jsonify(tag)
示例3: tag_create_api
# 需要导入模块: from inbox.models import Tag [as 别名]
# 或者: from inbox.models.Tag import name_available [as 别名]
def tag_create_api():
data = request.get_json(force=True)
if data.keys() != ['name']:
return err(400, 'Malformed tag request')
tag_name = data['name']
if not Tag.name_available(tag_name, g.namespace.id, g.db_session):
return err(409, 'Tag name not available')
if len(tag_name) > MAX_INDEXABLE_LENGTH:
return err(400, 'Tag name is too long.')
tag = Tag(name=tag_name, namespace=g.namespace, user_created=True)
g.db_session.commit()
return g.encoder.jsonify(tag)
示例4: tag_create_api
# 需要导入模块: from inbox.models import Tag [as 别名]
# 或者: from inbox.models.Tag import name_available [as 别名]
def tag_create_api():
data = request.get_json(force=True)
if 'name' not in data.keys():
return err(400, 'Malformed tag request')
if 'namespace_id' in data.keys():
ns_id = data['namespace_id']
valid_public_id(ns_id)
if ns_id != g.namespace.id:
return err(400, 'Cannot change the namespace on a tag.')
tag_name = data['name']
if not Tag.name_available(tag_name, g.namespace.id, g.db_session):
return err(409, 'Tag name not available')
if len(tag_name) > MAX_INDEXABLE_LENGTH:
return err(400, 'Tag name is too long.')
tag = Tag(name=tag_name, namespace=g.namespace, user_created=True)
g.db_session.commit()
return g.encoder.jsonify(tag)
示例5: tag_create_api
# 需要导入模块: from inbox.models import Tag [as 别名]
# 或者: from inbox.models.Tag import name_available [as 别名]
def tag_create_api():
data = request.get_json(force=True)
if not ('name' in data.keys() and isinstance(data['name'], basestring)):
raise InputError('Malformed tag request')
if 'namespace_id' in data.keys():
ns_id = data['namespace_id']
valid_public_id(ns_id)
if ns_id != g.namespace.id:
raise InputError('Cannot change the namespace on a tag.')
# Lowercase tag name, regardless of input casing.
tag_name = data['name'].lower()
if not Tag.name_available(tag_name, g.namespace.id, g.db_session):
return err(409, 'Tag name not available')
if len(tag_name) > MAX_INDEXABLE_LENGTH:
raise InputError('Tag name is too long.')
tag = Tag(name=tag_name, namespace=g.namespace, user_created=True)
g.db_session.commit()
return g.encoder.jsonify(tag)
示例6: tag_read_update_api
# 需要导入模块: from inbox.models import Tag [as 别名]
# 或者: from inbox.models.Tag import name_available [as 别名]
def tag_read_update_api(public_id):
try:
valid_public_id(public_id)
tag = g.db_session.query(Tag).filter(Tag.public_id == public_id, Tag.namespace_id == g.namespace.id).one()
except InputError:
return err(400, "{} is not a valid id".format(public_id))
except NoResultFound:
return err(404, "No tag found")
if request.method == "GET":
return g.encoder.jsonify(tag)
elif request.method == "PUT":
data = request.get_json(force=True)
if data.keys() != ["name"]:
return err(400, "Malformed tag update request")
if not tag.user_created:
return err(403, "Cannot modify tag {}".format(public_id))
new_name = data["name"]
if not Tag.name_available(new_name, g.namespace.id, g.db_session):
return err(409, "Tag name already used")
tag.name = new_name
g.db_session.commit()
return g.encoder.jsonify(tag)
示例7: tag_read_update_api
# 需要导入模块: from inbox.models import Tag [as 别名]
# 或者: from inbox.models.Tag import name_available [as 别名]
def tag_read_update_api(public_id):
try:
valid_public_id(public_id)
tag = g.db_session.query(Tag).filter(
Tag.public_id == public_id,
Tag.namespace_id == g.namespace.id).one()
except ValueError:
return err(400, '{} is not a valid id'.format(public_id))
except NoResultFound:
return err(404, 'No tag found')
if request.method == 'GET':
return g.encoder.jsonify(tag)
elif request.method == 'PUT':
data = request.get_json(force=True)
if data.keys() != ['name']:
return err(400, 'Malformed tag update request')
if not tag.user_created:
return err(403, 'Cannot modify tag {}'.format(public_id))
new_name = data['name']
if not Tag.name_available(new_name, g.namespace.id, g.db_session):
return err(409, 'Tag name already used')
tag.name = new_name
g.db_session.commit()
return g.encoder.jsonify(tag)