Added deleting of collections

This commit is contained in:
Анатолий Богомолов 2024-03-07 02:56:27 +10:00
parent cf76eb5b90
commit 09b5b36f86
3 changed files with 31 additions and 12 deletions

View File

@ -1,3 +1,21 @@
from flask import Blueprint, render_template, request
from app.models.collection import Collection
from app.extensions import db
collections = Blueprint("collections", __name__, url_prefix="/collections", template_folder="templates")
@collections.route("/<int:id>", methods=["DELETE"])
def delete_collection(id: int):
collection: Collection = Collection.query.get_or_404(id)
length = len(Collection.query.all()) - 1
db.session.delete(collection)
db.session.commit()
if length <= 0:
return "<small class=\"form-text\">Здесь ничего нет</small>", 200
return "", 204

View File

@ -1,19 +1,18 @@
<div data-collection-id="{{ collection.id }}" class="card">
<div class="card-header">{{ collection.name }}</div>
<div class="card-body">
<div class="card-header"><h5>{{ collection.name }}</h5></div>
<ul class="list-group list-group-flush">
<li class="list-group-item">{{ collection.users.lenght() }}</li>
<li class="list-group-item">Кол-во пользрвателей: {{ collection.users|length }}</li>
</ul>
</div>
<from action="/api/collection/{{ collection.id }}" method="DELETE" class="card-footer px-2 pt-2">
<form action="/api/collections/{{ collection.id }}" method="DELETE" class="card-footer px-2 pt-2">
<button
type="submit"
hx-delete='[data-collection-id="{{ collection.id }}"]'
hx-delete="/api/collections/{{ collection.id }}"
hx-swap="outerHTML"
hx-target='[data-collection-id="{{ collection.id }}"]'
hx-confirm="Вы уверены, что хотите удалить коллекцию?"
class="btn btn-outline-danger"
>
Удалить
</button>
</from>
</form>
</div>

View File

@ -1,7 +1,9 @@
<div id="cards-grid" class="row row-cols-1 row-cols-sm-2 row-cols-md-3 row-cols-lg-4">
{% for collection in collections %}
<div id="cards-grid" class="row row-cols-1 row-cols-sm-2 row-cols-md-3 row-cols-lg-4">
<div class="col mb-3">
{% include "collections/card.j2" %}
</div>
{% else %}
Здесь ничего нет
<small class="form-text">Здесь ничего нет.</small>
{% endfor %}
</div>