Peter Oertel пре 1 година
родитељ
комит
2a91772603
2 измењених фајлова са 86 додато и 0 уклоњено
  1. 20 0
      app/main.py
  2. 66 0
      app/templates/tableview.html

+ 20 - 0
app/main.py

@@ -313,6 +313,26 @@ def admin():
     return render_template("admin.html", users=users)
 
 
[email protected]("/tableview")
+def tableview():
+    if not session.get("userid"):
+        return redirect(url_for("login"))
+
+    user = db.session.execute(
+        db.select(User).where(User.id == session.get("userid"))
+    ).scalar_one_or_none()
+
+    if not user or not user.is_admin:
+        flash("You are not an admin!", category="danger")
+        return redirect(url_for("home"))
+
+    return render_template(
+        "tableview.html",
+        tasks=db.session.execute(db.select(Task)).scalars().all(),
+        users=db.session.execute(db.select(User)).scalars().all(),
+    )
+
+
 @app.route("/logout", methods=["POST"])
 def logout():
     session.pop("userid", None)

+ 66 - 0
app/templates/tableview.html

@@ -0,0 +1,66 @@
+{% extends "base.html" %}
+{% block title %}
+Toppers Tasks | Account
+{% endblock %}
+{% block content %}
+{% for category, message in get_flashed_messages(with_categories=True) %}
+<div class="alert alert-{{ category }}" role="alert">
+    {{ message }}
+</div>
+{% endfor %}
+<div class="row">
+    <div class="task-card">
+        <table class="table table-striped table-hover">
+            <thead>
+                <tr>
+                    <th>id</th>
+                    <th>Username</th>
+                    <th>Passhash</th>
+                    <th>Is Admin</th>
+                </tr>
+            </thead>
+            <tbody>
+                {% for user in users %}
+                <tr>
+                    <td>{{ user.id }}</td>
+                    <td>{{ user.username }}</td>
+                    <td>...{{ user.passhash[-6:] if user.passhash else 'None'
+                        }}</td>
+                    <td>{{ user.is_admin }}</td>
+                </tr>
+                {% endfor %}
+            </tbody>
+        </table>
+    </div>
+</div>
+<div class="row">
+    <div class="task-card">
+        <table class="table table-striped table-hover">
+            <thead>
+                <tr>
+                    <th>id</th>
+                    <th>tasktext</th>
+                    <th>created_datetime</th>
+                    <th>created_by</th>
+                    <th>due</th>
+                    <th>completed</th>
+                    <th>deleted</th>
+                </tr>
+            </thead>
+            <tbody>
+                {% for task in tasks %}
+                <tr>
+                    <td>{{ task.id }}</td>
+                    <td>{{ task.tasktext[:20] }}</td>
+                    <td>{{ task.created_datetime }}</td>
+                    <td>{{ task.user.username }}</td>
+                    <td>{{ task.due }}</td>
+                    <td>{{ task.completed }}</td>
+                    <td>{{ task.deleted }}</td>
+                </tr>
+                {% endfor %}
+            </tbody>
+        </table>
+    </div>
+</div>
+{% endblock %}