diff options
author | Nico von Geyso <Nico.Geyso@FU-Berlin.de> | 2012-09-17 11:12:08 +0200 |
---|---|---|
committer | Nico von Geyso <Nico.Geyso@FU-Berlin.de> | 2012-09-17 11:12:08 +0200 |
commit | 5765b05c65acdd2038d3eed270f521b1c499efcc (patch) | |
tree | 8ac432d8bbd983fd94f2c50cf50051efd3363366 | |
parent | 537ba4f396bd5db32eacf1b5e811209095582086 (diff) | |
parent | 97f983b73c5a27cd8785575bf941e66d747cdd82 (diff) | |
download | web-5765b05c65acdd2038d3eed270f521b1c499efcc.tar.gz web-5765b05c65acdd2038d3eed270f521b1c499efcc.tar.bz2 web-5765b05c65acdd2038d3eed270f521b1c499efcc.zip |
Merge branch 'master' of ssh://git.spline.de/account-web
-rw-r--r-- | app.py | 34 | ||||
-rw-r--r-- | forms.py | 9 | ||||
-rw-r--r-- | static/layout.css | 3 | ||||
-rw-r--r-- | templates/_macros.html | 16 | ||||
-rw-r--r-- | templates/base.html | 18 | ||||
-rw-r--r-- | templates/index.html | 5 | ||||
-rw-r--r-- | templates/register.html | 12 | ||||
-rw-r--r-- | utils.py | 21 |
8 files changed, 115 insertions, 3 deletions
@@ -1,11 +1,39 @@ # -*- coding: utf-8 -*- -from flask import Flask +from flask import Flask, request +from utils import templated +from forms import RegisterForm + app = Flask(__name__) @app.route('/') +@templated('index.html') def index(): - return 'Hello World!' + return {} + +@app.route('/register', methods=['GET', 'POST']) +@templated('register.html') +def register(): + form = RegisterForm(request.form) + if request.method == 'POST' and form.validate(): + username = form.username.data + mail = form.mail.data + password = form.password.data + return '<h1>501 Not Implemented</h1>' + return {'form': form} if __name__ == '__main__': - app.run() + app.run(debug=True) + + + + +# wir brauchen: +# registrieren +# login +# passwort ändern (master-passwort, einzelne) +# email ändern + +# später: +# account löschen +# openid-provider (ggf mehr Details: Realname, Zeitzone, ...) diff --git a/forms.py b/forms.py new file mode 100644 index 0000000..273d02f --- /dev/null +++ b/forms.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +from wtforms import Form, validators, TextField, PasswordField + +class RegisterForm(Form): + username = TextField('Benutzername', [validators.Length(min=4, max=20)]) + mail = TextField('E-Mail-Adresse', [validators.Length(min=6, max=50)]) + password = PasswordField('Passwort', [validators.Required(), + validators.EqualTo('password_confirm', message=u'Passwörter stimmen nicht überein')]) + password_confirm = PasswordField(u'Passwort bestätigen') diff --git a/static/layout.css b/static/layout.css new file mode 100644 index 0000000..d649f78 --- /dev/null +++ b/static/layout.css @@ -0,0 +1,3 @@ +form .errors { + color: #D00; +} diff --git a/templates/_macros.html b/templates/_macros.html new file mode 100644 index 0000000..2c933be --- /dev/null +++ b/templates/_macros.html @@ -0,0 +1,16 @@ +{% macro render_field(field) %} + <dt>{{ field.label }} + <dd>{{ field(**kwargs)|safe }} + {% if field.errors|length == 1 %} + <div class="errors"> + {{ field.errors.0 }} + </div> + {% elif field.errors %} + <ul class="errors"> + {% for error in field.errors %} + <li>{{ error }}</li> + {% endfor %} + </ul> + {% endif %} + </dd> +{% endmacro %} diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..6e4e403 --- /dev/null +++ b/templates/base.html @@ -0,0 +1,18 @@ +{%- set styles = ['layout.css'] + styles|default([]) %} +{%- set scripts = [] + scripts|default([]) %} +<!doctype html> +<html> + <head> + <title>{% if title %}{{ title }} – {% endif %}spline accounts</title> + {%- for script in scripts %} + <script type="text/javascript" src="{{ url_for('static', filename=script) }}"></script> + {%- endfor %} + {%- for style in styles %} + <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename=style) }}"> + {%- endfor %} + </head> + <body> + <h1>{% if title %}{{ title }}{% else %}spline accounts{% endif %}</h1> + {% block content %}{% endblock %} + </body> +</html> diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..9ee3b0f --- /dev/null +++ b/templates/index.html @@ -0,0 +1,5 @@ +{%- extends 'base.html' %} +{%- block content %} + <p>Willkommen bei <strong>spline accounts</strong>!</p> + <p><a href="/register">Account erstellen</a></p> +{%- endblock %} diff --git a/templates/register.html b/templates/register.html new file mode 100644 index 0000000..094056e --- /dev/null +++ b/templates/register.html @@ -0,0 +1,12 @@ +{%- extends 'base.html' %} +{%- from '_macros.html' import render_field %} +{%- set title = 'Account erstellen' %} +{%- block content %} +<form action="" method="post"> + {{ render_field(form.username) }} + {{ render_field(form.mail) }} + {{ render_field(form.password) }} + {{ render_field(form.password_confirm) }} + <input type="submit" value="Registrieren" /> +</form> +{%- endblock %} diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..2f3b433 --- /dev/null +++ b/utils.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +from functools import wraps +from flask import request, render_template + +# from http://flask.pocoo.org/docs/patterns/viewdecorators/#templating-decorator +def templated(template=None): + def decorator(f): + @wraps(f) + def decorated_function(*args, **kwargs): + template_name = template + if template_name is None: + template_name = request.endpoint \ + .replace('.', '/') + '.html' + ctx = f(*args, **kwargs) + if ctx is None: + ctx = {} + elif not isinstance(ctx, dict): + return ctx + return render_template(template_name, **ctx) + return decorated_function + return decorator |