aboutsummaryrefslogtreecommitdiff
path: root/budget
diff options
context:
space:
mode:
authorAlexis Metaireau <alexis@notmyidea.org>2011-07-31 00:41:28 +0200
committerAlexis Metaireau <alexis@notmyidea.org>2011-07-31 00:41:28 +0200
commit2df6e11f05eff9bd855079097aa865f52689d7ca (patch)
tree6de593b6d68b2ee91c211af71a3168ba261293cf /budget
parent3bbc3343a2409de3cccdd7f50360e631224bf066 (diff)
downloadihatemoney-mirror-2df6e11f05eff9bd855079097aa865f52689d7ca.zip
ihatemoney-mirror-2df6e11f05eff9bd855079097aa865f52689d7ca.tar.gz
ihatemoney-mirror-2df6e11f05eff9bd855079097aa865f52689d7ca.tar.bz2
Adding a bill is now working properly
Diffstat (limited to 'budget')
-rw-r--r--budget/forms.py13
-rw-r--r--budget/models.py3
-rw-r--r--budget/static/main.css2
-rw-r--r--budget/templates/add_bill.html8
-rw-r--r--budget/templates/layout.html2
-rw-r--r--budget/templates/list_bills.html3
-rw-r--r--budget/utils.py2
-rw-r--r--budget/web.py13
8 files changed, 29 insertions, 17 deletions
diff --git a/budget/forms.py b/budget/forms.py
index 0d9dae5..9abbb16 100644
--- a/budget/forms.py
+++ b/budget/forms.py
@@ -1,7 +1,6 @@
from flaskext.wtf import *
-from models import Project, Person
+from models import Project, Person, Bill
-# define forms
class ProjectForm(Form):
name = TextField("Project name", validators=[Required()])
id = TextField("Project identifier", validators=[Required()])
@@ -34,6 +33,15 @@ class BillForm(Form):
validators=[Required()])
submit = SubmitField("Add the bill")
+ def save(self):
+ bill = Bill(payer_id=self.payer.data, amount=self.amount.data,
+ what=self.what.data)
+ # set the owers
+ for ower in self.payed_for.data:
+ bill.owers.append(Person.query.get(ower))
+
+ return bill
+
class MemberForm(Form):
def __init__(self, project, *args, **kwargs):
@@ -48,6 +56,7 @@ class MemberForm(Form):
.filter(Person.project == form.project).all():
raise ValidationError("This project already have this member")
+
class InviteForm(Form):
emails = TextAreaField("People to notify")
submit = SubmitField("Send invites")
diff --git a/budget/models.py b/budget/models.py
index c0d6db2..bf9ad92 100644
--- a/budget/models.py
+++ b/budget/models.py
@@ -24,6 +24,9 @@ class Person(db.Model):
name = db.Column(db.UnicodeText)
# activated = db.Column(db.Boolean, default=True)
+ def __str__(self):
+ return self.name
+
def __repr__(self):
return "<Person %s for project %s>" % (self.name, self.project.name)
diff --git a/budget/static/main.css b/budget/static/main.css
index 0ca39ff..d8f25f9 100644
--- a/budget/static/main.css
+++ b/budget/static/main.css
@@ -37,7 +37,9 @@
float: right;
}
#topmenu ul li{
+ float: right;
list-style-type: none;
+ margin-left: 10px;
}
/** links **/
diff --git a/budget/templates/add_bill.html b/budget/templates/add_bill.html
index 8dec74c..f959a64 100644
--- a/budget/templates/add_bill.html
+++ b/budget/templates/add_bill.html
@@ -9,7 +9,13 @@
{% if form.errors %}
<p class=error><strong>Your form contains errors.</strong></p>
- <ul>{% for error in form.errors %}<li>{{ error }}</li>{% endfor %}</ul>
+ <ul>
+ {% for field, errors in form.errors.items() %}
+ {% for error in errors %}
+ <li>{{ field }} : {{ error }}</li>
+ {% endfor %}
+ {% endfor %}
+ </ul>
{% endif %}
<form action="{{ url_for('add_bill', project_id=project.id) }}" method=post class="container span-24 add-bill">
diff --git a/budget/templates/layout.html b/budget/templates/layout.html
index 25c5dd7..cd0fca4 100644
--- a/budget/templates/layout.html
+++ b/budget/templates/layout.html
@@ -9,11 +9,11 @@
<div class="container" class="span-24">
<div id="title">
<a href="/"><h1>Account manager ! <span class="small">Manage your shared expenses.</span></h1></a>
+ <hr>
<div class="fright" id="topmenu">
{% block top_menu %}{% endblock %}
</div>
</div>
- <hr>
{% for message in get_flashed_messages() %}
<div class=info>{{ message }}</div>
{% endfor %}
diff --git a/budget/templates/list_bills.html b/budget/templates/list_bills.html
index 8f07f9b..a26dccc 100644
--- a/budget/templates/list_bills.html
+++ b/budget/templates/list_bills.html
@@ -2,8 +2,7 @@
{% block top_menu %}
<ul>
- <li><a href="{{ url_for('add_bill', project_id=project.id) }}">Add a bill</a></li>
- <li><a href="{{ url_for('add_member', project_id=project.id) }}">Add a member</a></li>
+ <li><a class="awesome button" href="{{ url_for('add_bill', project_id=project.id) }}">Add a bill</a></li>
</ul>
{% endblock %}
diff --git a/budget/utils.py b/budget/utils.py
index a5f1474..20989e9 100644
--- a/budget/utils.py
+++ b/budget/utils.py
@@ -7,7 +7,7 @@ from forms import BillForm
def get_billform_for(project_id):
"""Return an instance of BillForm configured for a particular project."""
form = BillForm()
- payers = [(m.id, m.name) for m in Project.query.get(project_id).members]
+ payers = [(str(m.id), m.name) for m in Project.query.get(project_id).members]
form.payed_for.choices = form.payer.choices = payers
return form
diff --git a/budget/web.py b/budget/web.py
index 10b2d4a..f313266 100644
--- a/budget/web.py
+++ b/budget/web.py
@@ -123,18 +123,11 @@ def add_bill(project):
form = get_billform_for(project.id)
if request.method == 'POST':
if form.validate():
- bill = Bill()
- form.populate_obj(bill)
-
- for ower in form.payed_for.data:
- ower = BillOwer(name=ower)
- db.session.add(ower)
- bill.owers.append(ower)
-
- db.session.add(bill)
+ db.session.add(form.save())
db.session.commit()
+
flash("The bill have been added")
- return redirect(url_for('list_bills'))
+ return redirect(url_for('list_bills', project_id=project.id))
return render_template("add_bill.html", form=form, project=project)