summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/forms.py67
-rw-r--r--app/views/expenses.py23
-rw-r--r--static/css/style.css3
-rw-r--r--templates/pages/add.jinja31
-rw-r--r--templates/pages/add.mako27
5 files changed, 120 insertions, 31 deletions
diff --git a/app/forms.py b/app/forms.py
new file mode 100644
index 0000000..da5fc9e
--- /dev/null
+++ b/app/forms.py
@@ -0,0 +1,67 @@
+# -*- encoding: utf-8 -*-
+
+from flask.ext.wtf import Form
+from wtforms.fields import DateField, IntegerField, StringField, HiddenField
+from wtforms import validators as v
+from wtforms import fields
+
+from wtforms.ext.sqlalchemy.fields import QuerySelectField
+
+import datetime
+
+from . import app
+
+today = datetime.date.today
+
+def is_hidden_field(f):
+ return isinstance(f, HiddenField)
+
+app.jinja_env.tests["hidden"] = is_hidden_field
+
+class DecimalField(fields.DecimalField):
+ def process_formdata(self, valuelist):
+ if valuelist:
+ value = valuelist[0].replace(',','.')
+ super(DecimalField, self).process_formdata([value])
+
+req = [v.input_required()]
+
+class ExpenseForm(Form):
+ date = DateField("Datum", req,
+ format="%d.%m.%Y",
+ default=today())
+
+ expense = DecimalField("Betrag", req,
+ description="EUR",
+ places=2)
+
+ description = StringField("Beschreibung", req)
+
+ category = QuerySelectField("Kategorie",
+ get_label="name")
+
+class ConstForm(Form):
+ start = DateField("Beginn", req,
+ format="%m.%Y",
+ default=today())
+
+ end = DateField("Ende", req,
+ format="%m.%Y",
+ default=today(),
+ description="(einschließlich)")
+
+ months = IntegerField("Zahlungsrythmus", req,
+ description="Monate")
+
+ expense = DecimalField("Betrag", req,
+ description="EUR",
+ places=2)
+
+ desc = StringField("Beschreibung", req)
+
+ cat = QuerySelectField("Kategorie",
+ get_label="name")
+
+ prev = QuerySelectField("Vorgänger",
+ get_label="description",
+ allow_blank=True)
diff --git a/app/views/expenses.py b/app/views/expenses.py
index 6b976de..da01308 100644
--- a/app/views/expenses.py
+++ b/app/views/expenses.py
@@ -1,10 +1,12 @@
from flask import Blueprint
-from flask import render_template, request, url_for
+from flask import render_template, request, url_for, redirect
import datetime, decimal
from sqlalchemy import sql, func
-from ..model import Category, SingleExpense, CatExpense, MonthExpense
+from ..model import db, Category, SingleExpense, CatExpense, MonthExpense
+
+from ..forms import ExpenseForm
mod = Blueprint('expenses', __name__)
@@ -71,6 +73,19 @@ def show(year = None, month = None):
def edit(id):
return render_template("page.jinja")
-@mod.route("/add/")
+@mod.route("/add/", methods=("GET", "POST"))
def add():
- return render_template("page.jinja")
+ form = ExpenseForm()
+ form.category.query = Category.query.order_by("name")
+
+ if form.validate_on_submit():
+ se = SingleExpense()
+
+ form.populate_obj(se)
+
+ db.session.add(se)
+ db.session.commit()
+
+ return redirect(url_for("index"))
+
+ return render_template("pages/add.jinja", form=form)
diff --git a/static/css/style.css b/static/css/style.css
index 5b4381b..64c612d 100644
--- a/static/css/style.css
+++ b/static/css/style.css
@@ -108,6 +108,9 @@ ul.arrow {
list-style-image: url(../images/closed.png);
}
+.error {
+ color: #E15418;
+}
/* Header */
diff --git a/templates/pages/add.jinja b/templates/pages/add.jinja
new file mode 100644
index 0000000..3e3caa2
--- /dev/null
+++ b/templates/pages/add.jinja
@@ -0,0 +1,31 @@
+{% extends "page.jinja" %}
+
+{% block heading %}
+ Neue Ausgabe hinzufügen
+{% endblock %}
+
+{% block js %}
+ {{ super() }}
+ <script type="text/javascript" src="{{ "jqueryui/jquery-ui-1.8.2.js" | static_url }}"></script>
+ <script type="text/javascript" src="{{ "js/add.js" | static_url }}"></script>
+{% endblock %}
+
+{% block style %}
+ {{ super() }}
+ <link href="{{ "jqueryui/css/ui-darkness/jquery-ui-1.8.2.custom.css" | static_url }}" rel="stylesheet" type="text/css">
+{% endblock %}
+
+{% block content %}
+ <form name="add_expense" method="post">
+ <table>
+ {% for field in form if not field is hidden %}
+ <tr><th>{{ field.label }}</th><td>{{ field }}</td><td>{{ field.description }}</td>
+ <td>{% if field.errors %}<span class="error">{{ field.errors[0] }}</span>{% endif %}</td></tr>
+ {% endfor %}
+ </table>
+ {{ form.hidden_tag() }}
+ {% block form_buttons %}
+ <input type="submit" name="changeB">
+ {% endblock %}
+ </form>
+{% endblock %}
diff --git a/templates/pages/add.mako b/templates/pages/add.mako
deleted file mode 100644
index 3ce46fd..0000000
--- a/templates/pages/add.mako
+++ /dev/null
@@ -1,27 +0,0 @@
-<%inherit file="/page.mako" />
-
-% if not form.valid:
- FEHLER!
-% endif
-
-<form name="add_expense" method="post">
- ${form.render()}
- <%block name="form_buttons">
- <input type="submit" name="changeB" />
- </%block>
-</form>
-
-<%block name="heading">
- Neue Ausgabe hinzufügen
-</%block>
-
-<%block name="js">
- ${parent.js()}
- <script type="text/javascript" src=${"/static/jqueryui/jquery-ui-1.8.2.js" | url}></script>
- <script type="text/javascript" src=${"/static/js/add.js" | url}></script>
-</%block>
-
-<%block name="style">
- ${parent.style()}
- <link href=${"/static/jqueryui/css/ui-darkness/jquery-ui-1.8.2.custom.css" | url} rel="stylesheet" type="text/css" />
-</%block>