Ejemplo n.º 1
0
def set_default_category(category):
    assert category
    old_category = try_get_default_category(lock=True)
    if old_category:
        db.session.refresh(old_category)
        old_category.default = False
    db.session.refresh(category)
    category.default = True
    cache.remove(DEFAULT_CATEGORY_NAME_CACHE_KEY)
Ejemplo n.º 2
0
def set_default_category(category: model.TagCategory) -> None:
    assert category
    old_category = try_get_default_category(lock=True)
    if old_category:
        db.session.refresh(old_category)
        old_category.default = False
    db.session.refresh(category)
    category.default = True
    cache.remove(DEFAULT_CATEGORY_NAME_CACHE_KEY)
Ejemplo n.º 3
0
def update_category_name(category, name):
    assert category
    if not name:
        raise InvalidTagCategoryNameError('Name cannot be empty.')
    expr = sqlalchemy.func.lower(db.TagCategory.name) == name.lower()
    if category.tag_category_id:
        expr = expr & (
            db.TagCategory.tag_category_id != category.tag_category_id)
    already_exists = db.session.query(db.TagCategory).filter(expr).count() > 0
    if already_exists:
        raise TagCategoryAlreadyExistsError(
            'A category with this name already exists.')
    if util.value_exceeds_column_size(name, db.TagCategory.name):
        raise InvalidTagCategoryNameError('Name is too long.')
    _verify_name_validity(name)
    category.name = name
    cache.remove(DEFAULT_CATEGORY_NAME_CACHE_KEY)
Ejemplo n.º 4
0
def update_category_name(category: model.TagCategory, name: str) -> None:
    assert category
    if not name:
        raise InvalidTagCategoryNameError('이름은 빈 값일 수 없습니다.')
    expr = sa.func.lower(model.TagCategory.name) == name.lower()
    if category.tag_category_id:
        expr = expr & (model.TagCategory.tag_category_id !=
                       category.tag_category_id)
    already_exists = (db.session.query(model.TagCategory).filter(expr).count()
                      > 0)
    if already_exists:
        raise TagCategoryAlreadyExistsError('동일한 이름의 카테고리자 존재합니다.')
    if util.value_exceeds_column_size(name, model.TagCategory.name):
        raise InvalidTagCategoryNameError('이름이 너무 깁니다.')
    _verify_name_validity(name)
    category.name = name
    cache.remove(DEFAULT_CATEGORY_NAME_CACHE_KEY)
Ejemplo n.º 5
0
def update_category_name(category: model.TagCategory, name: str) -> None:
    assert category
    if not name:
        raise InvalidTagCategoryNameError("Name cannot be empty.")
    expr = sa.func.lower(model.TagCategory.name) == name.lower()
    if category.tag_category_id:
        expr = expr & (model.TagCategory.tag_category_id !=
                       category.tag_category_id)
    already_exists = (db.session.query(model.TagCategory).filter(expr).count()
                      > 0)
    if already_exists:
        raise TagCategoryAlreadyExistsError(
            "A category with this name already exists.")
    if util.value_exceeds_column_size(name, model.TagCategory.name):
        raise InvalidTagCategoryNameError("Name is too long.")
    _verify_name_validity(name)
    category.name = name
    cache.remove(DEFAULT_CATEGORY_NAME_CACHE_KEY)