From bec3d5a0eaa08b56e2c7b527856c7d4b775fc661 Mon Sep 17 00:00:00 2001 From: cato447 Date: Tue, 28 Oct 2025 22:58:36 +0100 Subject: [PATCH] added download button to slides with pdfs --- .gitignore | 1 + app/models.py | 5 ++++- app/routes.py | 25 +++++++++++++++++++++++++ app/templates/index.html | 29 +++++++++++++++++++++++------ 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 593f83f..8d5b05d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,6 @@ node_modules .venv config.py slides +exports log nohup.out diff --git a/app/models.py b/app/models.py index 8c13ddf..0c5182a 100644 --- a/app/models.py +++ b/app/models.py @@ -71,6 +71,7 @@ class Deck(db.Model): deck : Mapped[str] = mapped_column(String(60), nullable=False) description : Mapped[str] = mapped_column(String(60)) index_file: Mapped[str] = mapped_column(String(40), nullable=False) + export_file: Mapped[Optional[str]] = mapped_column(String(40), nullable=True) passwords : Mapped[List[Password]] = relationship("Password", secondary=deck_password, back_populates='decks') tokens : Mapped[List[Token]] = relationship("Token", secondary=deck_token, back_populates='decks') @@ -78,12 +79,14 @@ class Deck(db.Model): course: Mapped['Course'] = relationship("Course", back_populates='decks') - def __init__(self, name: str, deck: str, course: Course, description: str = "", index_file: str = "index.html") -> None: + def __init__(self, name: str, deck: str, course: Course, description: str = "", index_file: str = "index.html", export_file: str | None = None) -> None: self.name = name self.deck = deck self.description = description self.course = course self.index_file = index_file + if export_file: + self.export_file = export_file def __repr__(self) -> str: return f"" diff --git a/app/routes.py b/app/routes.py index d074711..1f59b5c 100644 --- a/app/routes.py +++ b/app/routes.py @@ -102,6 +102,9 @@ def index(): if not token: return redirect(url_for("main.set_token")) else: + for deck in get_unlocked_decks(token): + print(str(deck) + " | " + str(deck.export_file)) + return render_template('index.html', active_banner=get_active_banner(), decks=get_unlocked_decks(token), user_name=token.name, active_course_name=token.active_course.name, courses=get_all_courses()) def set_cookie(token): @@ -308,6 +311,28 @@ def serve_deck(deck, course_folder, path='index.html'): abort(404) + +@main.route('/exports///') +def serve_export(deck, course_folder, path): + course = db.session.execute(db.select(Course).where(Course.folder==course_folder)).scalar() + if not course: + abort(404) + assert isinstance(course, Course) + deck = db.session.execute(db.select(Deck).where(Deck.deck==deck and Deck.course_id == course.id)).scalar() + if not deck: + abort(404) + assert isinstance(deck, Deck) + + if not is_deck_unlocked(deck.deck): + return redirect(url_for('main.index')) + exports_dir = os.path.join(current_app.config['EXPORTS_DIR'], course.folder) + deck_path = os.path.join(exports_dir, deck.deck) + requested_file = os.path.join(deck_path, path) + if os.path.isfile(requested_file): + return send_from_directory(deck_path, path) + abort(404) + + @main.route('/admin', methods=['GET', 'POST']) @flask_login.login_required def admin(): diff --git a/app/templates/index.html b/app/templates/index.html index 1e3fdd8..0b47ad0 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -130,14 +130,31 @@ {% if decks %}
-
+
{% for deck in decks %} - -

{{ deck.name }}

-

{{ deck.description }}

-
+
+ +
+ + +

{{ deck.name }}

+

{{ deck.description }}

+
+ {% if deck.export_file %} + + + + + + {% endif %} +
+ +
{% endfor %} -
+
{% else %}

No decks unlocked yet.