diff --git a/forms.py b/forms.py deleted file mode 100644 index c739a5b..0000000 --- a/forms.py +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index b2d8902..0000000 --- a/geruecht.py +++ /dev/null @@ -1,52 +0,0 @@ -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/geruecht/__init__.py b/geruecht/__init__.py new file mode 100644 index 0000000..5900adf --- /dev/null +++ b/geruecht/__init__.py @@ -0,0 +1,10 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy + + +app = Flask(__name__) +app.config['SECRET_KEY'] = '0a657b97ef546da90b2db91862ad4e29' +app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db' +db = SQLAlchemy(app) + +from geruecht import routes \ No newline at end of file diff --git a/geruecht/forms.py b/geruecht/forms.py new file mode 100644 index 0000000..3940087 --- /dev/null +++ b/geruecht/forms.py @@ -0,0 +1,16 @@ +from flask_wtf import FlaskForm +from wtforms import StringField, SubmitField +from wtforms.validators import DataRequired, Length, ValidationError +from geruecht.model import User + + +class RegistrationForm(FlaskForm): + username = StringField('Name', validators=[DataRequired(), Length(min=2, max=20)]) + submit = SubmitField('Create') + + def validate_username(self, username): + + user = User.query.filter_by(username=username.data).first() + + if user: + raise ValidationError('Bist du behindert!? Der Name ist vergeben!!') diff --git a/geruecht/model.py b/geruecht/model.py new file mode 100644 index 0000000..0ca57b2 --- /dev/null +++ b/geruecht/model.py @@ -0,0 +1,13 @@ +from geruecht import db + + +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 add(self, value): + self.sum += value + + def __repr__(self): + return f"User('{self.username}', '{self.sum}')" diff --git a/geruecht/routes.py b/geruecht/routes.py new file mode 100644 index 0000000..96d5932 --- /dev/null +++ b/geruecht/routes.py @@ -0,0 +1,46 @@ +from flask import render_template, url_for, redirect, flash, jsonify +from geruecht import app, db +from geruecht.forms import RegistrationForm +from geruecht.model import User + +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(): + user = User(username=form.username.data) + db.session.add(user) + db.session.commit() + flash(f'Person wurde angelegt: {form.username.data}', 'success') + return redirect(url_for('home')) + return render_template('home.html', users=User.query.all(), form=form) + + +@app.route("//add-", methods=['POST']) +def add(username, value): + user = User.query.filter_by(username=username).first() + user.add(value) + db.session.commit() + flash(f'{username} wurde {value}€ hinzugefügt', 'success') + return jsonify({'data': user.sum}) + + +@app.route("/about") +def about(): + return render_template('about.html', title='about') diff --git a/geruecht/static/img/logo.png b/geruecht/static/img/logo.png new file mode 100644 index 0000000..abd2e09 Binary files /dev/null and b/geruecht/static/img/logo.png differ diff --git a/geruecht/static/js/scriptfile.js b/geruecht/static/js/scriptfile.js new file mode 100644 index 0000000..e69de29 diff --git a/static/master.css b/geruecht/static/master.css similarity index 77% rename from static/master.css rename to geruecht/static/master.css index 8b6a668..819da71 100644 --- a/static/master.css +++ b/geruecht/static/master.css @@ -4,11 +4,11 @@ body { .topnav { background-color: #077BCB; + height: 61; overflow: hidden; } -.topnav a { - float: left; +.blue-button { color: white; background-color: #055288; text-align: center; @@ -20,18 +20,36 @@ body { border-style: solid; border-radius: 10px; transition-duration: 0.4s; - box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); +/*box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);*/ } -.topnav a:hover { +.no-mg { + margin: 0; +} + +.no-pd { + padding: 0; +} + +.blue-button:hover { background: white; color: black; } -.topnav a.first { +.first { + float: left;; margin-left: 10%; } +.last { + float: right; +} + +.logo-nav { + height: 61px; + width: auto; +} + .geruecht { margin: 5px auto; display: table; @@ -75,6 +93,7 @@ body { .bottombar-element { float: left; line-height: auto; + vertical-align: middle; } .right { @@ -112,3 +131,11 @@ body { border-radius: 5px; padding: 6px; } + +.alert-error { + background: darksalmon; + border: 1px solid darkred; + color: darkred; + border-radius: 5px; + padding: 6px; +} diff --git a/templates/about.html b/geruecht/templates/about.html similarity index 100% rename from templates/about.html rename to geruecht/templates/about.html diff --git a/geruecht/templates/home.html b/geruecht/templates/home.html new file mode 100644 index 0000000..5efac90 --- /dev/null +++ b/geruecht/templates/home.html @@ -0,0 +1,44 @@ +{% extends "layout.html" %} +{% block content %} + {% for user in users %} +
+
+

{{ user.username }}

+
+ +
+

+1 €

+
+
+

+0,5 €

+
+
+

+0,4 €

+
+
+

+0,2 €

+
+
+

+0,1 €

+
+
+

{{ user.sum }}

+
+
+ + + {% endfor %} +{% endblock %} + diff --git a/templates/layout.html b/geruecht/templates/layout.html similarity index 77% rename from templates/layout.html rename to geruecht/templates/layout.html index 9a06d9f..3b957d7 100644 --- a/templates/layout.html +++ b/geruecht/templates/layout.html @@ -16,7 +16,8 @@
{% block content %} @@ -33,6 +34,13 @@
{% endfor %} {% endif %} + {% if form.username.errors %} + {% for error in form.username.errors %} +
+ {{ error }} +
+ {% endfor %} + {% endif %} {% endwith %}
@@ -45,14 +53,18 @@
- {{ form.submit(class="btn") }} + {{ form.submit(class="blue-button no-mg") }}
-
+

Stornieren

+ + +