remove interpretation label

This commit is contained in:
SvyatoslavArtymovych 2023-05-18 15:37:55 +03:00
parent c1579a7715
commit 7ab0eb1dec
12 changed files with 3214 additions and 58 deletions

View File

@ -99,25 +99,4 @@ def create_breadcrumbs(
label=section.label,
)
]
if interpretation_id:
interpretation: m.Interpretation = db.session.get(
m.Interpretation, interpretation_id
)
crumples += [
s.BreadCrumb(
type=s.BreadCrumbType.Interpretation,
url=url_for(
"book.qa_view",
book_id=book_id,
collection_id=collection_path[0],
sub_collection_id=collection_path[-1]
if len(collection_path) == 2
else collection_path[0],
section_id=section_id,
interpretation_id=interpretation_id,
),
label=interpretation.label,
)
]
return crumples

View File

@ -1,6 +1,6 @@
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import DataRequired, Length
from wtforms.validators import DataRequired
class BaseInterpretationForm(FlaskForm):
@ -9,7 +9,6 @@ class BaseInterpretationForm(FlaskForm):
class CreateInterpretationForm(BaseInterpretationForm):
label = StringField("Label", [DataRequired(), Length(3, 256)])
section_id = StringField("Interpretation ID", [DataRequired()])
submit = SubmitField("Create")

View File

@ -7,7 +7,6 @@ from app.models.utils import BaseModel
class Interpretation(BaseModel):
__tablename__ = "interpretations"
label = db.Column(db.String(256), unique=False, nullable=False)
text = db.Column(db.Text, unique=False, nullable=False)
approved = db.Column(db.Boolean, default=False)
marked = db.Column(db.Boolean, default=False)
@ -55,4 +54,4 @@ class Interpretation(BaseModel):
return self.section.version.book
def __repr__(self):
return f"<{self.id}: {self.label}>"
return f"<{self.id}: {self.text[:15]}>"

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,7 @@
{% extends 'base.html' %}
{% if current_user.is_authenticated %}
{% include 'book/delete_interpretation_modal.html' %}
{% include 'book/delete_comment_modal.html' %}
@ -21,7 +21,7 @@
<div class="shadow-md mt-5 md:mr-64 h-auto overflow-x-hidden">
<div class="ql-snow mt-20">
<h1 class="text-l font-extrabold dark:text-white ml-4 truncate">
{{ interpretation.label }}
{{ section.label }}
</h1>
<div class="ql-editor-readonly text-lg dark:text-white p-3">{{interpretation.text|safe}}</div>
</div>

View File

@ -814,7 +814,6 @@ def interpretation_create(
if form.validate_on_submit():
interpretation: m.Interpretation = m.Interpretation(
label=form.label.data,
text=form.text.data,
section_id=section_id,
user_id=current_user.id,

View File

@ -113,14 +113,12 @@ def create_dummy_data():
# - interpretation 4
interpretation_1 = m.Interpretation(
label="Dummy Interpretation 1 Label",
text="Dummy Interpretation 1 About",
section_id=section_1_1.id,
user_id=user.id,
).save()
interpretation_2 = m.Interpretation(
label="Dummy Interpretation 2 Label",
text="Dummy Interpretation 2 About",
section_id=section_2_1_1.id,
user_id=user.id,
@ -128,7 +126,6 @@ def create_dummy_data():
).save()
interpretation_3 = m.Interpretation(
label="Dummy Interpretation 3 Label",
text="Dummy Interpretation 3 About",
section_id=section_2_1_2.id,
user_id=user.id,
@ -136,7 +133,6 @@ def create_dummy_data():
).save()
m.Interpretation(
label="Dummy Interpretation 4 Label",
text="Dummy Interpretation 4 About",
section_id=section_2_1_2.id,
user_id=user.id,

View File

@ -818,18 +818,17 @@ def test_crud_interpretation(client: FlaskClient, runner: FlaskCliRunner):
version_id=book.last_version.id,
).save()
label_1 = "Test Interpretation #1 Label"
text_1 = "Test Interpretation #1 Text"
response: Response = client.post(
f"/book/{book.id}/{collection.id}/{sub_collection.id}/{section_in_subcollection.id}/create_interpretation",
data=dict(section_id=section_in_subcollection.id, label=label_1, text=text_1),
data=dict(section_id=section_in_subcollection.id, text=text_1),
follow_redirects=True,
)
assert response.status_code == 200
interpretation: m.Interpretation = m.Interpretation.query.filter_by(
label=label_1, section_id=section_in_subcollection.id
section_id=section_in_subcollection.id, text=text_1
).first()
assert interpretation
assert interpretation.section_id == section_in_subcollection.id
@ -837,13 +836,13 @@ def test_crud_interpretation(client: FlaskClient, runner: FlaskCliRunner):
response: Response = client.post(
f"/book/{book.id}/{leaf_collection.id}/{section_in_collection.id}/create_interpretation",
data=dict(section_id=section_in_collection.id, label=label_1, text=text_1),
data=dict(section_id=section_in_collection.id, text=text_1),
follow_redirects=True,
)
assert response.status_code == 200
interpretation: m.Interpretation = m.Interpretation.query.filter_by(
label=label_1, section_id=section_in_collection.id
text=text_1, section_id=section_in_collection.id
).first()
assert interpretation
assert interpretation.section_id == section_in_collection.id
@ -851,7 +850,7 @@ def test_crud_interpretation(client: FlaskClient, runner: FlaskCliRunner):
response: Response = client.post(
f"/book/{book.id}/{collection.id}/999/create_section",
data=dict(collection_id=999, label=label_1, text=text_1),
data=dict(collection_id=999, text=text_1),
follow_redirects=True,
)
@ -860,7 +859,7 @@ def test_crud_interpretation(client: FlaskClient, runner: FlaskCliRunner):
response: Response = client.post(
f"/book/{book.id}/{leaf_collection.id}/999/create_interpretation",
data=dict(collection_id=999, label=label_1, text=text_1),
data=dict(collection_id=999, text=text_1),
follow_redirects=True,
)
@ -869,7 +868,7 @@ def test_crud_interpretation(client: FlaskClient, runner: FlaskCliRunner):
response: Response = client.post(
f"/book/{book.id}/{collection.id}/{sub_collection.id}/888/create_interpretation",
data=dict(collection_id=999, label=label_1, text=text_1),
data=dict(collection_id=999, text=text_1),
follow_redirects=True,
)
@ -879,17 +878,16 @@ def test_crud_interpretation(client: FlaskClient, runner: FlaskCliRunner):
# edit
m.Interpretation(
label="Test", text="Test", section_id=section_in_collection.id, user_id=user.id
text="Test", section_id=section_in_collection.id, user_id=user.id
).save()
m.Interpretation(
label="Test",
text="Test",
section_id=section_in_subcollection.id,
).save()
interpretation: m.Interpretation = m.Interpretation.query.filter_by(
label=label_1, section_id=section_in_collection.id
section_id=section_in_collection.id
).first()
new_label = "Test Interpretation #1 Label(edited)"
@ -898,7 +896,6 @@ def test_crud_interpretation(client: FlaskClient, runner: FlaskCliRunner):
response: Response = client.post(
f"/book/{book.id}/{leaf_collection.id}/{section_in_collection.id}/{interpretation.id}/edit_interpretation",
data=dict(
label=new_label,
interpretation_id=interpretation.id,
text=new_text,
),
@ -908,7 +905,7 @@ def test_crud_interpretation(client: FlaskClient, runner: FlaskCliRunner):
assert b"Success!" in response.data
edited_interpretation: m.Interpretation = m.Interpretation.query.filter_by(
label=new_label, text=new_text, id=interpretation.id
text=new_text, id=interpretation.id
).first()
assert edited_interpretation
@ -916,7 +913,6 @@ def test_crud_interpretation(client: FlaskClient, runner: FlaskCliRunner):
f"/book/{book.id}/{leaf_collection.id}/{section_in_collection.id}/999/edit_interpretation",
data=dict(
interpretation_id=interpretation.id,
label=new_label,
text=new_text,
),
follow_redirects=True,
@ -1018,7 +1014,7 @@ def test_crud_comment(client: FlaskClient, runner: FlaskCliRunner):
assert response.status_code == 200
interpretation: m.Interpretation = m.Interpretation.query.filter_by(
label=label_1, section_id=section_in_subcollection.id
section_id=section_in_subcollection.id
).first()
assert interpretation
assert interpretation.section_id == section_in_subcollection.id
@ -1170,7 +1166,7 @@ def test_interpretation_in_home_last_inter_section(
assert response.status_code == 200
interpretation: m.Interpretation = m.Interpretation.query.filter_by(
label=label_1, section_id=section_in_subcollection.id
section_id=section_in_subcollection.id
).first()
assert interpretation
assert interpretation.section_id == section_in_subcollection.id
@ -1184,7 +1180,7 @@ def test_interpretation_in_home_last_inter_section(
assert response.status_code == 200
interpretation: m.Interpretation = m.Interpretation.query.filter_by(
label=label_1, section_id=section_in_collection.id
section_id=section_in_collection.id
).first()
assert interpretation
assert interpretation.section_id == section_in_collection.id

View File

@ -24,7 +24,7 @@ def test_approved_interpretations(client: FlaskClient):
section: m.Section = m.Section.query.first()
assert section
interpretation: m.Interpretation = m.Interpretation(
section_id=section.id, label="231", text="123", approved=True
section_id=section.id, text="123", approved=True
).save()
assert len(book.approved_interpretations) == 2
@ -43,7 +43,7 @@ def test_approved_interpretations(client: FlaskClient):
label="123", collection_id=sub_collection.id, version_id=book.last_version.id
).save()
interpretation: m.Interpretation = m.Interpretation(
section_id=section.id, label="231", text="123", approved=True
section_id=section.id, text="123", approved=True
).save()
assert len(book.approved_interpretations) == 2

View File

@ -149,7 +149,7 @@ def test_dummy_data(runner: FlaskCliRunner):
# - interpretation 4
interpretation_1: m.Interpretation = m.Interpretation.query.filter_by(
label="Dummy Interpretation 1 Label"
text="Dummy Interpretation 1 About"
).first()
assert interpretation_1
@ -157,7 +157,7 @@ def test_dummy_data(runner: FlaskCliRunner):
assert interpretation_1.section == section_1_1
interpretation_2: m.Interpretation = m.Interpretation.query.filter_by(
label="Dummy Interpretation 2 Label"
text="Dummy Interpretation 2 About"
).first()
assert interpretation_2
@ -166,7 +166,7 @@ def test_dummy_data(runner: FlaskCliRunner):
assert interpretation_2.section == section_2_1_1
interpretation_3: m.Interpretation = m.Interpretation.query.filter_by(
label="Dummy Interpretation 3 Label"
text="Dummy Interpretation 3 About"
).first()
assert interpretation_3
@ -175,7 +175,7 @@ def test_dummy_data(runner: FlaskCliRunner):
assert interpretation_3.section == section_2_1_2
interpretation_4: m.Interpretation = m.Interpretation.query.filter_by(
label="Dummy Interpretation 3 Label"
text="Dummy Interpretation 3 About"
).first()
assert interpretation_4

View File

@ -21,7 +21,6 @@ def test_upvote_interpretation(client: FlaskClient):
assert response.json["message"] == "Interpretation not found"
interpretation = m.Interpretation(
label="Test Interpretation 1 Label",
text="Test Interpretation 1 Text",
user_id=user.id,
).save()

View File

@ -46,7 +46,6 @@ def create_test_book(owner_id: int, entity_id: int = randint(1, 100)):
interpretation: m.Interpretation = m.Interpretation(
section_id=section.id,
label=f"Interpretation {entity_id}",
text=f"Interpretation Text {entity_id}",
user_id=owner_id,
).save()