1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/ihatemoney_ynh.git synced 2024-09-03 19:26:15 +02:00

Adding a bill is now working properly

This commit is contained in:
Alexis Metaireau 2011-07-31 00:41:28 +02:00
parent 3bbc3343a2
commit 2df6e11f05
8 changed files with 29 additions and 17 deletions

View file

@ -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")

View file

@ -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)

View file

@ -37,7 +37,9 @@
float: right;
}
#topmenu ul li{
float: right;
list-style-type: none;
margin-left: 10px;
}
/** links **/

View file

@ -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">

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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

View file

@ -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)