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
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)
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)
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
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
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
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