Merge branch 'develop' into svyat/feat/mention_user

This commit is contained in:
Kostiantyn Stoliarskyi 2023-06-01 15:11:42 +03:00
commit 5f80ceb182
30 changed files with 758 additions and 648 deletions

View File

@ -16,7 +16,7 @@ jobs:
matrix: matrix:
python-version: [3.11] python-version: [3.11]
poetry-version: [1.4] poetry-version: [1.4]
os: [ubuntu-latest, macos-latest] os: [macos-latest]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:

View File

@ -20,6 +20,7 @@
"jsonify", "jsonify",
"pydantic", "pydantic",
"pytest", "pytest",
"scrf",
"siwe", "siwe",
"sqlalchemy", "sqlalchemy",
"tailwindcss", "tailwindcss",

View File

@ -10,7 +10,8 @@ def create_collections_breadcrumb(
bread_crumbs += [ bread_crumbs += [
s.BreadCrumb( s.BreadCrumb(
type=s.BreadCrumbType.Collection, type=s.BreadCrumbType.Collection,
url="", url=url_for("book.collection_view", book_id=collection.book_id)
+ f"#collection-{collection.label}",
label=collection.label, label=collection.label,
) )
] ]
@ -41,8 +42,8 @@ def create_breadcrumbs(
crumples += [ crumples += [
s.BreadCrumb( s.BreadCrumb(
type=s.BreadCrumbType.MyBookList, type=s.BreadCrumbType.MyBookList,
url=url_for("book.my_library"), url=url_for("user.profile", user_id=current_user.id),
label="My Books", label="Me",
) )
] ]
else: else:
@ -50,8 +51,8 @@ def create_breadcrumbs(
crumples += [ crumples += [
s.BreadCrumb( s.BreadCrumb(
type=s.BreadCrumbType.AuthorBookList, type=s.BreadCrumbType.AuthorBookList,
url="", url=url_for("user.profile", user_id=book.owner.id),
label=book.owner.username + "'s books", label=book.owner.username,
) )
] ]

View File

@ -92,3 +92,27 @@ class Book(BaseModel):
) )
return interpretations return interpretations
@property
def interpretations(self):
interpretations = (
db.session.query(
m.Interpretation,
)
.filter(
and_(
m.BookVersion.id == self.last_version.id,
m.Section.version_id == m.BookVersion.id,
m.Collection.id == m.Section.collection_id,
m.Interpretation.section_id == m.Section.id,
m.BookVersion.is_deleted.is_(False),
m.Interpretation.is_deleted.is_(False),
m.Section.is_deleted.is_(False),
m.Collection.is_deleted.is_(False),
),
)
.order_by(m.Interpretation.created_at.desc())
.all()
)
return interpretations

View File

@ -33,6 +33,10 @@ class Collection(BaseModel):
def active_sections(self): def active_sections(self):
return [section for section in self.sections if not section.is_deleted] return [section for section in self.sections if not section.is_deleted]
@property
def book_id(self):
return self.version.book_id
@property @property
def sub_collections(self): def sub_collections(self):
return [ return [

File diff suppressed because one or more lines are too long

View File

@ -27,7 +27,7 @@
</span> </span>
<span class="space-x-0.5 flex items-center"> <span class="space-x-0.5 flex items-center">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M3.75 13.5l10.5-11.25L12 10.5h8.25L9.75 21.75 12 13.5H3.75z" /> </svg> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M3.75 13.5l10.5-11.25L12 10.5h8.25L9.75 21.75 12 13.5H3.75z" /> </svg>
<p>{{ book.approved_interpretations|length }}</p> <p>{{ book.interpretations|length }}</p>
</span> </span>
<span class="space-x-0.5 flex items-center"> <span class="space-x-0.5 flex items-center">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" /> </svg> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" /> </svg>

View File

@ -48,13 +48,13 @@
<!-- prettier-ignore --> <!-- prettier-ignore -->
<svg data-accordion-icon class="w-6 h-6 rotate-180 shrink-0" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd"></path> </svg> <svg data-accordion-icon class="w-6 h-6 rotate-180 shrink-0" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd"></path> </svg>
</button> </button>
<a id="accordion-collapse-heading-{{collection.id}}" class=" text-black dark:text-white "> <button href="#collection-{{collection.label}}" id="accordion-collapse-heading-{{collection.id}}" class=" text-black dark:text-white ">
<form id="rename-collection-label-form-{{collection.id}}" data-book-id='{{book.id}}' data-collection-id="{{collection.id}}" method="post" class="mb-0"> <form id="rename-collection-label-form-{{collection.id}}" data-book-id='{{book.id}}' data-collection-id="{{collection.id}}" method="post" class="mb-0">
{{ form_hidden_tag() }} {{ form_hidden_tag() }}
<input class=" bg-inherit border-none " value="{{collection.label}}" type="text" name="label" id="edit-collection-label-{{collection.id}}" placeholder="Collection label" required readonly/> <input class=" bg-inherit border-none " value="{{collection.label}}" type="text" name="label" id="edit-collection-label-{{collection.id}}" placeholder="Collection label" required readonly/>
<button name="submit" type="submit"></button> <button name="submit" type="submit"></button>
</form> </form>
</a> </button>
</div> </div>
<svg id="dropdownCollectionContextButton{{collection.id}}" data-dropdown-toggle="dropdown" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 0 0" stroke-width="1.5" stroke="none" class="w-0 h-0"></svg> <svg id="dropdownCollectionContextButton{{collection.id}}" data-dropdown-toggle="dropdown" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 0 0" stroke-width="1.5" stroke="none" class="w-0 h-0"></svg>
</div> </div>
@ -133,7 +133,7 @@
<p class=" text-sm mb-3">{% if book.about==None %}About text{% else %}{{book.about}}{% endif %}</p> <p class=" text-sm mb-3">{% if book.about==None %}About text{% else %}{{book.about}}{% endif %}</p>
{% for collection in book.versions[-1].children_collections if not collection.is_root and not collection.is_deleted %} {% for collection in book.versions[-1].children_collections if not collection.is_root and not collection.is_deleted %}
<p class="my-3 underline">#{{collection.label}}</p> <p class="my-3 underline" id="collection-{{collection.label}}">#{{collection.label}}</p>
{% if not collection.is_leaf and not collection.children %} {% if not collection.is_leaf and not collection.children %}
<p class="ml-3 my-3 italic text-sm">Collection is empty</p> <p class="ml-3 my-3 italic text-sm">Collection is empty</p>
{% endif %} {% endif %}

View File

@ -1,7 +1,9 @@
{% if not collection.is_leaf %} {% if not collection.is_leaf %}
<!-- if collection has sub_collection make for loop for it --> <!-- if collection has sub_collection make for loop for it -->
{% for sub_collection in collection.children if not sub_collection.is_deleted%} {% for sub_collection in collection.children if not sub_collection.is_deleted%}
<p class="my-3">##{{sub_collection.label}}</p> <p class="my-3" id="collection-{{sub_collection.label}}">
##{{sub_collection.label}}
</p>
{% if not sub_collection.active_sections and not sub_collection.children %} {% if not sub_collection.active_sections and not sub_collection.children %}
<p class="ml-3 my-3 italic text-sm">This sub collection is empty</p> <p class="ml-3 my-3 italic text-sm">This sub collection is empty</p>
{% endif %} {% endif %}

View File

@ -2,8 +2,8 @@
{% if not collection.is_leaf %} {% if not collection.is_leaf %}
<!-- if collection has sub_collection make for loop for it --> <!-- if collection has sub_collection make for loop for it -->
<!-- Nested accordion --> <!-- Nested accordion -->
{% for sub_collection in collection.children if not <!-- prettier-ignore -->
sub_collection.is_deleted%} {% for sub_collection in collection.children if not sub_collection.is_deleted%}
<div id="accordion-nested-collapse" data-accordion="open"> <div id="accordion-nested-collapse" data-accordion="open">
<!-- prettier-ignore --> <!-- prettier-ignore -->
<div class="flex items-center justify-start w-full font-medium text-left text-gray-500 focus:ring-4 focus:ring-gray-200 dark:focus:ring-gray-800 dark:text-gray-400"> <div class="flex items-center justify-start w-full font-medium text-left text-gray-500 focus:ring-4 focus:ring-gray-200 dark:focus:ring-gray-800 dark:text-gray-400">
@ -17,14 +17,14 @@
<svg data-accordion-icon class="w-6 h-6 shrink-0" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd"></path> </svg> <svg data-accordion-icon class="w-6 h-6 shrink-0" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd"></path> </svg>
</button> </button>
<!-- prettier-ignore --> <!-- prettier-ignore -->
<a id="accordion-nested-collapse-heading-{{sub_collection.parent.id}}-{{sub_collection.id}}" class="text-black dark:text-white"> <button href="#collection-{{sub_collection.label}}" id="accordion-nested-collapse-heading-{{sub_collection.parent.id}}-{{sub_collection.id}}" class="text-black dark:text-white">
<form id="rename-sub-collection-label-form-{{sub_collection.id}}" data-book-id="{{book.id}}" data-collection-id="{{collection.id}}" data-sub-collection-id="{{sub_collection.id}}" method="post" class="mb-0"> <form id="rename-sub-collection-label-form-{{sub_collection.id}}" data-book-id="{{book.id}}" data-collection-id="{{collection.id}}" data-sub-collection-id="{{sub_collection.id}}" method="post" class="mb-0">
{{ form_hidden_tag() }} {{ form_hidden_tag() }}
<!-- prettier-ignore --> <!-- prettier-ignore -->
<input class="bg-inherit border-none" value="{{sub_collection.label}}" type="text" name="label" id="edit-sub-collection-label-{{sub_collection.id}}" placeholder="Sub collection label" required readonly /> <input class="bg-inherit border-none" value="{{sub_collection.label}}" type="text" name="label" id="edit-sub-collection-label-{{sub_collection.id}}" placeholder="Sub collection label" required readonly />
<button name="submit" type="submit"></button> <button name="submit" type="submit"></button>
</form> </form>
</a> </button>
</div> </div>
<!-- prettier-ignore --> <!-- prettier-ignore -->
<svg id="dropdownSubCollectionContextButton{{sub_collection.id}}" data-dropdown-toggle="dropdown" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 0 0" stroke-width="1.5" stroke="none" class="w-0 h-0"></svg> <svg id="dropdownSubCollectionContextButton{{sub_collection.id}}" data-dropdown-toggle="dropdown" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 0 0" stroke-width="1.5" stroke="none" class="w-0 h-0"></svg>
@ -36,6 +36,13 @@
<li> <li>
<button type="button" id="callAddSectionModal" data-modal-target="add-section-modal" data-modal-toggle="add-section-modal" data-collection-id="{{collection.id}}" data-sub-collection-id="{{sub_collection.id}}" class="w-full block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white"> New Section </button> <button type="button" id="callAddSectionModal" data-modal-target="add-section-modal" data-modal-toggle="add-section-modal" data-collection-id="{{collection.id}}" data-sub-collection-id="{{sub_collection.id}}" class="w-full block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white"> New Section </button>
</li> </li>
{% elif not sub_collection.is_leaf and not sub_collection.children %}
<li>
<button type="button" id="callAddSectionModal" data-modal-target="add-section-modal" data-modal-toggle="add-section-modal" data-collection-id="{{collection.id}}" data-sub-collection-id="{{sub_collection.id}}" class="w-full block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white"> New Section </button>
</li>
<li>
<button type="button" id="callAddSubCollectionModal" data-modal-target="add-sub-collection-modal" data-modal-toggle="add-sub-collection-modal" data-collection-id="{{sub_collection.id}}" class="w-full block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white"> New Subcollection </button>
</li>
{% else %} {% else %}
<li> <li>
<button type="button" id="callAddSubCollectionModal" data-modal-target="add-sub-collection-modal" data-modal-toggle="add-sub-collection-modal" data-collection-id="{{sub_collection.id}}" class="w-full block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white"> New Subcollection </button> <button type="button" id="callAddSubCollectionModal" data-modal-target="add-sub-collection-modal" data-modal-toggle="add-sub-collection-modal" data-collection-id="{{sub_collection.id}}" class="w-full block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white"> New Subcollection </button>

View File

@ -16,7 +16,7 @@
{% if current_user.is_authenticated and current_user.stars|length==0 %} {% if current_user.is_authenticated and current_user.stars|length==0 %}
<!-- prettier-ignore --> <!-- prettier-ignore -->
<div class="mx-auto my-auto h-full w-full p-2"> <div class="mx-auto my-auto h-full w-full p-2">
<button type="button" data-modal-target="add-book-modal" data-modal-toggle="add-book-modal" class="w-full h-full text-black dark:text-white focus:ring-4 focus:outline-none focus:ring-blue-100 font-medium rounded-lg text-sm px-4 py-2.5 justify-center text-center inline-flex items-center border border-gray-200 dark:border-gray-700"><div class="my-auto"></div><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="M12 4.5v15m7.5-7.5h-15" /> </svg> You don't have favorite books start to create your own! </div></button></div> <a type="button" href="{{ url_for('book.get_all') }}" class="w-full h-full text-black dark:text-white focus:ring-4 focus:outline-none focus:ring-blue-100 font-medium rounded-lg text-sm px-4 py-2.5 justify-center text-center inline-flex items-center border border-gray-200 dark:border-gray-700"><div class="my-auto"></div><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="M12 4.5v15m7.5-7.5h-15" /> </svg> You don't have favorite books start to explore book to choose one! </div></button></div>
<!-- prettier-ignore --> <!-- prettier-ignore -->
{% endif %} {% endif %}
<!-- prettier-ignore --> <!-- prettier-ignore -->
@ -41,7 +41,7 @@
</span> </span>
<span class="space-x-0.5 flex items-center"> <span class="space-x-0.5 flex items-center">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M3.75 13.5l10.5-11.25L12 10.5h8.25L9.75 21.75 12 13.5H3.75z" /> </svg> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M3.75 13.5l10.5-11.25L12 10.5h8.25L9.75 21.75 12 13.5H3.75z" /> </svg>
<p>{{ book.approved_interpretations|length }}</p> <p>{{ book.interpretations|length }}</p>
</span> </span>
<span class="space-x-0.5 flex items-center"> <span class="space-x-0.5 flex items-center">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" /> </svg> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" /> </svg>

View File

@ -86,15 +86,14 @@
<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-row pb-3 p-3 pt-0 w-2/3 md:w-full"> <div class="flex flex-row pb-3 p-3 pt-0 w-2/3 md:w-full">
<div class="vote-block flex flex-col m-5 mr-8 justify-center items-center"> <div class="vote-block flex flex-col m-5 mr-8 justify-center items-center">
{% if interpretation.user_id != current_user.id %} <div class="vote-button cursor-pointer" data-vote-for="interpretation" data-entity-id="{{ interpretation.id }}" data-positive="true">
<div class="vote-button cursor-pointer" data-vote-for="interpretation" data-entity-id="{{ interpretation.id }}" data-positive="true"> <svg class="w-6 h-6 select-none
<svg class="w-6 h-6 select-none {% if interpretation.current_user_vote %}
{% if interpretation.current_user_vote %} stroke-green-500
stroke-green-500 {% endif %}
{% endif %} " xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" > <path stroke-linecap="round" stroke-linejoin="round" d="M4.5 10.5L12 3m0 0l7.5 7.5M12 3v18" /> </svg>
" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" > <path stroke-linecap="round" stroke-linejoin="round" d="M4.5 10.5L12 3m0 0l7.5 7.5M12 3v18" /> </svg> </div>
</div>
{% endif %}
<span <span
class="vote-count text-3xl select-none class="vote-count text-3xl select-none
@ -108,15 +107,13 @@
{{ interpretation.vote_count }} {{ interpretation.vote_count }}
</span> </span>
{% if interpretation.user_id != current_user.id %} <div class="vote-button cursor-pointer" data-vote-for="interpretation" data-entity-id="{{ interpretation.id }}" data-positive="false">
<div class="vote-button cursor-pointer" data-vote-for="interpretation" data-entity-id="{{ interpretation.id }}" data-positive="false"> <svg class="w-6 h-6 select-none
<svg class="w-6 h-6 select-none {% if interpretation.current_user_vote == False %}
{% if interpretation.current_user_vote == False %} stroke-red-500
stroke-red-500 {% endif %}
{% endif %} " xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"> <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 13.5L12 21m0 0l-7.5-7.5M12 21V3" /> </svg>
" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"> <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 13.5L12 21m0 0l-7.5-7.5M12 21V3" /> </svg> </div>
</div>
{% endif %}
<!-- TODO check permissions --> <!-- TODO check permissions -->
{% if interpretation.book.owner == current_user %} {% if interpretation.book.owner == current_user %}

View File

@ -21,14 +21,6 @@
</div> </div>
</div> </div>
</div> </div>
<div class="p-6 pt-0 space-y-6">
<div class="grid gap-6">
<div class="col-span-6 sm:col-span-3">
<label for="about-collection" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white" >About</label >
<textarea name="about" id="about-collection" rows="4" class="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="About collection..."></textarea>
</div>
</div>
</div>
<!-- Modal footer --> <!-- Modal footer -->
<div class="flex items-center p-6 space-x-2 border-t border-gray-200 rounded-b dark:border-gray-600"> <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> <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

@ -20,13 +20,6 @@
</div> </div>
</div> </div>
</div> </div>
<div class="p-6 pt-0 space-y-6">
<div class="w-full max-w-6xl mx-auto rounded-xl bg-gray-50 dark:bg-gray-600 shadow-lg text-white-900">
<div class="overflow-hidden rounded-md bg-gray-50 [&>*]:dark:bg-gray-600 text-black [&>*]:!border-none [&>*]:!stroke-black dark:text-white dark:[&>*]:!stroke-white">
<div id="new-section" class="quill-editor dark:text-white h-40"></div>
</div>
</div>
</div>
<!-- Modal footer --> <!-- Modal footer -->
<div class="flex items-center p-6 space-x-2 border-t border-gray-200 rounded-b dark:border-gray-600"> <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> <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

@ -47,7 +47,7 @@
</span> </span>
<span class="space-x-0.5 flex items-center"> <span class="space-x-0.5 flex items-center">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M3.75 13.5l10.5-11.25L12 10.5h8.25L9.75 21.75 12 13.5H3.75z" /> </svg> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M3.75 13.5l10.5-11.25L12 10.5h8.25L9.75 21.75 12 13.5H3.75z" /> </svg>
<p>{{ book.approved_interpretations|length }}</p> <p>{{ book.interpretations|length }}</p>
</span> </span>
<span class="space-x-0.5 flex items-center"> <span class="space-x-0.5 flex items-center">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" /> </svg> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" /> </svg>

View File

@ -79,17 +79,17 @@
<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-row pb-3 p-3 w-2/3 md:w-full"> <div class="flex flex-row pb-3 p-3 w-2/3 md:w-full">
<div class="vote-block flex flex-col m-5 mr-8 justify-center items-center"> <div class="vote-block flex flex-col m-5 mr-8 justify-center items-center">
{% if comment.user_id != current_user.id %}
<div class="vote-button cursor-pointer" data-vote-for="comment" data-entity-id="{{ comment.id }}" data-positive="true"> <div class="vote-button cursor-pointer" data-vote-for="comment" data-entity-id="{{ comment.id }}" data-positive="true">
<svg <svg
class="w-6 h-6 select-none class="w-6 h-6 select-none
{% if comment.current_user_vote %} {% if comment.current_user_vote %}
stroke-green-500 stroke-green-500
{% endif %} {% endif %}
" "
xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" > <path stroke-linecap="round" stroke-linejoin="round" d="M4.5 10.5L12 3m0 0l7.5 7.5M12 3v18" /> </svg> xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" > <path stroke-linecap="round" stroke-linejoin="round" d="M4.5 10.5L12 3m0 0l7.5 7.5M12 3v18" /> </svg>
</div> </div>
{% endif %}
<span <span
class="vote-count text-3xl select-none class="vote-count text-3xl select-none
@ -103,15 +103,14 @@
{{ comment.vote_count }} {{ comment.vote_count }}
</span> </span>
{% if comment.user_id != current_user.id %}
<div class="vote-button cursor-pointer" data-vote-for="comment" data-entity-id="{{ comment.id }}" data-positive="false"> <div class="vote-button cursor-pointer" data-vote-for="comment" data-entity-id="{{ comment.id }}" data-positive="false">
<svg class="w-6 h-6 select-none <svg class="w-6 h-6 select-none
{% if comment.current_user_vote == False %} {% if comment.current_user_vote == False %}
stroke-red-500 stroke-red-500
{% endif %} {% endif %}
" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"> <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 13.5L12 21m0 0l-7.5-7.5M12 21V3" /> </svg> " xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"> <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 13.5L12 21m0 0l-7.5-7.5M12 21V3" /> </svg>
</div> </div>
{% endif %}
<!-- TODO check permissions --> <!-- TODO check permissions -->
{% if interpretation.book.owner == current_user %} {% if interpretation.book.owner == current_user %}

View File

@ -33,15 +33,14 @@
<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-row pb-3 p-3"> <div class="flex flex-row pb-3 p-3">
<div class="vote-block flex flex-col m-5 justify-center items-center"> <div class="vote-block flex flex-col m-5 justify-center items-center">
{% if interpretation.user_id != current_user.id %} <div class="vote-button cursor-pointer" data-vote-for="interpretation" data-entity-id="{{ interpretation.id }}" data-positive="true">
<div class="vote-button cursor-pointer" data-vote-for="interpretation" data-entity-id="{{ interpretation.id }}" data-positive="true"> <svg class="w-6 h-6 select-none
<svg class="w-6 h-6 select-none {% if interpretation.current_user_vote %}
{% if interpretation.current_user_vote %} stroke-green-500
stroke-green-500 {% endif %}
{% endif %} " xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" > <path stroke-linecap="round" stroke-linejoin="round" d="M4.5 10.5L12 3m0 0l7.5 7.5M12 3v18" /> </svg>
" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" > <path stroke-linecap="round" stroke-linejoin="round" d="M4.5 10.5L12 3m0 0l7.5 7.5M12 3v18" /> </svg> </div>
</div>
{% endif %}
<span <span
class="vote-count text-3xl select-none class="vote-count text-3xl select-none
@ -55,15 +54,14 @@
{{ interpretation.vote_count }} {{ interpretation.vote_count }}
</span> </span>
{% if interpretation.user_id != current_user.id %}
<div class="vote-button cursor-pointer" data-vote-for="interpretation" data-entity-id="{{ interpretation.id }}" data-positive="false"> <div class="vote-button cursor-pointer" data-vote-for="interpretation" data-entity-id="{{ interpretation.id }}" data-positive="false">
<svg class="w-6 h-6 select-none <svg class="w-6 h-6 select-none
{% if interpretation.current_user_vote == False %} {% if interpretation.current_user_vote == False %}
stroke-red-500 stroke-red-500
{% endif %} {% endif %}
" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"> <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 13.5L12 21m0 0l-7.5-7.5M12 21V3" /> </svg> " xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"> <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 13.5L12 21m0 0l-7.5-7.5M12 21V3" /> </svg>
</div> </div>
{% endif %}
</div> </div>
<!-- prettier-ignore --> <!-- prettier-ignore -->
<dt class="flex w-full mb-1 text-gray-500 md:text-lg dark:text-gray-400 flex-col"> <dt class="flex w-full mb-1 text-gray-500 md:text-lg dark:text-gray-400 flex-col">
@ -117,7 +115,7 @@
</span> </span>
<span class="space-x-0.5 flex items-center"> <span class="space-x-0.5 flex items-center">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M3.75 13.5l10.5-11.25L12 10.5h8.25L9.75 21.75 12 13.5H3.75z" /> </svg> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M3.75 13.5l10.5-11.25L12 10.5h8.25L9.75 21.75 12 13.5H3.75z" /> </svg>
<p>{{ book.approved_interpretations|length }}</p> <p>{{ book.interpretations|length }}</p>
</span> </span>
<span class="space-x-0.5 flex items-center"> <span class="space-x-0.5 flex items-center">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" /> </svg> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" /> </svg>

View File

@ -63,7 +63,7 @@
</span> </span>
<span class="space-x-0.5 flex items-center"> <span class="space-x-0.5 flex items-center">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M3.75 13.5l10.5-11.25L12 10.5h8.25L9.75 21.75 12 13.5H3.75z" /> </svg> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M3.75 13.5l10.5-11.25L12 10.5h8.25L9.75 21.75 12 13.5H3.75z" /> </svg>
<p>{{ book.approved_interpretations|length }}</p> <p>{{ book.interpretations|length }}</p>
</span> </span>
<span class="space-x-0.5 flex items-center"> <span class="space-x-0.5 flex items-center">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" /> </svg> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" /> </svg>

View File

@ -51,7 +51,7 @@
</span> </span>
<span class="space-x-0.5 flex items-center"> <span class="space-x-0.5 flex items-center">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M3.75 13.5l10.5-11.25L12 10.5h8.25L9.75 21.75 12 13.5H3.75z" /> </svg> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M3.75 13.5l10.5-11.25L12 10.5h8.25L9.75 21.75 12 13.5H3.75z" /> </svg>
<p>{{ book.approved_interpretations|length }}</p> <p>{{ book.interpretations|length }}</p>
</span> </span>
<span class="space-x-0.5 flex items-center"> <span class="space-x-0.5 flex items-center">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" /> </svg> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" /> </svg>

View File

@ -63,7 +63,7 @@
</span> </span>
<span class="space-x-0.5 flex items-center"> <span class="space-x-0.5 flex items-center">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M3.75 13.5l10.5-11.25L12 10.5h8.25L9.75 21.75 12 13.5H3.75z" /> </svg> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M3.75 13.5l10.5-11.25L12 10.5h8.25L9.75 21.75 12 13.5H3.75z" /> </svg>
<p>{{ book.approved_interpretations|length }}</p> <p>{{ book.interpretations|length }}</p>
</span> </span>
<span class="space-x-0.5 flex items-center"> <span class="space-x-0.5 flex items-center">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" /> </svg> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22" stroke-width="1" stroke="currentColor" class="w-4 h-4 inline-flex mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" /> </svg>

View File

@ -46,8 +46,16 @@ def my_library():
if current_user.is_authenticated: if current_user.is_authenticated:
log(log.INFO, "Create query for my_library page for books") log(log.INFO, "Create query for my_library page for books")
books: m.Book = m.Book.query.order_by(m.Book.id) books: m.Book = (
books = books.filter_by(user_id=current_user.id, is_deleted=False) db.session.query(m.Book)
.join(m.BookContributor, m.BookContributor.book_id == m.Book.id, full=True)
.filter(
m.Book.user_id == current_user.id,
m.Book.is_deleted == False, # noqa: E712
)
.group_by(m.Book.id)
)
log(log.INFO, "Create pagination for books") log(log.INFO, "Create pagination for books")
pagination = create_pagination(total=books.count()) pagination = create_pagination(total=books.count())

View File

@ -1,10 +1,11 @@
from flask import ( from flask import (
Blueprint, Blueprint,
jsonify, jsonify,
request,
) )
from flask_login import login_required, current_user from flask_login import login_required, current_user
from app import models as m, db, forms as f from app import models as m, db
from app.logger import log from app.logger import log
bp = Blueprint("vote", __name__, url_prefix="/vote") bp = Blueprint("vote", __name__, url_prefix="/vote")
@ -23,55 +24,44 @@ def vote_interpretation(interpretation_id: int):
log(log.WARNING, "Interpretation with id [%s] not found", interpretation_id) log(log.WARNING, "Interpretation with id [%s] not found", interpretation_id)
return jsonify({"message": "Interpretation not found"}), 404 return jsonify({"message": "Interpretation not found"}), 404
form = f.VoteForm() vote: m.InterpretationVote = m.InterpretationVote.query.filter_by(
if form.validate_on_submit(): user_id=current_user.id, interpretation_id=interpretation_id
vote: m.InterpretationVote = m.InterpretationVote.query.filter_by( ).first()
user_id=current_user.id, interpretation_id=interpretation_id if vote:
).first() db.session.delete(vote)
if vote:
db.session.delete(vote)
positive = form.positive.data and "true" in [ positive = request.json.get("positive") in ("true", True)
data.lower() for data in form.positive.raw_data
]
if not vote or vote.positive != positive:
vote: m.InterpretationVote = m.InterpretationVote(
user_id=current_user.id,
interpretation_id=interpretation_id,
positive=positive,
)
log(
log.INFO,
"User [%s]. [%s] vote interpretation: [%s]",
current_user,
"Positive" if positive else "Negative",
interpretation,
)
vote.save(False)
else:
log(
log.INFO,
"User [%s]. Remove [%s] vote for interpretation: [%s]",
current_user,
"positive" if positive else "negative",
interpretation,
)
db.session.commit()
return jsonify( if not vote or vote.positive != positive:
{ vote: m.InterpretationVote = m.InterpretationVote(
"vote_count": interpretation.vote_count, user_id=current_user.id,
"current_user_vote": interpretation.current_user_vote, interpretation_id=interpretation_id,
} positive=positive,
) )
log(
log.INFO,
"User [%s]. [%s] vote interpretation: [%s]",
current_user,
"Positive" if positive else "Negative",
interpretation,
)
vote.save(False)
else:
log(
log.INFO,
"User [%s]. Remove [%s] vote for interpretation: [%s]",
current_user,
"positive" if positive else "negative",
interpretation,
)
db.session.commit()
log( return jsonify(
log.CRITICAL, {
"Unexpected error: User [%s]. Vote for interpretation: [%s]", "vote_count": interpretation.vote_count,
current_user, "current_user_vote": interpretation.current_user_vote,
interpretation, }
) )
return jsonify({"message": "Unexpected error"}), 400
@bp.route( @bp.route(
@ -85,52 +75,41 @@ def vote_comment(comment_id: int):
log(log.WARNING, "Comment with id [%s] not found", comment_id) log(log.WARNING, "Comment with id [%s] not found", comment_id)
return jsonify({"message": "Comment not found"}), 404 return jsonify({"message": "Comment not found"}), 404
form = f.VoteForm() vote: m.CommentVote = m.CommentVote.query.filter_by(
if form.validate_on_submit(): user_id=current_user.id, comment_id=comment_id
vote: m.CommentVote = m.CommentVote.query.filter_by( ).first()
user_id=current_user.id, comment_id=comment_id if vote:
).first() db.session.delete(vote)
if vote:
db.session.delete(vote)
positive = form.positive.data and "true" in [ positive = request.json.get("positive") in ("true", True)
data.lower() for data in form.positive.raw_data
]
if not vote or vote.positive != positive:
vote: m.CommentVote = m.CommentVote(
user_id=current_user.id,
comment_id=comment_id,
positive=positive,
)
log(
log.INFO,
"User [%s]. [%s] vote comment: [%s]",
current_user,
"Positive" if positive else "Negative",
comment,
)
vote.save(False)
else:
log(
log.INFO,
"User [%s]. Remove [%s] vote for comment: [%s]",
current_user,
"positive" if positive else "negative",
comment,
)
db.session.commit()
return jsonify( if not vote or vote.positive != positive:
{ vote: m.CommentVote = m.CommentVote(
"vote_count": comment.vote_count, user_id=current_user.id,
"current_user_vote": comment.current_user_vote, comment_id=comment_id,
} positive=positive,
) )
log(
log.INFO,
"User [%s]. [%s] vote comment: [%s]",
current_user,
"Positive" if positive else "Negative",
comment,
)
vote.save(False)
else:
log(
log.INFO,
"User [%s]. Remove [%s] vote for comment: [%s]",
current_user,
"positive" if positive else "negative",
comment,
)
db.session.commit()
log( return jsonify(
log.CRITICAL, {
"Unexpected error: User [%s]. Vote for comment: [%s]", "vote_count": comment.vote_count,
current_user, "current_user_vote": comment.current_user_vote,
comment, }
) )
return jsonify({"message": "Unexpected error"}), 400

957
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -47,7 +47,6 @@ export function deleteInterpretation() {
}), }),
); );
const modalOptions: ModalOptions = { const modalOptions: ModalOptions = {
placement: 'bottom-right',
closable: true, closable: true,
onHide: () => { onHide: () => {
deleteInterpretationForm.setAttribute('action', ''); deleteInterpretationForm.setAttribute('action', '');

View File

@ -9,10 +9,15 @@ export function renameCollection() {
btn.addEventListener('click', () => { btn.addEventListener('click', () => {
const inputsForRename: NodeListOf<HTMLInputElement> = const inputsForRename: NodeListOf<HTMLInputElement> =
document.querySelectorAll(`[id^="edit-collection-label-"]`); document.querySelectorAll(`[id^="edit-collection-label-"]`);
const scrfInput: HTMLInputElement =
document.querySelector('#csrf_token');
inputsForRename[index].removeAttribute('readonly'); inputsForRename[index].removeAttribute('readonly');
const oldName = inputsForRename[index].value; const oldName = inputsForRename[index].value;
inputsForRename[index].value = ''; inputsForRename[index].value = oldName;
inputsForRename[index].focus(); inputsForRename[index].focus();
inputsForRename[index].selectionStart = inputsForRename[
index
].selectionEnd = 257;
inputsForRename[index].addEventListener('blur', () => { inputsForRename[index].addEventListener('blur', () => {
inputsForRename[index].value = oldName; inputsForRename[index].value = oldName;
}); });
@ -35,6 +40,7 @@ export function renameCollection() {
}, },
body: JSON.stringify({ body: JSON.stringify({
label: newLabel, label: newLabel,
csrf_token: scrfInput.value,
}), }),
}); });
if (response.status == 200) { if (response.status == 200) {

View File

@ -4,18 +4,26 @@ export function renameSection() {
); );
const sectionRenameForms: NodeListOf<HTMLFormElement> = const sectionRenameForms: NodeListOf<HTMLFormElement> =
document.querySelectorAll('[id^="rename-section-label-form-"]'); document.querySelectorAll('[id^="rename-section-label-form-"]');
if (renameSectionBtns.length > 0 && sectionRenameForms.length > 0) { if (renameSectionBtns.length > 0 && sectionRenameForms.length > 0) {
renameSectionBtns.forEach((btn, index) => { renameSectionBtns.forEach((btn, index) => {
btn.addEventListener('click', () => { btn.addEventListener('click', () => {
const inputsForRename: NodeListOf<HTMLInputElement> = const inputsForRename: NodeListOf<HTMLInputElement> =
document.querySelectorAll(`[id^="edit-section-label-"]`); document.querySelectorAll(`[id^="edit-section-label-"]`);
const scrfInput: HTMLInputElement =
document.querySelector('#csrf_token');
console.log(scrfInput.value);
const oldName = inputsForRename[index].value; const oldName = inputsForRename[index].value;
inputsForRename[index].removeAttribute('readonly'); inputsForRename[index].removeAttribute('readonly');
inputsForRename[index].value = ''; inputsForRename[index].value = oldName;
inputsForRename[index].focus(); inputsForRename[index].focus();
inputsForRename[index].selectionStart = inputsForRename[
index
].selectionEnd = 257;
inputsForRename[index].addEventListener('blur', () => { inputsForRename[index].addEventListener('blur', () => {
inputsForRename[index].value = oldName; inputsForRename[index].value = oldName;
}); });
console.log(sectionRenameForms[index]);
sectionRenameForms[index].addEventListener('submit', async e => { sectionRenameForms[index].addEventListener('submit', async e => {
e.preventDefault(); e.preventDefault();
const bookId = sectionRenameForms[index].getAttribute('data-book-id'); const bookId = sectionRenameForms[index].getAttribute('data-book-id');
@ -36,6 +44,7 @@ export function renameSection() {
body: JSON.stringify({ body: JSON.stringify({
label: newLabel, label: newLabel,
section_id: sectionId, section_id: sectionId,
csrf_token: scrfInput.value,
}), }),
}); });
if (response.status == 200) { if (response.status == 200) {

View File

@ -12,10 +12,15 @@ export function renameSubCollection() {
btn.addEventListener('click', () => { btn.addEventListener('click', () => {
const inputsForRename: NodeListOf<HTMLInputElement> = const inputsForRename: NodeListOf<HTMLInputElement> =
document.querySelectorAll(`[id^="edit-sub-collection-label-"]`); document.querySelectorAll(`[id^="edit-sub-collection-label-"]`);
const scrfInput: HTMLInputElement =
document.querySelector('#csrf_token');
const oldName = inputsForRename[index].value; const oldName = inputsForRename[index].value;
inputsForRename[index].removeAttribute('readonly'); inputsForRename[index].removeAttribute('readonly');
inputsForRename[index].value = ''; inputsForRename[index].value = oldName;
inputsForRename[index].focus(); inputsForRename[index].focus();
inputsForRename[index].selectionStart = inputsForRename[
index
].selectionEnd = 257;
inputsForRename[index].addEventListener('blur', () => { inputsForRename[index].addEventListener('blur', () => {
inputsForRename[index].value = oldName; inputsForRename[index].value = oldName;
}); });
@ -39,6 +44,7 @@ export function renameSubCollection() {
}, },
body: JSON.stringify({ body: JSON.stringify({
label: newLabel, label: newLabel,
csrf_token: scrfInput.value,
}), }),
}); });
if (response.status == 200) { if (response.status == 200) {

View File

@ -1,7 +1,20 @@
export function scroll() { export function scroll() {
const btns = document.querySelectorAll('[href^="#section-"]'); const btns = document.querySelectorAll('[href^="#section-"]');
if (btns) { if (btns) {
btns.forEach((btn, index) => { btns.forEach(btn => {
btn.addEventListener('click', () => {
let link = btn.getAttribute('href');
link = link.replace('#', '');
const neededSection = document.querySelector(`[id^="${link}"]`);
if (neededSection) {
neededSection.scrollIntoView(true);
}
});
});
}
const collectionBtns = document.querySelectorAll('[href^="#collection-"]');
if (collectionBtns) {
collectionBtns.forEach(btn => {
btn.addEventListener('click', () => { btn.addEventListener('click', () => {
let link = btn.getAttribute('href'); let link = btn.getAttribute('href');
link = link.replace('#', ''); link = link.replace('#', '');

View File

@ -17,7 +17,6 @@ const voteClickEventListener = async (
const positive = btn.getAttribute('data-positive'); const positive = btn.getAttribute('data-positive');
const entityId = btn.getAttribute('data-entity-id'); const entityId = btn.getAttribute('data-entity-id');
const requestUrl = REQUEST_URLS[voteFor] + entityId; const requestUrl = REQUEST_URLS[voteFor] + entityId;
const response = await fetch(requestUrl, { const response = await fetch(requestUrl, {
method: 'POST', method: 'POST',

View File

@ -10,7 +10,8 @@ def test_upvote_interpretation(client: FlaskClient):
response: Response = client.post( response: Response = client.post(
"/vote/interpretation/999", "/vote/interpretation/999",
data=dict( headers={"Content-Type": "application/json"},
json=dict(
positive=True, positive=True,
), ),
follow_redirects=True, follow_redirects=True,
@ -29,7 +30,8 @@ def test_upvote_interpretation(client: FlaskClient):
response: Response = client.post( response: Response = client.post(
f"/vote/interpretation/{interpretation.id}", f"/vote/interpretation/{interpretation.id}",
data=dict( headers={"Content-Type": "application/json"},
json=dict(
positive=True, positive=True,
), ),
follow_redirects=True, follow_redirects=True,
@ -47,7 +49,8 @@ def test_upvote_interpretation(client: FlaskClient):
response: Response = client.post( response: Response = client.post(
f"/vote/interpretation/{interpretation.id}", f"/vote/interpretation/{interpretation.id}",
data=dict( headers={"Content-Type": "application/json"},
json=dict(
positive=True, positive=True,
), ),
follow_redirects=True, follow_redirects=True,
@ -65,7 +68,8 @@ def test_upvote_interpretation(client: FlaskClient):
response: Response = client.post( response: Response = client.post(
f"/vote/interpretation/{interpretation.id}", f"/vote/interpretation/{interpretation.id}",
data=dict( headers={"Content-Type": "application/json"},
json=dict(
positive=False, positive=False,
), ),
follow_redirects=True, follow_redirects=True,
@ -83,7 +87,8 @@ def test_upvote_interpretation(client: FlaskClient):
response: Response = client.post( response: Response = client.post(
f"/vote/interpretation/{interpretation.id}", f"/vote/interpretation/{interpretation.id}",
data=dict( headers={"Content-Type": "application/json"},
json=dict(
positive=False, positive=False,
), ),
follow_redirects=True, follow_redirects=True,
@ -105,7 +110,8 @@ def test_upvote_comment(client: FlaskClient):
response: Response = client.post( response: Response = client.post(
"/vote/comment/999", "/vote/comment/999",
data=dict( headers={"Content-Type": "application/json"},
json=dict(
positive=True, positive=True,
), ),
follow_redirects=True, follow_redirects=True,
@ -124,7 +130,8 @@ def test_upvote_comment(client: FlaskClient):
response: Response = client.post( response: Response = client.post(
f"/vote/comment/{comment.id}", f"/vote/comment/{comment.id}",
data=dict( headers={"Content-Type": "application/json"},
json=dict(
positive=True, positive=True,
), ),
follow_redirects=True, follow_redirects=True,
@ -142,7 +149,8 @@ def test_upvote_comment(client: FlaskClient):
response: Response = client.post( response: Response = client.post(
f"/vote/comment/{comment.id}", f"/vote/comment/{comment.id}",
data=dict( headers={"Content-Type": "application/json"},
json=dict(
positive=True, positive=True,
), ),
follow_redirects=True, follow_redirects=True,
@ -160,7 +168,8 @@ def test_upvote_comment(client: FlaskClient):
response: Response = client.post( response: Response = client.post(
f"/vote/comment/{comment.id}", f"/vote/comment/{comment.id}",
data=dict( headers={"Content-Type": "application/json"},
json=dict(
positive=False, positive=False,
), ),
follow_redirects=True, follow_redirects=True,
@ -178,7 +187,8 @@ def test_upvote_comment(client: FlaskClient):
response: Response = client.post( response: Response = client.post(
f"/vote/comment/{comment.id}", f"/vote/comment/{comment.id}",
data=dict( headers={"Content-Type": "application/json"},
json=dict(
positive=False, positive=False,
), ),
follow_redirects=True, follow_redirects=True,