mirror of
https://github.com/partitioncloud/partitioncloud-server.git
synced 2025-01-23 17:26:26 +01:00
Ajout d'une vue de toutes les partitions
This commit is contained in:
parent
b1052563f7
commit
870d71fc5b
@ -93,7 +93,7 @@ def create_album():
|
||||
db = get_db()
|
||||
error = None
|
||||
|
||||
if not name:
|
||||
if not name or name.strip() == "":
|
||||
error = "Un nom est requis."
|
||||
|
||||
if error is None:
|
||||
|
@ -17,6 +17,7 @@ from flask import (
|
||||
from werkzeug.security import check_password_hash, generate_password_hash
|
||||
|
||||
from .db import get_db
|
||||
from .utils import User
|
||||
|
||||
bp = Blueprint("auth", __name__, url_prefix="/auth")
|
||||
|
||||
@ -34,6 +35,23 @@ def login_required(view):
|
||||
return wrapped_view
|
||||
|
||||
|
||||
def admin_required(view):
|
||||
"""View decorator that redirects anonymous users to the login page."""
|
||||
|
||||
@functools.wraps(view)
|
||||
def wrapped_view(**kwargs):
|
||||
if g.user is None:
|
||||
return redirect(url_for("auth.login"))
|
||||
|
||||
user = User(session.get("user_id"))
|
||||
if user.access_level != 1:
|
||||
return redirect("/albums")
|
||||
|
||||
return view(**kwargs)
|
||||
|
||||
return wrapped_view
|
||||
|
||||
|
||||
@bp.before_app_request
|
||||
def load_logged_in_user():
|
||||
"""If a user id is stored in the session, load the user object from
|
||||
|
@ -3,10 +3,11 @@
|
||||
Partition module
|
||||
"""
|
||||
import os
|
||||
from flask import Blueprint, abort, send_file
|
||||
from flask import Blueprint, abort, send_file, render_template
|
||||
|
||||
from .db import get_db
|
||||
from .auth import login_required
|
||||
from .auth import login_required, admin_required
|
||||
from .utils import get_all_partitions
|
||||
|
||||
|
||||
bp = Blueprint("partition", __name__, url_prefix="/partition")
|
||||
@ -26,3 +27,10 @@ def partition(uuid):
|
||||
if partition is None:
|
||||
abort(404)
|
||||
return send_file(os.path.join("partitions", f"{uuid}.pdf"))
|
||||
|
||||
|
||||
@bp.route("/")
|
||||
@admin_required
|
||||
def index():
|
||||
partitions = get_all_partitions().fetchall()
|
||||
return render_template("partitions/view-all.html", partitions=partitions)
|
25
partitioncloud/templates/partitions/view-all.html
Normal file
25
partitioncloud/templates/partitions/view-all.html
Normal file
@ -0,0 +1,25 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block header %}
|
||||
<h1>{% block title %}Liste des partitions{% endblock %}</h1>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if partitions|length != 0 %}
|
||||
<div id="partitions-grid">
|
||||
{% for partition in partitions %}
|
||||
<a href="/partition/{{ partition['uuid'] }}">
|
||||
<div class="partition" id="partition-{{ partition['uuid'] }}">
|
||||
<img class="partition-thumbnail" src="/static/thumbnails/{{ partition['uuid'] }}.jpg">
|
||||
<div class="partition-description">
|
||||
<div class="partition-name">{{ partition["name"] }}</div>
|
||||
<div class="partition-author">{{ partition["author"] }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div>Aucune partition disponible</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user