mirror of
https://github.com/logos-co/open-law.git
synced 2025-01-11 15:24:43 +00:00
build_qa_url_using_interpretation()
This commit is contained in:
parent
6308f7e0bf
commit
b91d6cb5b8
@ -68,9 +68,13 @@ def create_app(environment="development"):
|
||||
login_manager.anonymous_user = AnonymousUser
|
||||
|
||||
# Jinja globals
|
||||
from app.controllers.jinja_globals import form_hidden_tag
|
||||
from app.controllers.jinja_globals import (
|
||||
form_hidden_tag,
|
||||
build_qa_url_using_interpretation,
|
||||
)
|
||||
|
||||
app.jinja_env.globals["form_hidden_tag"] = form_hidden_tag
|
||||
app.jinja_env.globals["build_qa_url"] = build_qa_url_using_interpretation
|
||||
|
||||
# Error handlers.
|
||||
@app.errorhandler(HTTPException)
|
||||
|
23
app/controllers/build_qa_url_using_interpretation.py
Normal file
23
app/controllers/build_qa_url_using_interpretation.py
Normal file
@ -0,0 +1,23 @@
|
||||
from flask import url_for
|
||||
|
||||
from app import models as m
|
||||
|
||||
|
||||
def build_qa_url_using_interpretation(interpretation: m.Interpretation):
|
||||
section: m.Section = interpretation.section
|
||||
collection: m.Collection = section.collection
|
||||
sub_collection = None
|
||||
if collection.is_leaf and collection.parent.is_root:
|
||||
collection: m.Collection = collection.parent
|
||||
sub_collection: m.Collection = collection
|
||||
book: m.Book = section.version.book
|
||||
|
||||
url = url_for(
|
||||
"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
|
@ -1,7 +1,31 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from flask import url_for
|
||||
|
||||
from app import models as m
|
||||
|
||||
|
||||
# Using: {{ form_hidden_tag() }}
|
||||
def form_hidden_tag():
|
||||
form = FlaskForm()
|
||||
return form.hidden_tag()
|
||||
|
||||
|
||||
# Using: {{ build_qa_url(interpretation) }}
|
||||
def build_qa_url_using_interpretation(interpretation: m.Interpretation):
|
||||
section: m.Section = interpretation.section
|
||||
collection: m.Collection = section.collection
|
||||
sub_collection = None
|
||||
if not collection.parent.is_root:
|
||||
sub_collection: m.Collection = collection
|
||||
collection: m.Collection = collection.parent
|
||||
book: m.Book = section.version.book
|
||||
|
||||
url = url_for(
|
||||
"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
|
||||
|
File diff suppressed because one or more lines are too long
143082
app/static/js/main.js
143082
app/static/js/main.js
File diff suppressed because one or more lines are too long
@ -158,11 +158,7 @@
|
||||
<div class="space-x-0.5 flex items-center">
|
||||
<a
|
||||
class="!cursor-pointer text-no-underline flex items-center"
|
||||
{% if sub_collection %}
|
||||
href="{{ url_for('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) }}"
|
||||
{% else %}
|
||||
href="{{ url_for('book.qa_view', book_id=book.id, collection_id=collection.id, section_id=section.id, interpretation_id=interpretation.id) }}"
|
||||
{% endif %}
|
||||
href="{{ build_qa_url(interpretation) }}"
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"> <path stroke-linecap="round" stroke-linejoin="round" d="M20.25 8.511c.884.284 1.5 1.128 1.5 2.097v4.286c0 1.136-.847 2.1-1.98 2.193-.34.027-.68.052-1.02.072v3.091l-3-3c-1.354 0-2.694-.055-4.02-.163a2.115 2.115 0 01-.825-.242m9.345-8.334a2.126 2.126 0 00-.476-.095 48.64 48.64 0 00-8.048 0c-1.131.094-1.976 1.057-1.976 2.192v4.286c0 .837.46 1.58 1.155 1.951m9.345-8.334V6.637c0-1.621-1.152-3.026-2.76-3.235A48.455 48.455 0 0011.25 3c-2.115 0-4.198.137-6.24.402-1.608.209-2.76 1.614-2.76 3.235v6.226c0 1.621 1.152 3.026 2.76 3.235.577.075 1.157.14 1.74.194V21l4.155-4.155" /> </svg>
|
||||
<p class="select-none">{{interpretation.active_comments | length}}</p>
|
||||
|
@ -86,8 +86,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"> <path stroke-linecap="round" stroke-linejoin="round" d="M9 8.25H7.5a2.25 2.25 0 00-2.25 2.25v9a2.25 2.25 0 002.25 2.25h9a2.25 2.25 0 002.25-2.25v-9a2.25 2.25 0 00-2.25-2.25H15m0-3l-3-3m0 0l-3 3m3-3V15" /> </svg>
|
||||
</span>
|
||||
<div class="space-x-0.5 flex items-center">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"> <path stroke-linecap="round" stroke-linejoin="round" d="M20.25 8.511c.884.284 1.5 1.128 1.5 2.097v4.286c0 1.136-.847 2.1-1.98 2.193-.34.027-.68.052-1.02.072v3.091l-3-3c-1.354 0-2.694-.055-4.02-.163a2.115 2.115 0 01-.825-.242m9.345-8.334a2.126 2.126 0 00-.476-.095 48.64 48.64 0 00-8.048 0c-1.131.094-1.976 1.057-1.976 2.192v4.286c0 .837.46 1.58 1.155 1.951m9.345-8.334V6.637c0-1.621-1.152-3.026-2.76-3.235A48.455 48.455 0 0011.25 3c-2.115 0-4.198.137-6.24.402-1.608.209-2.76 1.614-2.76 3.235v6.226c0 1.621 1.152 3.026 2.76 3.235.577.075 1.157.14 1.74.194V21l4.155-4.155" /> </svg>
|
||||
<p>{{interpretation.active_comments | length}}</p>
|
||||
<a class="!cursor-pointer text-no-underline flex items-center" href="{{ build_qa_url(interpretation) }}" >
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"> <path stroke-linecap="round" stroke-linejoin="round" d="M20.25 8.511c.884.284 1.5 1.128 1.5 2.097v4.286c0 1.136-.847 2.1-1.98 2.193-.34.027-.68.052-1.02.072v3.091l-3-3c-1.354 0-2.694-.055-4.02-.163a2.115 2.115 0 01-.825-.242m9.345-8.334a2.126 2.126 0 00-.476-.095 48.64 48.64 0 00-8.048 0c-1.131.094-1.976 1.057-1.976 2.192v4.286c0 .837.46 1.58 1.155 1.951m9.345-8.334V6.637c0-1.621-1.152-3.026-2.76-3.235A48.455 48.455 0 0011.25 3c-2.115 0-4.198.137-6.24.402-1.608.209-2.76 1.614-2.76 3.235v6.226c0 1.621 1.152 3.026 2.76 3.235.577.075 1.157.14 1.74.194V21l4.155-4.155" /> </svg>
|
||||
<p>{{interpretation.active_comments | length}}</p>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -130,8 +130,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"> <path stroke-linecap="round" stroke-linejoin="round" d="M9 8.25H7.5a2.25 2.25 0 00-2.25 2.25v9a2.25 2.25 0 002.25 2.25h9a2.25 2.25 0 002.25-2.25v-9a2.25 2.25 0 00-2.25-2.25H15m0-3l-3-3m0 0l-3 3m3-3V15" /> </svg>
|
||||
</span>
|
||||
<div class="space-x-0.5 flex items-center">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"> <path stroke-linecap="round" stroke-linejoin="round" d="M20.25 8.511c.884.284 1.5 1.128 1.5 2.097v4.286c0 1.136-.847 2.1-1.98 2.193-.34.027-.68.052-1.02.072v3.091l-3-3c-1.354 0-2.694-.055-4.02-.163a2.115 2.115 0 01-.825-.242m9.345-8.334a2.126 2.126 0 00-.476-.095 48.64 48.64 0 00-8.048 0c-1.131.094-1.976 1.057-1.976 2.192v4.286c0 .837.46 1.58 1.155 1.951m9.345-8.334V6.637c0-1.621-1.152-3.026-2.76-3.235A48.455 48.455 0 0011.25 3c-2.115 0-4.198.137-6.24.402-1.608.209-2.76 1.614-2.76 3.235v6.226c0 1.621 1.152 3.026 2.76 3.235.577.075 1.157.14 1.74.194V21l4.155-4.155" /> </svg>
|
||||
<p>{{interpretation.active_comments | length}}</p>
|
||||
<a class="!cursor-pointer text-no-underline flex items-center" href="{{ build_qa_url(interpretation) }}" >
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"> <path stroke-linecap="round" stroke-linejoin="round" d="M20.25 8.511c.884.284 1.5 1.128 1.5 2.097v4.286c0 1.136-.847 2.1-1.98 2.193-.34.027-.68.052-1.02.072v3.091l-3-3c-1.354 0-2.694-.055-4.02-.163a2.115 2.115 0 01-.825-.242m9.345-8.334a2.126 2.126 0 00-.476-.095 48.64 48.64 0 00-8.048 0c-1.131.094-1.976 1.057-1.976 2.192v4.286c0 .837.46 1.58 1.155 1.951m9.345-8.334V6.637c0-1.621-1.152-3.026-2.76-3.235A48.455 48.455 0 0011.25 3c-2.115 0-4.198.137-6.24.402-1.608.209-2.76 1.614-2.76 3.235v6.226c0 1.621 1.152 3.026 2.76 3.235.577.075 1.157.14 1.74.194V21l4.155-4.155" /> </svg>
|
||||
<p>{{interpretation.active_comments | length}}</p>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
27
tests/test_build_qa_url_using_interpretation.py
Normal file
27
tests/test_build_qa_url_using_interpretation.py
Normal file
@ -0,0 +1,27 @@
|
||||
from flask.testing import FlaskClient
|
||||
from flask import current_app as Response
|
||||
|
||||
from app.controllers.jinja_globals import (
|
||||
build_qa_url_using_interpretation,
|
||||
)
|
||||
from .utils import create_test_book, login
|
||||
from app import models as m
|
||||
|
||||
|
||||
def test_build_qa_url_using_interpretation(client: FlaskClient):
|
||||
_, user = login(client)
|
||||
user: m.User
|
||||
|
||||
create_test_book(user.id)
|
||||
|
||||
interpretation: m.Interpretation = m.Interpretation.query.first()
|
||||
|
||||
url = build_qa_url_using_interpretation(interpretation)
|
||||
assert url
|
||||
|
||||
response: Response = client.get(url, follow_redirects=True)
|
||||
assert response.status_code == 200
|
||||
|
||||
section: m.Section = m.Section.query.first()
|
||||
assert section
|
||||
assert str.encode(section.label) in response.data
|
Loading…
x
Reference in New Issue
Block a user