Merge pull request #102 from Simple2B/kostia/fixes/fix_issues

Kostia/fixes/fix issues
This commit is contained in:
Костя Столярский 2023-06-01 14:43:02 +03:00 committed by GitHub
commit 193064ce41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 758 additions and 647 deletions

View File

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

View File

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

View File

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

View File

@ -92,3 +92,27 @@ class Book(BaseModel):
)
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):
return [section for section in self.sections if not section.is_deleted]
@property
def book_id(self):
return self.version.book_id
@property
def sub_collections(self):
return [

File diff suppressed because one or more lines are too long

View File

@ -27,7 +27,7 @@
</span>
<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>
<p>{{ book.approved_interpretations|length }}</p>
<p>{{ book.interpretations|length }}</p>
</span>
<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>

View File

@ -48,13 +48,13 @@
<!-- 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>
</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_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/>
<button name="submit" type="submit"></button>
</form>
</a>
</button>
</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>
</div>
@ -133,7 +133,7 @@
<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 %}
<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 %}
<p class="ml-3 my-3 italic text-sm">Collection is empty</p>
{% endif %}

View File

@ -1,7 +1,9 @@
{% if not collection.is_leaf %}
<!-- if collection has sub_collection make for loop for it -->
{% 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 %}
<p class="ml-3 my-3 italic text-sm">This sub collection is empty</p>
{% endif %}

View File

@ -2,8 +2,8 @@
{% if not collection.is_leaf %}
<!-- if collection has sub_collection make for loop for it -->
<!-- Nested accordion -->
{% for sub_collection in collection.children if not
sub_collection.is_deleted%}
<!-- prettier-ignore -->
{% for sub_collection in collection.children if not sub_collection.is_deleted%}
<div id="accordion-nested-collapse" data-accordion="open">
<!-- 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">
@ -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>
</button>
<!-- 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_hidden_tag() }}
<!-- 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 />
<button name="submit" type="submit"></button>
</form>
</a>
</button>
</div>
<!-- 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>
@ -36,6 +36,13 @@
<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>
{% 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 %}
<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>

View File

@ -16,7 +16,7 @@
{% if current_user.is_authenticated and current_user.stars|length==0 %}
<!-- prettier-ignore -->
<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 -->
{% endif %}
<!-- prettier-ignore -->
@ -41,7 +41,7 @@
</span>
<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>
<p>{{ book.approved_interpretations|length }}</p>
<p>{{ book.interpretations|length }}</p>
</span>
<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>

View File

@ -86,7 +86,6 @@
<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="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">
<svg class="w-6 h-6 select-none
{% if interpretation.current_user_vote %}
@ -94,7 +93,7 @@
{% 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>
</div>
{% endif %}
<span
class="vote-count text-3xl select-none
@ -108,7 +107,6 @@
{{ interpretation.vote_count }}
</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">
<svg class="w-6 h-6 select-none
{% if interpretation.current_user_vote == False %}
@ -116,7 +114,6 @@
{% 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>
</div>
{% endif %}
<!-- TODO check permissions -->
{% if interpretation.book.owner == current_user %}

View File

@ -21,14 +21,6 @@
</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 -->
<div class="flex items-center p-6 space-x-2 border-t border-gray-200 rounded-b dark:border-gray-600">
<button name="submit" type="submit" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Create</button>

View File

@ -20,13 +20,6 @@
</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 -->
<div class="flex items-center p-6 space-x-2 border-t border-gray-200 rounded-b dark:border-gray-600">
<button name="submit" type="submit" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Create</button>

View File

@ -47,7 +47,7 @@
</span>
<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>
<p>{{ book.approved_interpretations|length }}</p>
<p>{{ book.interpretations|length }}</p>
</span>
<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>

View File

@ -79,7 +79,7 @@
<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="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">
<svg
class="w-6 h-6 select-none
@ -89,7 +89,7 @@
"
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>
{% endif %}
<span
class="vote-count text-3xl select-none
@ -103,7 +103,7 @@
{{ comment.vote_count }}
</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">
<svg class="w-6 h-6 select-none
{% if comment.current_user_vote == False %}
@ -111,7 +111,6 @@
{% 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>
</div>
{% endif %}
<!-- TODO check permissions -->
{% if interpretation.book.owner == current_user %}

View File

@ -33,7 +33,6 @@
<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="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">
<svg class="w-6 h-6 select-none
{% if interpretation.current_user_vote %}
@ -41,7 +40,7 @@
{% 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>
</div>
{% endif %}
<span
class="vote-count text-3xl select-none
@ -55,7 +54,7 @@
{{ interpretation.vote_count }}
</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">
<svg class="w-6 h-6 select-none
{% if interpretation.current_user_vote == False %}
@ -63,7 +62,6 @@
{% 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>
</div>
{% endif %}
</div>
<!-- prettier-ignore -->
<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 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>
<p>{{ book.approved_interpretations|length }}</p>
<p>{{ book.interpretations|length }}</p>
</span>
<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>

View File

@ -63,7 +63,7 @@
</span>
<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>
<p>{{ book.approved_interpretations|length }}</p>
<p>{{ book.interpretations|length }}</p>
</span>
<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>

View File

@ -51,7 +51,7 @@
</span>
<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>
<p>{{ book.approved_interpretations|length }}</p>
<p>{{ book.interpretations|length }}</p>
</span>
<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>

View File

@ -63,7 +63,7 @@
</span>
<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>
<p>{{ book.approved_interpretations|length }}</p>
<p>{{ book.interpretations|length }}</p>
</span>
<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>

View File

@ -46,8 +46,16 @@ def my_library():
if current_user.is_authenticated:
log(log.INFO, "Create query for my_library page for books")
books: m.Book = m.Book.query.order_by(m.Book.id)
books = books.filter_by(user_id=current_user.id, is_deleted=False)
books: m.Book = (
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")
pagination = create_pagination(total=books.count())

View File

@ -1,10 +1,11 @@
from flask import (
Blueprint,
jsonify,
request,
)
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
bp = Blueprint("vote", __name__, url_prefix="/vote")
@ -23,17 +24,14 @@ def vote_interpretation(interpretation_id: int):
log(log.WARNING, "Interpretation with id [%s] not found", interpretation_id)
return jsonify({"message": "Interpretation not found"}), 404
form = f.VoteForm()
if form.validate_on_submit():
vote: m.InterpretationVote = m.InterpretationVote.query.filter_by(
user_id=current_user.id, interpretation_id=interpretation_id
).first()
if vote:
db.session.delete(vote)
positive = form.positive.data and "true" in [
data.lower() for data in form.positive.raw_data
]
positive = request.json.get("positive") in ("true", True)
if not vote or vote.positive != positive:
vote: m.InterpretationVote = m.InterpretationVote(
user_id=current_user.id,
@ -65,14 +63,6 @@ def vote_interpretation(interpretation_id: int):
}
)
log(
log.CRITICAL,
"Unexpected error: User [%s]. Vote for interpretation: [%s]",
current_user,
interpretation,
)
return jsonify({"message": "Unexpected error"}), 400
@bp.route(
"/comment/<int:comment_id>",
@ -85,17 +75,14 @@ def vote_comment(comment_id: int):
log(log.WARNING, "Comment with id [%s] not found", comment_id)
return jsonify({"message": "Comment not found"}), 404
form = f.VoteForm()
if form.validate_on_submit():
vote: m.CommentVote = m.CommentVote.query.filter_by(
user_id=current_user.id, comment_id=comment_id
).first()
if vote:
db.session.delete(vote)
positive = form.positive.data and "true" in [
data.lower() for data in form.positive.raw_data
]
positive = request.json.get("positive") in ("true", True)
if not vote or vote.positive != positive:
vote: m.CommentVote = m.CommentVote(
user_id=current_user.id,
@ -126,11 +113,3 @@ def vote_comment(comment_id: int):
"current_user_vote": comment.current_user_vote,
}
)
log(
log.CRITICAL,
"Unexpected error: User [%s]. Vote for comment: [%s]",
current_user,
comment,
)
return jsonify({"message": "Unexpected error"}), 400

957
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

@ -1,7 +1,20 @@
export function scroll() {
const btns = document.querySelectorAll('[href^="#section-"]');
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', () => {
let link = btn.getAttribute('href');
link = link.replace('#', '');

View File

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

View File

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