summaryrefslogtreecommitdiff
path: root/app/forms.py
blob: 1ab3c72ed058bf13750b6386f6f17cca332b1868 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- 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

@app.template_test("hidden")
def is_hidden_field(f):
    return isinstance(f, HiddenField)

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(u"Datum", req,
            format="%d.%m.%Y",
            default=today())

    expense = DecimalField(u"Betrag", req,
            description=u"EUR",
            places=2)

    description = StringField(u"Beschreibung", req)

    category = QuerySelectField(u"Kategorie",
            get_label="name")

class ConstForm(Form):
    start = DateField(u"Beginn", req,
            format="%m.%Y",
            default=today())

    end = DateField(u"Ende", req,
            format="%m.%Y",
            default=today().replace(year = today().year + 1),
            description=u"(einschließlich)")

    months = IntegerField(u"Zahlungsrythmus", req,
            description="Monate")

    expense = DecimalField(u"Betrag", req,
            description=u"EUR",
            places=2)

    description = StringField(u"Beschreibung", req)

    category = QuerySelectField(u"Kategorie",
            get_label="name")

    prev = QuerySelectField(u"Vorgänger",
            get_label="description",
            allow_blank=True)