From 3a1cc938d0a900963584658010de134d27e74e74 Mon Sep 17 00:00:00 2001 From: crimsen Date: Sat, 12 Jan 2019 02:57:06 +0100 Subject: [PATCH] tests --- .gitignore | 3 ++ forms.py | 8 ++++ geruecht.py | 52 ++++++++++++++++++++++++++ {css => static}/master.css | 50 ++++++++++++++++++++++--- templates/about.html | 4 ++ templates/home.html | 32 ++++++++++++++++ templates/layout.html | 63 ++++++++++++++++++++++++++++++++ test.html => templates/test.html | 0 8 files changed, 206 insertions(+), 6 deletions(-) create mode 100644 forms.py create mode 100644 geruecht.py rename {css => static}/master.css (63%) create mode 100644 templates/about.html create mode 100644 templates/home.html create mode 100644 templates/layout.html rename test.html => templates/test.html (100%) diff --git a/.gitignore b/.gitignore index c9c0d14..716695e 100644 --- a/.gitignore +++ b/.gitignore @@ -114,3 +114,6 @@ dmypy.json # Pyre type checker .pyre/ + +#ide +.idea \ No newline at end of file diff --git a/forms.py b/forms.py new file mode 100644 index 0000000..c739a5b --- /dev/null +++ b/forms.py @@ -0,0 +1,8 @@ +from flask_wtf import FlaskForm +from wtforms import StringField, SubmitField +from wtforms.validators import DataRequired, Length + + +class RegistrationForm(FlaskForm): + username = StringField('Name', validators=[DataRequired(), Length(min=2, max=20)]) + submit = SubmitField('Create') \ No newline at end of file diff --git a/geruecht.py b/geruecht.py new file mode 100644 index 0000000..b2d8902 --- /dev/null +++ b/geruecht.py @@ -0,0 +1,52 @@ +from flask import Flask, render_template, url_for, redirect, flash +from flask_sqlalchemy import SQLAlchemy +from forms import RegistrationForm + +app = Flask(__name__) +app.config['SECRET_KEY'] = '0a657b97ef546da90b2db91862ad4e29' +app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db' +db = SQLAlchemy(app) + +class User(db.Model): + id = db.Column(db.Integer, primary_key=True) + username = db.Column(db.String(20), unique=True, nullable=False) + sum = db.Column(db.Float, nullable=False, default=0.0) + + def __repr__(self): + return f"User('{self.username}', '{self.sum}')" + + + +users = [ + { + 'name': 'Corey Schafer', + 'sum': '20€' + }, + { + 'name': 'Tim Gröger', + 'sum': '10€' + }, + { + 'name': 'Franziska Bobbe', + 'sum': '5,80€' + } +] + + +@app.route("/", methods=['GET', 'POST']) +@app.route("/home", methods=['GET', 'POST']) +def home(): + form = RegistrationForm() + if form.validate_on_submit(): + flash(f'Person wurde angelegt: {form.username.data}', 'success') + return redirect(url_for('home')) + return render_template('home.html', users=users, form=form) + + +@app.route("/about") +def about(): + return render_template('about.html', title='about') + + +if __name__ == '__main__': + app.run(debug=True) diff --git a/css/master.css b/static/master.css similarity index 63% rename from css/master.css rename to static/master.css index 18bbecb..8b6a668 100644 --- a/css/master.css +++ b/static/master.css @@ -12,7 +12,7 @@ body { color: white; background-color: #055288; text-align: center; - padding: 10px 16px; + padding: 5px 5px; margin: 17px 17px; text-decoration: none; font-size: 17px; @@ -33,23 +33,27 @@ body { } .geruecht { - margin: 10px auto; + margin: 5px auto; display: table; - top: 40px; border: 0px; border-top: 1px gray; border-bottom: 1px gray; border-radius: 15px; border-style: solid; width: 100%; - border-spacing: 10px; + border-spacing: 5px; + height: 30px; } .g-item { display: table-cell; text-align: center; - padding: 10px; - height: 50px; + vertical-align: middle; + width: 20%; +} + +.g-item p { + font-size: 15px; } .button { @@ -65,12 +69,46 @@ body { position: fixed; bottom: 0; width: 100%; + display: table; } .bottombar-element { float: left; + line-height: auto; } .right { float: right; } + +.form-group { + float: left; + border: 0; + height: auto; + padding: 5px; + margin: auto; + float: left; + vertical-align: middle; +} + +.reg-label { + color: white; +} + +.m { + margin-top: 10px; +} + +.alert { + color: black; + font-size: 15px; + text-align: center; +} + +.alert-success { + background: lightgreen; + border: 1px solid darkgreen; + color: darkgreen; + border-radius: 5px; + padding: 6px; +} diff --git a/templates/about.html b/templates/about.html new file mode 100644 index 0000000..941af53 --- /dev/null +++ b/templates/about.html @@ -0,0 +1,4 @@ +{% extends "layout.html" %} +{% block content %} +

About Page

+{% endblock %} \ No newline at end of file diff --git a/templates/home.html b/templates/home.html new file mode 100644 index 0000000..6452938 --- /dev/null +++ b/templates/home.html @@ -0,0 +1,32 @@ +{% extends "layout.html" %} +{% block content %} + {% for user in users %} +
+
+

{{ user.name }}

+
+
+

+2 €

+
+
+

+1 €

+
+
+

+0,5 €

+
+
+

+0,4 €

+
+
+

+0,2 €

+
+
+

+0,1 €

+
+
+

{{ user.sum }}

+
+
+ {% endfor %} +{% endblock %} + diff --git a/templates/layout.html b/templates/layout.html new file mode 100644 index 0000000..9a06d9f --- /dev/null +++ b/templates/layout.html @@ -0,0 +1,63 @@ + + + + {% if title %} + {{ title }} + {% else %} + Gerüchteküche + {% endif %} + + + + + + + + + +
+ Finanzer +
+
+ {% block content %} + + {% endblock %} + +
+
+ {% with messages = get_flashed_messages(with_categories=true) %} + {% if messages %} + {% for category, message in messages %} +
+ {{ message }} +
+ {% endfor %} + {% endif %} + {% endwith %} +
+
+ {{ form.hidden_tag() }} +
+ +
+ {{ form.username.label(class="reg-label") }} + {{ form.username() }} +
+
+
+ {{ form.submit(class="btn") }} +
+
+
+
+

Stornieren

+
+
+ + + + \ No newline at end of file diff --git a/test.html b/templates/test.html similarity index 100% rename from test.html rename to templates/test.html