remove tags from sections

This commit is contained in:
SvyatoslavArtymovych 2023-05-19 15:49:40 +03:00
parent 84bbb26010
commit 7276050bb3
8 changed files with 146430 additions and 139 deletions

View File

@ -98,28 +98,3 @@ def set_interpretation_tags(interpretation: m.InterpretationTag, tags: str):
log(log.INFO, "Create InterpretationTag: [%s]", interpretation_tag)
interpretation_tag.save(False)
db.session.commit()
def set_section_tags(section: m.SectionTag, tags: str):
section_tags = m.SectionTag.query.filter_by(section_id=section.id).all()
for tag in section_tags:
db.session.delete(tag)
tags_names = [tag.title() for tag in tags.split(",") if len(tag)]
for tag_name in tags_names:
try:
tag = get_or_create_tag(tag_name)
except ValueError as e:
if str(e) == "Exceeded name length":
continue
log(
log.CRITICAL,
"Unexpected error [%s]",
str(e),
)
raise e
section_tag = m.SectionTag(tag_id=tag.id, section_id=section.id)
log(log.INFO, "Create SectionTag: [%s]", section_tag)
section_tag.save(False)
db.session.commit()

View File

@ -9,7 +9,6 @@ from app.logger import log
class BaseSectionForm(FlaskForm):
label = StringField("Label", [DataRequired(), Length(3, 256)])
about = StringField("About")
tags = StringField("Tags")
class CreateSectionForm(BaseSectionForm):

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -35,21 +35,6 @@
</div>
</div>
</div>
<div class="multiple-input-block mb-6 px-6 ">
<label for="tags-input" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">
Tags
</label>
<input type="text" name="tags" class="hidden tags-to-submit">
<input
type="text"
id="tags-input"
class="multiple-input mb-3 shadow-sm bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-600 focus:border-blue-600 block w-full p-2.5 dark:bg-gray-600 dark:border-gray-500 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
placeholder="e.g. Law (press 'Enter' or Comma to add tag. Click on tag to edit it)"
data-save-results-to="tags-to-submit"
>
<div class="multiple-input-items gap-1 flex flex-wrap">
</div>
</div>
<!-- Modal footer -->
<div class="flex items-center p-6 space-x-2 border-t border-gray-200 rounded-b dark:border-gray-600">
<button name="submit" type="submit" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Create</button>

View File

@ -37,24 +37,6 @@
</div>
</div>
</div>
<div class="multiple-input-block mb-6 px-6 ">
<label for="tags-input" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">
Tags
</label>
<input type="text" name="tags" class="hidden tags-to-submit">
<input
type="text"
id="tags-input"
class="multiple-input mb-3 shadow-sm bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-600 focus:border-blue-600 block w-full p-2.5 dark:bg-gray-600 dark:border-gray-500 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
placeholder="e.g. Law (press 'Enter' or Comma to add tag. Click on tag to edit it)"
data-save-results-to="tags-to-submit"
>
<div class="multiple-input-items gap-1 flex flex-wrap">
{% for tag in section.tags %}
<div class="cursor-pointer multiple-input-word bg-sky-300 hover:bg-sky-400 dark:bg-blue-600 dark:hover:bg-blue-700 dark:text-white rounded text-center py-1/2 px-2">{{tag.name}}</div>
{% endfor %}
</div>
</div>
<!-- Modal footer -->
<div class="flex items-center p-6 space-x-2 border-t border-gray-200 rounded-b dark:border-gray-600">
<button name="submit" type="submit" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Save</button>

View File

@ -14,7 +14,6 @@ from app.controllers.delete_nested_book_entities import (
delete_nested_section_entities,
)
from app import models as m, db, forms as f
from app.controllers.tags import set_section_tags
from app.logger import log
from .bp import bp
@ -116,10 +115,6 @@ def section_create(
log(log.INFO, "Create section [%s]. Collection: [%s]", section, collection_id)
section.save()
tags = form.tags.data
if tags:
set_section_tags(section, tags)
flash("Success!", "success")
return redirect(redirect_url)
else:
@ -162,10 +157,6 @@ def section_edit(
if label:
section.label = label
tags = form.tags.data
if tags:
set_section_tags(section, tags)
log(log.INFO, "Edit section [%s]", section.id)
section.save()

View File

@ -189,71 +189,3 @@ def test_create_tags_on_interpretation_create_and_edit(client: FlaskClient):
tags_from_db: m.Tag = m.Tag.query.all()
assert len(tags_from_db) == 5
def test_create_tags_on_section_create_and_edit(client: FlaskClient):
_, user = login(client)
create_test_book(user.id, 1)
book: m.Book = db.session.get(m.Book, 1)
collection: m.Collection = db.session.get(m.Collection, 1)
section: m.Section = db.session.get(m.Section, 1)
tags = "tag1,tag2,tag3"
label_1 = "Test Interpretation #1 Label"
text_1 = "Test Interpretation #1 Text"
response: Response = client.post(
f"/book/{book.id}/{collection.id}/create_section",
data=dict(
collection_id=collection.id,
label=label_1,
about=text_1,
tags=tags,
),
follow_redirects=True,
)
assert response.status_code == 200
assert response.status_code == 200
section: m.Section = m.Section.query.filter_by(label=label_1).first()
assert section
assert section.tags
splitted_tags = [tag.title() for tag in tags.split(",")]
assert len(section.tags) == 3
for tag in section.tags:
tag: m.Tag
assert tag.name in splitted_tags
tags_from_db: m.Tag = m.Tag.query.all()
assert len(tags_from_db) == 3
tags = "tag-4,tag5,tag3"
response: Response = client.post(
f"/book/{book.id}/{collection.id}/{section.id}/edit_section",
data=dict(
section_id=section.id,
label=label_1,
about=text_1,
tags=tags,
),
follow_redirects=True,
)
assert response.status_code == 200
assert b"Success!" in response.data
assert response.status_code == 200
section: m.Section = m.Section.query.filter_by(label=label_1).first()
assert section
assert section.tags
splitted_tags = [tag.title() for tag in tags.split(",")]
assert len(section.tags) == 3
for tag in section.tags:
tag: m.Tag
assert tag.name in splitted_tags
tags_from_db: m.Tag = m.Tag.query.all()
assert len(tags_from_db) == 5