Ver código fonte

Added alerts for bad arguments

Pjotir 10 meses atrás
pai
commit
37aa582690
3 arquivos alterados com 33 adições e 2 exclusões
  1. 7 2
      flaskapp.py
  2. 13 0
      static/css/custom.css
  3. 13 0
      templates/home.html

+ 7 - 2
flaskapp.py

@@ -1,6 +1,7 @@
 from flask import (
     Flask,
     abort,
+    flash,
     redirect,
     render_template,
     request,
@@ -36,8 +37,12 @@ def new_game():
 
         if not name or not hand_size or not match_count or not turn_count:
             raise KeyError
-
-    except (KeyError, TypeError) as e:
+    except KeyError as e:
+        app.logger.error(e)
+        app.logger.error("Failed, missing args")
+        flash("Failed to create game, bad arguments")
+        return redirect(url_for("home"))
+    except TypeError as e:
         app.logger.error(e)
         app.logger.error("Failed, bad args")
         return abort(400)

+ 13 - 0
static/css/custom.css

@@ -23,4 +23,17 @@ body {
 input[type="text"],
 input[type="number"] {
     color: black;
+}
+
+.alert {
+    background-color: rgb(44, 11, 14);
+    color: rgb(234, 134, 143);
+    border-color: rgb(132, 32, 41);
+    border-radius: 0.375rem;
+    border-style: solid;
+    border-width: 0.125rem;
+    padding: 1rem;
+    margin-bottom: 1rem;
+    width: 100% - 2rem;
+    ;
 }

+ 13 - 0
templates/home.html

@@ -1,6 +1,19 @@
 {% extends "base.html" %}
 {% block content %}
 <div class="container">
+    {% with messages = get_flashed_messages() %}
+    {% if messages %}
+    {% for message in messages %}
+    <div class="row">
+        <div class="twelve columns">
+            <div class="alert">
+                {{ message }}
+            </div>
+        </div>
+    </div>
+    {% endfor %}
+    {% endif %}
+    {% endwith %}
     <form action="/newgame">
         <div class="row">
             <div class="six columns">