当前位置: 首页>>代码示例>>Python>>正文


Python Tag.name_available方法代码示例

本文整理汇总了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)
开发者ID:raghuveerkancherla,项目名称:sync-engine,代码行数:31,代码来源:ns_api.py

示例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)
开发者ID:mdeng1024,项目名称:inbox,代码行数:33,代码来源:ns_api.py

示例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)
开发者ID:admix,项目名称:inbox,代码行数:15,代码来源:ns_api.py

示例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)
开发者ID:mdeng1024,项目名称:inbox,代码行数:20,代码来源:ns_api.py

示例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)
开发者ID:apolmig,项目名称:inbox,代码行数:21,代码来源:ns_api.py

示例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)
开发者ID:jjayyoung,项目名称:inbox,代码行数:24,代码来源:ns_api.py

示例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)
开发者ID:0xcd03,项目名称:inbox,代码行数:26,代码来源:ns_api.py


注:本文中的inbox.models.Tag.name_available方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。