mirror of https://github.com/logos-co/open-law.git
Merge pull request #88 from Simple2B/svyat/routes_interpretation
fix interpretation routes
This commit is contained in:
commit
4f8c9bab5a
|
@ -85,12 +85,7 @@ def book_validator() -> Response | None:
|
||||||
flash("Interpretation not found", "danger")
|
flash("Interpretation not found", "danger")
|
||||||
return redirect(
|
return redirect(
|
||||||
url_for(
|
url_for(
|
||||||
"book.qa_view",
|
"book.qa_view", book_id=book_id, interpretation_id=interpretation_id
|
||||||
book_id=book_id,
|
|
||||||
collection_id=collection_id,
|
|
||||||
sub_collection_id=sub_collection_id,
|
|
||||||
section_id=section_id,
|
|
||||||
interpretation_id=interpretation_id,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -101,12 +96,5 @@ def book_validator() -> Response | None:
|
||||||
log(log.WARNING, "Comment with id [%s] not found", comment_id)
|
log(log.WARNING, "Comment with id [%s] not found", comment_id)
|
||||||
flash("Comment not found", "danger")
|
flash("Comment not found", "danger")
|
||||||
return redirect(
|
return redirect(
|
||||||
url_for(
|
url_for("book.qa_view", interpretation_id=interpretation_id)
|
||||||
"book.qa_view",
|
|
||||||
book_id=book_id,
|
|
||||||
collection_id=collection_id,
|
|
||||||
sub_collection_id=sub_collection_id,
|
|
||||||
section_id=section_id,
|
|
||||||
interpretation_id=interpretation_id,
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,18 +6,9 @@ from app import models as m
|
||||||
def build_qa_url_using_interpretation(interpretation: m.Interpretation):
|
def build_qa_url_using_interpretation(interpretation: m.Interpretation):
|
||||||
section: m.Section = interpretation.section
|
section: m.Section = interpretation.section
|
||||||
collection: m.Collection = section.collection
|
collection: m.Collection = section.collection
|
||||||
sub_collection = None
|
|
||||||
if collection.is_leaf and collection.parent.is_root:
|
if collection.is_leaf and collection.parent.is_root:
|
||||||
collection: m.Collection = collection.parent
|
collection: m.Collection = collection.parent
|
||||||
sub_collection: m.Collection = collection
|
|
||||||
book: m.Book = section.version.book
|
book: m.Book = section.version.book
|
||||||
|
|
||||||
url = url_for(
|
url = url_for("book.qa_view", book_id=book.id, interpretation_id=interpretation.id)
|
||||||
"book.qa_view",
|
|
||||||
book_id=book.id,
|
|
||||||
collection_id=collection.id,
|
|
||||||
sub_collection_id=sub_collection.id if sub_collection else None,
|
|
||||||
section_id=section.id,
|
|
||||||
interpretation_id=interpretation.id,
|
|
||||||
)
|
|
||||||
return url
|
return url
|
||||||
|
|
|
@ -39,18 +39,13 @@ def display_tags(text: str):
|
||||||
def build_qa_url_using_interpretation(interpretation: m.Interpretation):
|
def build_qa_url_using_interpretation(interpretation: m.Interpretation):
|
||||||
section: m.Section = interpretation.section
|
section: m.Section = interpretation.section
|
||||||
collection: m.Collection = section.collection
|
collection: m.Collection = section.collection
|
||||||
sub_collection = None
|
|
||||||
if collection.parent and not collection.parent.is_root:
|
if collection.parent and not collection.parent.is_root:
|
||||||
sub_collection: m.Collection = collection
|
|
||||||
collection: m.Collection = collection.parent
|
collection: m.Collection = collection.parent
|
||||||
book: m.Book = section.version.book
|
book: m.Book = section.version.book
|
||||||
|
|
||||||
url = url_for(
|
url = url_for(
|
||||||
"book.qa_view",
|
"book.qa_view",
|
||||||
book_id=book.id,
|
book_id=book.id,
|
||||||
collection_id=collection.id,
|
|
||||||
sub_collection_id=sub_collection.id if sub_collection else None,
|
|
||||||
section_id=section.id,
|
|
||||||
interpretation_id=interpretation.id,
|
interpretation_id=interpretation.id,
|
||||||
)
|
)
|
||||||
return url
|
return url
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -286,7 +286,7 @@
|
||||||
<div class="flex flex-col pb-3 w-full">
|
<div class="flex flex-col pb-3 w-full">
|
||||||
<div class="flex w-full mb-1 dark:text-gray-100 flex-col">
|
<div class="flex w-full mb-1 dark:text-gray-100 flex-col">
|
||||||
<!-- prettier-ignore -->
|
<!-- prettier-ignore -->
|
||||||
<a href="{{url_for('book.interpretation_view',book_id=book.id,collection_id=collection.id,sub_collection_id=sub_collection.id,section_id=section.id)}}">
|
<a href="{{url_for('book.interpretation_view', book_id=book.id, section_id=section.id)}}">
|
||||||
<p id="section-{{section.label}}" class="truncate my-3">{{ section.label }}</p></a>
|
<p id="section-{{section.label}}" class="truncate my-3">{{ section.label }}</p></a>
|
||||||
{% if not section.active_interpretations %}
|
{% if not section.active_interpretations %}
|
||||||
<p class="ml-3 my-3 italic text-sm">This section is empty</p>
|
<p class="ml-3 my-3 italic text-sm">This section is empty</p>
|
||||||
|
@ -342,7 +342,7 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% for section in collection.active_sections %}
|
{% for section in collection.active_sections %}
|
||||||
<a href="{{url_for('book.interpretation_view',book_id=book.id,collection_id=collection.id,section_id=section.id)}}">
|
<a href="{{url_for('book.interpretation_view', book_id=book.id, section_id=section.id)}}">
|
||||||
<p id="section-{{section.label}}" class="truncate my-3">{{ section.label }}</p></a>
|
<p id="section-{{section.label}}" class="truncate my-3">{{ section.label }}</p></a>
|
||||||
{% if not section.active_interpretations %}
|
{% if not section.active_interpretations %}
|
||||||
<p class="ml-3 my-3 italic text-sm">This section is empty</p>
|
<p class="ml-3 my-3 italic text-sm">This section is empty</p>
|
||||||
|
|
|
@ -3,11 +3,7 @@
|
||||||
<div class="relative w-full max-w-2xl max-h-full">
|
<div class="relative w-full max-w-2xl max-h-full">
|
||||||
<!-- Modal content -->
|
<!-- Modal content -->
|
||||||
<form
|
<form
|
||||||
{% if sub_collection %}
|
action="{{ url_for('book.interpretation_delete', book_id=book.id, interpretation_id=interpretation.id) }}"
|
||||||
action="{{ url_for('book.interpretation_delete', book_id=book.id, collection_id=collection.id, sub_collection_id=sub_collection.id, section_id=section.id, interpretation_id=interpretation.id) }}"
|
|
||||||
{% else %}
|
|
||||||
action="{{ url_for('book.interpretation_delete', book_id=book.id, collection_id=collection.id, section_id=section.id, interpretation_id=interpretation.id) }}"
|
|
||||||
{% endif %}
|
|
||||||
method="post" class="relative bg-white rounded-lg shadow dark:bg-gray-700">
|
method="post" class="relative bg-white rounded-lg shadow dark:bg-gray-700">
|
||||||
{{ form_hidden_tag() }}
|
{{ form_hidden_tag() }}
|
||||||
<!-- Modal header -->
|
<!-- Modal header -->
|
||||||
|
|
|
@ -3,11 +3,7 @@
|
||||||
<div class="relative w-full max-w-2xl max-h-full">
|
<div class="relative w-full max-w-2xl max-h-full">
|
||||||
<!-- Modal content -->
|
<!-- Modal content -->
|
||||||
<form
|
<form
|
||||||
{% if sub_collection %}
|
action="{{ url_for('book.interpretation_edit', book_id=book.id, interpretation_id=interpretation.id) }}"
|
||||||
action="{{ url_for('book.interpretation_edit', book_id=book.id, collection_id=collection.id, sub_collection_id=sub_collection.id, section_id=section.id, interpretation_id=interpretation.id) }}"
|
|
||||||
{% else %}
|
|
||||||
action="{{ url_for('book.interpretation_edit', book_id=book.id, collection_id=collection.id, section_id=section.id, interpretation_id=interpretation.id) }}"
|
|
||||||
{% endif %}
|
|
||||||
method="post"
|
method="post"
|
||||||
class="prevent-submit-on-enter relative bg-white rounded-lg shadow dark:bg-gray-700"
|
class="prevent-submit-on-enter relative bg-white rounded-lg shadow dark:bg-gray-700"
|
||||||
>
|
>
|
||||||
|
|
|
@ -44,11 +44,7 @@
|
||||||
{% if current_user.is_authenticated %}
|
{% if current_user.is_authenticated %}
|
||||||
<!-- prettier-ignore -->
|
<!-- prettier-ignore -->
|
||||||
<form
|
<form
|
||||||
{% if sub_collection %}
|
action="{{ url_for('book.interpretation_create', book_id=book.id, section_id=section.id) }}"
|
||||||
action="{{ url_for('book.interpretation_create', book_id=book.id, collection_id=collection.id, sub_collection_id=sub_collection.id,section_id=section.id) }}"
|
|
||||||
{% else %}
|
|
||||||
action="{{ url_for('book.interpretation_create', book_id=book.id, collection_id=collection.id,section_id=section.id) }}"
|
|
||||||
{% endif %}
|
|
||||||
method="post" class="prevent-submit-on-enter bg-white rounded-lg shadow dark:bg-gray-700"
|
method="post" class="prevent-submit-on-enter bg-white rounded-lg shadow dark:bg-gray-700"
|
||||||
>
|
>
|
||||||
{{ form_hidden_tag() }}
|
{{ form_hidden_tag() }}
|
||||||
|
|
|
@ -40,18 +40,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if current_user.is_authenticated %}
|
{% if current_user.is_authenticated %}
|
||||||
<form
|
<form
|
||||||
{%
|
action="{{ url_for('book.create_comment', book_id=book.id, interpretation_id=interpretation.id) }}"
|
||||||
if
|
|
||||||
sub_collection
|
|
||||||
%}
|
|
||||||
action="{{ url_for('book.create_comment', book_id=book.id, collection_id=collection.id, sub_collection_id=sub_collection.id,section_id=section.id,interpretation_id=interpretation.id) }}"
|
|
||||||
{%
|
|
||||||
else
|
|
||||||
%}
|
|
||||||
action="{{ url_for('book.create_comment', book_id=book.id, collection_id=collection.id,section_id=section.id,interpretation_id=interpretation.id) }}"
|
|
||||||
{%
|
|
||||||
endif
|
|
||||||
%}
|
|
||||||
method="post"
|
method="post"
|
||||||
class="prevent-submit-on-enter flex flex-col bg-white dark:bg-gray-900 max-w-full p-3 text-gray-900 divide-y divide-gray-200 dark:text-white dark:divide-gray-700 m-3 border-2 border-gray-200 border-solid rounded-lg dark:border-gray-700">
|
class="prevent-submit-on-enter flex flex-col bg-white dark:bg-gray-900 max-w-full p-3 text-gray-900 divide-y divide-gray-200 dark:text-white dark:divide-gray-700 m-3 border-2 border-gray-200 border-solid rounded-lg dark:border-gray-700">
|
||||||
{{ form_hidden_tag() }}
|
{{ form_hidden_tag() }}
|
||||||
|
@ -237,11 +226,7 @@
|
||||||
<div id="accordion-collapse-body-{{loop.index}}" class="hidden" aria-labelledby="accordion-collapse-heading-1">
|
<div id="accordion-collapse-body-{{loop.index}}" class="hidden" aria-labelledby="accordion-collapse-heading-1">
|
||||||
<div class="p-5 border-t border-gray-200 dark:border-gray-700 dark:bg-gray-900">
|
<div class="p-5 border-t border-gray-200 dark:border-gray-700 dark:bg-gray-900">
|
||||||
<form
|
<form
|
||||||
{% if sub_collection %}
|
action="{{ url_for('book.create_comment', book_id=book.id, interpretation_id=interpretation.id) }}"
|
||||||
action="{{ url_for('book.create_comment', book_id=book.id, collection_id=collection.id, sub_collection_id=sub_collection.id,section_id=section.id,interpretation_id=interpretation.id) }}"
|
|
||||||
{% else %}
|
|
||||||
action="{{ url_for('book.create_comment', book_id=book.id, collection_id=collection.id,section_id=section.id,interpretation_id=interpretation.id) }}"
|
|
||||||
{% endif %}
|
|
||||||
method="post"
|
method="post"
|
||||||
class="prevent-submit-on-enter flex flex-col bg-white dark:bg-gray-900 max-w-full p-3 text-gray-900 dark:text-white dark:divide-gray-700 m-3 border-2 border-gray-200 border-solid rounded-lg dark:border-gray-700"
|
class="prevent-submit-on-enter flex flex-col bg-white dark:bg-gray-900 max-w-full p-3 text-gray-900 dark:text-white dark:divide-gray-700 m-3 border-2 border-gray-200 border-solid rounded-lg dark:border-gray-700"
|
||||||
>
|
>
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<dl class="w-md md:w-full text-gray-900 divide-y divide-gray-200 dark:text-white dark:divide-gray-700">
|
<dl class="w-md md:w-full text-gray-900 divide-y divide-gray-200 dark:text-white dark:divide-gray-700">
|
||||||
{% for section in sections %}
|
{% for section in sections %}
|
||||||
<!-- prettier-ignore -->
|
<!-- prettier-ignore -->
|
||||||
<a href="{{url_for('book.interpretation_view',book_id=section.book_id,collection_id=section.collection_id,sub_collection_id=section.sub_collection_id, section_id=section.id)}}">
|
<a href="{{url_for('book.interpretation_view', book_id=section.book_id, section_id=section.id)}}">
|
||||||
<dl class="bg-white dark:bg-gray-900 max-w-full p-3 text-gray-900 divide-y divide-gray-200 dark:text-white dark:divide-gray-700 m-3 border-2 border-gray-200 border-solid rounded-lg dark:border-gray-700">
|
<dl class="bg-white dark:bg-gray-900 max-w-full p-3 text-gray-900 divide-y divide-gray-200 dark:text-white dark:divide-gray-700 m-3 border-2 border-gray-200 border-solid rounded-lg dark:border-gray-700">
|
||||||
<div class="flex flex-col pb-3 p-3 w-full">
|
<div class="flex flex-col pb-3 p-3 w-full">
|
||||||
<!-- prettier-ignore -->
|
<!-- prettier-ignore -->
|
||||||
|
|
|
@ -59,12 +59,7 @@ def create_comment(
|
||||||
)
|
)
|
||||||
|
|
||||||
redirect_url = url_for(
|
redirect_url = url_for(
|
||||||
"book.qa_view",
|
"book.qa_view", book_id=book_id, interpretation_id=interpretation_id
|
||||||
book_id=book_id,
|
|
||||||
collection_id=collection_id,
|
|
||||||
sub_collection_id=sub_collection_id,
|
|
||||||
section_id=section_id,
|
|
||||||
interpretation_id=interpretation_id,
|
|
||||||
)
|
)
|
||||||
section: m.Section = db.session.get(m.Section, section_id)
|
section: m.Section = db.session.get(m.Section, section_id)
|
||||||
if not section or section.is_deleted:
|
if not section or section.is_deleted:
|
||||||
|
@ -149,12 +144,7 @@ def comment_delete(
|
||||||
flash("Success!", "success")
|
flash("Success!", "success")
|
||||||
return redirect(
|
return redirect(
|
||||||
url_for(
|
url_for(
|
||||||
"book.qa_view",
|
"book.qa_view", book_id=book_id, interpretation_id=interpretation_id
|
||||||
book_id=book_id,
|
|
||||||
collection_id=collection_id,
|
|
||||||
sub_collection_id=sub_collection_id,
|
|
||||||
section_id=section_id,
|
|
||||||
interpretation_id=interpretation_id,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return redirect(
|
return redirect(
|
||||||
|
@ -204,12 +194,7 @@ def comment_edit(
|
||||||
flash("Success!", "success")
|
flash("Success!", "success")
|
||||||
return redirect(
|
return redirect(
|
||||||
url_for(
|
url_for(
|
||||||
"book.qa_view",
|
"book.qa_view", book_id=book_id, interpretation_id=interpretation_id
|
||||||
book_id=book_id,
|
|
||||||
collection_id=collection_id,
|
|
||||||
sub_collection_id=sub_collection_id,
|
|
||||||
section_id=section_id,
|
|
||||||
interpretation_id=interpretation_id,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return redirect(
|
return redirect(
|
||||||
|
|
|
@ -17,19 +17,10 @@ from app.logger import log
|
||||||
from .bp import bp
|
from .bp import bp
|
||||||
|
|
||||||
|
|
||||||
@bp.route(
|
@bp.route("/<int:book_id>/<int:section_id>/interpretations", methods=["GET"])
|
||||||
"/<int:book_id>/<int:collection_id>/<int:section_id>/interpretations",
|
|
||||||
methods=["GET"],
|
|
||||||
)
|
|
||||||
@bp.route(
|
|
||||||
"/<int:book_id>/<int:collection_id>/<int:sub_collection_id>/<int:section_id>/interpretations",
|
|
||||||
methods=["GET"],
|
|
||||||
)
|
|
||||||
def interpretation_view(
|
def interpretation_view(
|
||||||
book_id: int,
|
book_id: int,
|
||||||
collection_id: int,
|
|
||||||
section_id: int,
|
section_id: int,
|
||||||
sub_collection_id: int | None = None,
|
|
||||||
):
|
):
|
||||||
book: m.Book = db.session.get(m.Book, book_id)
|
book: m.Book = db.session.get(m.Book, book_id)
|
||||||
if not book or book.is_deleted:
|
if not book or book.is_deleted:
|
||||||
|
@ -37,25 +28,6 @@ def interpretation_view(
|
||||||
flash("Book not found", "danger")
|
flash("Book not found", "danger")
|
||||||
return redirect(url_for("book.my_library"))
|
return redirect(url_for("book.my_library"))
|
||||||
|
|
||||||
collection: m.Collection = db.session.get(m.Collection, collection_id)
|
|
||||||
if not collection or collection.is_deleted:
|
|
||||||
log(log.WARNING, "Collection with id [%s] not found", collection_id)
|
|
||||||
flash("Collection not found", "danger")
|
|
||||||
return redirect(url_for("book.collection_view", book_id=book_id))
|
|
||||||
|
|
||||||
if sub_collection_id:
|
|
||||||
sub_collection: m.Collection = db.session.get(m.Collection, sub_collection_id)
|
|
||||||
if not sub_collection or sub_collection.is_deleted:
|
|
||||||
log(log.WARNING, "Sub_collection with id [%s] not found", sub_collection_id)
|
|
||||||
flash("Sub_collection not found", "danger")
|
|
||||||
return redirect(
|
|
||||||
url_for(
|
|
||||||
"book.sub_collection_view",
|
|
||||||
book_id=book_id,
|
|
||||||
collection_id=collection_id,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
section: m.Section = db.session.get(m.Section, section_id)
|
section: m.Section = db.session.get(m.Section, section_id)
|
||||||
if not section:
|
if not section:
|
||||||
log(log.WARNING, "Section with id [%s] not found", section_id)
|
log(log.WARNING, "Section with id [%s] not found", section_id)
|
||||||
|
@ -66,53 +38,35 @@ def interpretation_view(
|
||||||
book_id=book_id,
|
book_id=book_id,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
# FIXME breadcrumbs
|
||||||
breadcrumbs = create_breadcrumbs(
|
# breadcrumbs = create_breadcrumbs(
|
||||||
book_id=book_id,
|
# book_id=book_id,
|
||||||
collection_path=(
|
# collection_path=(
|
||||||
collection_id,
|
# collection_id,
|
||||||
sub_collection_id,
|
# sub_collection_id,
|
||||||
),
|
# ),
|
||||||
section_id=section_id,
|
# section_id=section_id,
|
||||||
)
|
# )
|
||||||
return render_template(
|
return render_template(
|
||||||
"book/interpretation_view.html",
|
"book/interpretation_view.html",
|
||||||
book=book,
|
book=book,
|
||||||
collection=collection,
|
section=section,
|
||||||
sub_collection=sub_collection if sub_collection_id else None,
|
breadcrumbs=[],
|
||||||
section=section,
|
)
|
||||||
breadcrumbs=breadcrumbs,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
#####################
|
@bp.route("/<int:book_id>/<int:section_id>/create_interpretation", methods=["POST"])
|
||||||
# Interpretation CRUD
|
|
||||||
#####################
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route(
|
|
||||||
"/<int:book_id>/<int:collection_id>/<int:section_id>/create_interpretation",
|
|
||||||
methods=["POST"],
|
|
||||||
)
|
|
||||||
@bp.route(
|
|
||||||
"/<int:book_id>/<int:collection_id>/<int:sub_collection_id>/<int:section_id>/create_interpretation",
|
|
||||||
methods=["POST"],
|
|
||||||
)
|
|
||||||
@register_book_verify_route(bp.name)
|
@register_book_verify_route(bp.name)
|
||||||
@login_required
|
@login_required
|
||||||
def interpretation_create(
|
def interpretation_create(
|
||||||
book_id: int,
|
book_id: int,
|
||||||
collection_id: int,
|
|
||||||
section_id: int,
|
section_id: int,
|
||||||
sub_collection_id: int | None = None,
|
|
||||||
):
|
):
|
||||||
section: m.Section = db.session.get(m.Section, section_id)
|
section: m.Section = db.session.get(m.Section, section_id)
|
||||||
form = f.CreateInterpretationForm()
|
form = f.CreateInterpretationForm()
|
||||||
redirect_url = url_for(
|
redirect_url = url_for(
|
||||||
"book.interpretation_view",
|
"book.interpretation_view",
|
||||||
book_id=book_id,
|
book_id=book_id,
|
||||||
collection_id=collection_id,
|
|
||||||
sub_collection_id=sub_collection_id,
|
|
||||||
section_id=section.id,
|
section_id=section.id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -153,36 +107,20 @@ def interpretation_create(
|
||||||
|
|
||||||
|
|
||||||
@bp.route(
|
@bp.route(
|
||||||
"/<int:book_id>/<int:collection_id>/<int:section_id>/<int:interpretation_id>/edit_interpretation",
|
"/<int:book_id>/<int:interpretation_id>/edit_interpretation", methods=["POST"]
|
||||||
methods=["POST"],
|
|
||||||
)
|
|
||||||
@bp.route(
|
|
||||||
(
|
|
||||||
"/<int:book_id>/<int:collection_id>/<int:sub_collection_id>/"
|
|
||||||
"<int:section_id>/<int:interpretation_id>/edit_interpretation"
|
|
||||||
),
|
|
||||||
methods=["POST"],
|
|
||||||
)
|
)
|
||||||
@register_book_verify_route(bp.name)
|
@register_book_verify_route(bp.name)
|
||||||
@login_required
|
@login_required
|
||||||
def interpretation_edit(
|
def interpretation_edit(
|
||||||
book_id: int,
|
book_id: int,
|
||||||
collection_id: int,
|
|
||||||
section_id: int,
|
|
||||||
interpretation_id: int,
|
interpretation_id: int,
|
||||||
sub_collection_id: int | None = None,
|
|
||||||
):
|
):
|
||||||
interpretation: m.Interpretation = db.session.get(
|
interpretation: m.Interpretation = db.session.get(
|
||||||
m.Interpretation, interpretation_id
|
m.Interpretation, interpretation_id
|
||||||
)
|
)
|
||||||
form = f.EditInterpretationForm()
|
form = f.EditInterpretationForm()
|
||||||
redirect_url = url_for(
|
redirect_url = url_for(
|
||||||
"book.qa_view",
|
"book.qa_view", book_id=book_id, interpretation_id=interpretation_id
|
||||||
book_id=book_id,
|
|
||||||
collection_id=collection_id,
|
|
||||||
sub_collection_id=sub_collection_id,
|
|
||||||
section_id=section_id,
|
|
||||||
interpretation_id=interpretation_id,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
|
@ -213,25 +151,11 @@ def interpretation_edit(
|
||||||
|
|
||||||
|
|
||||||
@bp.route(
|
@bp.route(
|
||||||
"/<int:book_id>/<int:collection_id>/<int:section_id>/<int:interpretation_id>/delete_interpretation",
|
"/<int:book_id>/<int:interpretation_id>/delete_interpretation", methods=["POST"]
|
||||||
methods=["POST"],
|
|
||||||
)
|
|
||||||
@bp.route(
|
|
||||||
(
|
|
||||||
"/<int:book_id>/<int:collection_id>/<int:sub_collection_id>/"
|
|
||||||
"<int:section_id>/<int:interpretation_id>/delete_interpretation"
|
|
||||||
),
|
|
||||||
methods=["POST"],
|
|
||||||
)
|
)
|
||||||
@register_book_verify_route(bp.name)
|
@register_book_verify_route(bp.name)
|
||||||
@login_required
|
@login_required
|
||||||
def interpretation_delete(
|
def interpretation_delete(book_id: int, interpretation_id: int):
|
||||||
book_id: int,
|
|
||||||
collection_id: int,
|
|
||||||
section_id: int,
|
|
||||||
interpretation_id: int,
|
|
||||||
sub_collection_id: int | None = None,
|
|
||||||
):
|
|
||||||
interpretation: m.Interpretation = db.session.get(
|
interpretation: m.Interpretation = db.session.get(
|
||||||
m.Interpretation, interpretation_id
|
m.Interpretation, interpretation_id
|
||||||
)
|
)
|
||||||
|
@ -251,85 +175,36 @@ def interpretation_delete(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@bp.route(
|
@bp.route("/<int:book_id>/<int:interpretation_id>/preview", methods=["GET"])
|
||||||
"/<int:book_id>/<int:collection_id>/<int:section_id>/<int:interpretation_id>/preview",
|
def qa_view(book_id: int, interpretation_id: int):
|
||||||
methods=["GET"],
|
|
||||||
)
|
|
||||||
@bp.route(
|
|
||||||
(
|
|
||||||
"/<int:book_id>/<int:collection_id>/<int:sub_collection_id>/"
|
|
||||||
"<int:section_id>/<int:interpretation_id>/preview"
|
|
||||||
),
|
|
||||||
methods=["GET"],
|
|
||||||
)
|
|
||||||
def qa_view(
|
|
||||||
book_id: int,
|
|
||||||
collection_id: int,
|
|
||||||
section_id: int,
|
|
||||||
interpretation_id: int,
|
|
||||||
sub_collection_id: int | None = None,
|
|
||||||
):
|
|
||||||
book: m.Book = db.session.get(m.Book, book_id)
|
book: m.Book = db.session.get(m.Book, book_id)
|
||||||
if not book or book.is_deleted:
|
if not book or book.is_deleted:
|
||||||
log(log.INFO, "User: [%s] is not owner of book: [%s]", current_user, book)
|
log(log.INFO, "User: [%s] is not owner of book: [%s]", current_user, book)
|
||||||
flash("You are not owner of this book!", "danger")
|
flash("You are not owner of this book!", "danger")
|
||||||
return redirect(url_for("book.my_library"))
|
return redirect(url_for("book.my_library"))
|
||||||
|
|
||||||
collection: m.Collection = db.session.get(m.Collection, collection_id)
|
|
||||||
if not collection or collection.is_deleted:
|
|
||||||
log(log.WARNING, "Collection with id [%s] not found", collection_id)
|
|
||||||
flash("Collection not found", "danger")
|
|
||||||
return redirect(url_for("book.collection_view", book_id=book_id))
|
|
||||||
|
|
||||||
if sub_collection_id:
|
|
||||||
sub_collection: m.Collection = db.session.get(m.Collection, sub_collection_id)
|
|
||||||
if not sub_collection or sub_collection.is_deleted:
|
|
||||||
log(log.WARNING, "Sub_collection with id [%s] not found", sub_collection_id)
|
|
||||||
flash("SubCollection not found", "danger")
|
|
||||||
return redirect(
|
|
||||||
url_for(
|
|
||||||
"book.sub_collection_view",
|
|
||||||
book_id=book_id,
|
|
||||||
collection_id=collection_id,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
redirect_url = url_for(
|
|
||||||
"book.interpretation_view",
|
|
||||||
book_id=book_id,
|
|
||||||
collection_id=collection_id,
|
|
||||||
sub_collection_id=sub_collection_id,
|
|
||||||
section_id=section_id,
|
|
||||||
)
|
|
||||||
section: m.Section = db.session.get(m.Section, section_id)
|
|
||||||
if not section or section.is_deleted:
|
|
||||||
log(log.WARNING, "Section with id [%s] not found", section_id)
|
|
||||||
flash("Section not found", "danger")
|
|
||||||
return redirect(redirect_url)
|
|
||||||
|
|
||||||
interpretation: m.Interpretation = db.session.get(
|
interpretation: m.Interpretation = db.session.get(
|
||||||
m.Interpretation, interpretation_id
|
m.Interpretation, interpretation_id
|
||||||
)
|
)
|
||||||
if not interpretation or interpretation.is_deleted:
|
if not interpretation or interpretation.is_deleted:
|
||||||
log(log.WARNING, "Interpretation with id [%s] not found", interpretation_id)
|
log(log.WARNING, "Interpretation with id [%s] not found", interpretation_id)
|
||||||
flash("Interpretation not found", "danger")
|
flash("Interpretation not found", "danger")
|
||||||
return redirect(redirect_url)
|
return redirect(url_for("book.collection_view", book_id=book_id))
|
||||||
|
|
||||||
breadcrumbs = create_breadcrumbs(
|
# FIXME
|
||||||
book_id=book_id,
|
# breadcrumbs = create_breadcrumbs(
|
||||||
collection_path=(
|
# book_id=book_id,
|
||||||
collection_id,
|
# collection_path=(
|
||||||
sub_collection_id,
|
# collection_id,
|
||||||
),
|
# sub_collection_id,
|
||||||
section_id=section_id,
|
# ),
|
||||||
interpretation_id=interpretation.id,
|
# section_id=section_id,
|
||||||
)
|
# interpretation_id=interpretation.id,
|
||||||
|
# )
|
||||||
return render_template(
|
return render_template(
|
||||||
"book/qa_view.html",
|
"book/qa_view.html",
|
||||||
book=book,
|
book=book,
|
||||||
collection=collection,
|
section=interpretation.section,
|
||||||
sub_collection=sub_collection if sub_collection_id else None,
|
|
||||||
section=section,
|
|
||||||
interpretation=interpretation,
|
interpretation=interpretation,
|
||||||
breadcrumbs=breadcrumbs,
|
breadcrumbs=[],
|
||||||
)
|
)
|
||||||
|
|
|
@ -817,7 +817,7 @@ def test_crud_interpretation(client: FlaskClient, runner: FlaskCliRunner):
|
||||||
text_1 = "Test Interpretation #1 Text"
|
text_1 = "Test Interpretation #1 Text"
|
||||||
|
|
||||||
response: Response = client.post(
|
response: Response = client.post(
|
||||||
f"/book/{book.id}/{collection.id}/{sub_collection.id}/{section_in_subcollection.id}/create_interpretation",
|
f"/book/{book.id}/{section_in_subcollection.id}/create_interpretation",
|
||||||
data=dict(section_id=section_in_subcollection.id, text=text_1),
|
data=dict(section_id=section_in_subcollection.id, text=text_1),
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
@ -831,7 +831,7 @@ def test_crud_interpretation(client: FlaskClient, runner: FlaskCliRunner):
|
||||||
assert not interpretation.comments
|
assert not interpretation.comments
|
||||||
|
|
||||||
response: Response = client.post(
|
response: Response = client.post(
|
||||||
f"/book/{book.id}/{leaf_collection.id}/{section_in_collection.id}/create_interpretation",
|
f"/book/{book.id}/{section_in_collection.id}/create_interpretation",
|
||||||
data=dict(section_id=section_in_collection.id, text=text_1),
|
data=dict(section_id=section_in_collection.id, text=text_1),
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
@ -854,7 +854,7 @@ def test_crud_interpretation(client: FlaskClient, runner: FlaskCliRunner):
|
||||||
assert b"Collection not found" in response.data
|
assert b"Collection not found" in response.data
|
||||||
|
|
||||||
response: Response = client.post(
|
response: Response = client.post(
|
||||||
f"/book/{book.id}/{leaf_collection.id}/999/create_interpretation",
|
f"/book/{book.id}/999/create_interpretation",
|
||||||
data=dict(collection_id=999, text=text_1),
|
data=dict(collection_id=999, text=text_1),
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
@ -863,7 +863,7 @@ def test_crud_interpretation(client: FlaskClient, runner: FlaskCliRunner):
|
||||||
assert b"Section not found" in response.data
|
assert b"Section not found" in response.data
|
||||||
|
|
||||||
response: Response = client.post(
|
response: Response = client.post(
|
||||||
f"/book/{book.id}/{collection.id}/{sub_collection.id}/888/create_interpretation",
|
f"/book/{book.id}/888/create_interpretation",
|
||||||
data=dict(collection_id=999, text=text_1),
|
data=dict(collection_id=999, text=text_1),
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
@ -890,7 +890,7 @@ def test_crud_interpretation(client: FlaskClient, runner: FlaskCliRunner):
|
||||||
new_text = "Test Interpretation #1 Text(edited)"
|
new_text = "Test Interpretation #1 Text(edited)"
|
||||||
|
|
||||||
response: Response = client.post(
|
response: Response = client.post(
|
||||||
f"/book/{book.id}/{leaf_collection.id}/{section_in_collection.id}/{interpretation.id}/edit_interpretation",
|
f"/book/{book.id}/{interpretation.id}/edit_interpretation",
|
||||||
data=dict(
|
data=dict(
|
||||||
interpretation_id=interpretation.id,
|
interpretation_id=interpretation.id,
|
||||||
text=new_text,
|
text=new_text,
|
||||||
|
@ -906,7 +906,7 @@ def test_crud_interpretation(client: FlaskClient, runner: FlaskCliRunner):
|
||||||
assert edited_interpretation
|
assert edited_interpretation
|
||||||
|
|
||||||
response: Response = client.post(
|
response: Response = client.post(
|
||||||
f"/book/{book.id}/{leaf_collection.id}/{section_in_collection.id}/999/edit_interpretation",
|
f"/book/{book.id}/999/edit_interpretation",
|
||||||
data=dict(
|
data=dict(
|
||||||
interpretation_id=interpretation.id,
|
interpretation_id=interpretation.id,
|
||||||
text=new_text,
|
text=new_text,
|
||||||
|
@ -917,7 +917,7 @@ def test_crud_interpretation(client: FlaskClient, runner: FlaskCliRunner):
|
||||||
assert b"Interpretation not found" in response.data
|
assert b"Interpretation not found" in response.data
|
||||||
|
|
||||||
response: Response = client.post(
|
response: Response = client.post(
|
||||||
f"/book/{book.id}/{leaf_collection.id}/{section_in_collection.id}/999/delete_interpretation",
|
f"/book/{book.id}/999/delete_interpretation",
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -926,8 +926,7 @@ def test_crud_interpretation(client: FlaskClient, runner: FlaskCliRunner):
|
||||||
|
|
||||||
response: Response = client.post(
|
response: Response = client.post(
|
||||||
(
|
(
|
||||||
f"/book/{book.id}/{collection.id}/{sub_collection.id}/"
|
f"/book/{book.id}/{section_in_subcollection.interpretations[0].id}/delete_interpretation"
|
||||||
f"{section_in_subcollection.id}/{section_in_subcollection.interpretations[0].id}/delete_interpretation"
|
|
||||||
),
|
),
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
@ -943,8 +942,7 @@ def test_crud_interpretation(client: FlaskClient, runner: FlaskCliRunner):
|
||||||
|
|
||||||
response: Response = client.post(
|
response: Response = client.post(
|
||||||
(
|
(
|
||||||
f"/book/{book.id}/{leaf_collection.id}/{section_in_collection.id}/"
|
f"/book/{book.id}/{section_in_collection.interpretations[0].id}/delete_interpretation"
|
||||||
f"{section_in_collection.interpretations[0].id}/delete_interpretation"
|
|
||||||
),
|
),
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
@ -1001,7 +999,7 @@ def test_crud_comment(client: FlaskClient, runner: FlaskCliRunner):
|
||||||
text_1 = "Test Interpretation #1 Text"
|
text_1 = "Test Interpretation #1 Text"
|
||||||
|
|
||||||
response: Response = client.post(
|
response: Response = client.post(
|
||||||
f"/book/{book.id}/{collection.id}/{sub_collection.id}/{section_in_subcollection.id}/create_interpretation",
|
f"/book/{book.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, label=label_1, text=text_1),
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
@ -1151,7 +1149,7 @@ def test_interpretation_in_home_last_inter_section(
|
||||||
text_1 = "Test Interpretation #1 Text"
|
text_1 = "Test Interpretation #1 Text"
|
||||||
|
|
||||||
response: Response = client.post(
|
response: Response = client.post(
|
||||||
f"/book/{book.id}/{collection.id}/{sub_collection.id}/{section_in_subcollection.id}/create_interpretation",
|
f"/book/{book.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, label=label_1, text=text_1),
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
@ -1165,7 +1163,7 @@ def test_interpretation_in_home_last_inter_section(
|
||||||
assert not interpretation.comments
|
assert not interpretation.comments
|
||||||
|
|
||||||
response: Response = client.post(
|
response: Response = client.post(
|
||||||
f"/book/{book.id}/{leaf_collection.id}/{section_in_collection.id}/create_interpretation",
|
f"/book/{book.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, label=label_1, text=text_1),
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
@ -1188,7 +1186,7 @@ def test_interpretation_in_home_last_inter_section(
|
||||||
assert b"Collection not found" in response.data
|
assert b"Collection not found" in response.data
|
||||||
|
|
||||||
response: Response = client.post(
|
response: Response = client.post(
|
||||||
f"/book/{book.id}/{leaf_collection.id}/999/create_interpretation",
|
f"/book/{book.id}/999/create_interpretation",
|
||||||
data=dict(collection_id=999, label=label_1, text=text_1),
|
data=dict(collection_id=999, label=label_1, text=text_1),
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
@ -1197,7 +1195,7 @@ def test_interpretation_in_home_last_inter_section(
|
||||||
assert b"Section not found" in response.data
|
assert b"Section not found" in response.data
|
||||||
|
|
||||||
response: Response = client.post(
|
response: Response = client.post(
|
||||||
f"/book/{book.id}/{collection.id}/{sub_collection.id}/888/create_interpretation",
|
f"/book/{book.id}/888/create_interpretation",
|
||||||
data=dict(collection_id=999, label=label_1, text=text_1),
|
data=dict(collection_id=999, label=label_1, text=text_1),
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
|
|
@ -175,7 +175,7 @@ def test_create_tags_on_interpretation_create_and_edit(client: FlaskClient):
|
||||||
|
|
||||||
tags = "[tag-4] [tag5] [tag3]"
|
tags = "[tag-4] [tag5] [tag3]"
|
||||||
response: Response = client.post(
|
response: Response = client.post(
|
||||||
f"/book/{book.id}/{collection.id}/{section.id}/{interpretation.id}/edit_interpretation",
|
f"/book/{book.id}/{interpretation.id}/edit_interpretation",
|
||||||
data=dict(interpretation_id=interpretation.id, text=text_1 + tags),
|
data=dict(interpretation_id=interpretation.id, text=text_1 + tags),
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue