Ejemplo n.º 1
0
def update_post_tags(
    post: model.Post, tag_names: List[str]
) -> List[model.Tag]:
    assert post
    existing_tags, new_tags = tags.get_or_create_tags_by_names(tag_names)
    post.tags = existing_tags + new_tags
    return new_tags
Ejemplo n.º 2
0
def _create_if_needed(tag_names, user):
    if not tag_names:
        return
    _existing_tags, new_tags = tags.get_or_create_tags_by_names(tag_names)
    if len(new_tags):
        auth.verify_privilege(user, 'tags:create')
    db.session.flush()
    for tag in new_tags:
        snapshots.create(tag, user)
Ejemplo n.º 3
0
def _create_if_needed(tag_names: List[str], user: model.User) -> None:
    if not tag_names:
        return
    _existing_tags, new_tags = tags.get_or_create_tags_by_names(tag_names)
    if len(new_tags):
        auth.verify_privilege(user, "tags:create")
    db.session.flush()
    for tag in new_tags:
        snapshots.create(tag, user)
Ejemplo n.º 4
0
def test_get_or_create_tags_by_names(names, expected_indexes,
                                     expected_created_names, tag_factory,
                                     tag_category_factory, config_injector):
    config_injector({'tag_name_regex': '.*'})
    category = tag_category_factory()
    input_tags = [
        tag_factory(names=['name1', 'ALIAS1'], category=category),
        tag_factory(names=['name2', 'ALIAS2'], category=category),
    ]
    db.session.add_all(input_tags)
    db.session.flush()
    result = tags.get_or_create_tags_by_names(names)
    expected_ids = [input_tags[i].tag_id for i in expected_indexes]
    actual_ids = [tag.tag_id for tag in result[0]]
    actual_created_names = [tag.names[0].name for tag in result[1]]
    assert actual_ids == expected_ids
    assert actual_created_names == expected_created_names
Ejemplo n.º 5
0
def test_get_or_create_tags_by_names(
        names,
        expected_indexes,
        expected_created_names,
        tag_factory,
        tag_category_factory,
        config_injector):
    config_injector({'tag_name_regex': '.*'})
    category = tag_category_factory()
    input_tags = [
        tag_factory(names=['name1', 'ALIAS1'], category=category),
        tag_factory(names=['name2', 'ALIAS2'], category=category),
    ]
    db.session.add_all(input_tags)
    db.session.flush()
    result = tags.get_or_create_tags_by_names(names)
    expected_ids = [input_tags[i].tag_id for i in expected_indexes]
    actual_ids = [tag.tag_id for tag in result[0]]
    actual_created_names = [tag.names[0].name for tag in result[1]]
    assert actual_ids == expected_ids
    assert actual_created_names == expected_created_names
Ejemplo n.º 6
0
def update_post_tags(post, tag_names):
    existing_tags, new_tags = tags.get_or_create_tags_by_names(tag_names)
    post.tags = existing_tags + new_tags
Ejemplo n.º 7
0
def update_post_tags(
        post: model.Post, tag_names: List[str]) -> List[model.Tag]:
    assert post
    existing_tags, new_tags = tags.get_or_create_tags_by_names(tag_names)
    post.tags = existing_tags + new_tags
    return new_tags