Compare commits
No commits in common. "819aa6784fc45c39e6cc862f1969005c7cacd1b7" and "1ce84db59c0900d24804121ca2bc39b62d1921e0" have entirely different histories.
819aa6784f
...
1ce84db59c
|
@ -1,10 +1,4 @@
|
|||
import csv
|
||||
from datetime import datetime
|
||||
import io
|
||||
import os
|
||||
|
||||
from flask import Blueprint, render_template, request
|
||||
from loguru import logger
|
||||
|
||||
from app.models.collection import Collection
|
||||
from app.extensions import db
|
||||
|
@ -45,22 +39,3 @@ def delete_collection(id: int):
|
|||
return "<small class=\"form-text\">Здесь ничего нет</small>", 200
|
||||
|
||||
return "", 200
|
||||
|
||||
@collections.route("/<int:id>/csv", methods=["GET"])
|
||||
def export_users_to_csv(id: int):
|
||||
collection: Collection = Collection.query.get_or_404(id)
|
||||
|
||||
if len(collection.users) <= 0:
|
||||
return "", 204
|
||||
|
||||
filename = f"{collection.name} - {datetime.now()}.csv"
|
||||
|
||||
fieldnames = collection.users[0].to_dict().keys()
|
||||
si = io.StringIO()
|
||||
|
||||
writer = csv.DictWriter(si, fieldnames)
|
||||
|
||||
writer.writeheader()
|
||||
writer.writerows(map(lambda user: user.to_dict(), collection.users))
|
||||
|
||||
return si.getvalue(), 200, {'Content-Disposition': f'attachment; filename={filename}', 'Content-type': 'text/csv'}
|
|
@ -4,27 +4,17 @@
|
|||
<ul class="list-group list-group-flush">
|
||||
<li class="list-group-item">Кол-во пользрвателей: {{ collection.users|length }}</li>
|
||||
</ul>
|
||||
<div class="card-footer px-2 pt-2">
|
||||
<div class="d-flex gap-2" role="group">
|
||||
<form action="/api/collections/{{ collection.id }}" method="DELETE">
|
||||
<button
|
||||
type="submit"
|
||||
hx-delete="/api/collections/{{ collection.id }}"
|
||||
hx-swap="outerHTML"
|
||||
hx-target='[data-collection-id="{{ collection.id }}"]'
|
||||
hx-confirm="Вы уверены, что хотите удалить коллекцию?"
|
||||
class="btn btn-outline-danger"
|
||||
>
|
||||
Удалить
|
||||
</button>
|
||||
</form>
|
||||
<a
|
||||
href="/api/collections/{{ collection.id }}/csv"
|
||||
class="btn btn-outline-success"
|
||||
>
|
||||
Экспорт
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<form action="/api/collections/{{ collection.id }}" method="DELETE" class="card-footer px-2 pt-2">
|
||||
<button
|
||||
type="submit"
|
||||
hx-delete="/api/collections/{{ collection.id }}"
|
||||
hx-swap="outerHTML"
|
||||
hx-target='[data-collection-id="{{ collection.id }}"]'
|
||||
hx-confirm="Вы уверены, что хотите удалить коллекцию?"
|
||||
class="btn btn-outline-danger"
|
||||
>
|
||||
Удалить
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
|
@ -59,7 +59,7 @@ def delete_task(task_id: int):
|
|||
db.session.delete(task)
|
||||
db.session.commit()
|
||||
|
||||
return '', 200
|
||||
return '', 204
|
||||
|
||||
@tasks.route("/<int:task_id>/stop", methods=["PUT"])
|
||||
def stop_task(task_id: int):
|
||||
|
|
|
@ -19,13 +19,4 @@ class User(db.Model):
|
|||
collection: Mapped["Collection"] = relationship("Collection", back_populates="users")
|
||||
|
||||
def exist(username: str, collection):
|
||||
return not User.query.filter_by(username=username, collection=collection).first() is None
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
'id': self.id,
|
||||
'first_name': self.first_name,
|
||||
'last_name': self.last_name,
|
||||
'phone': self.phone,
|
||||
'username': self.username,
|
||||
}
|
||||
return not User.query.filter_by(username=username, collection=collection).first() is None
|
Loading…
Reference in New Issue