aboutsummaryrefslogtreecommitdiff
path: root/budget/forms.py
diff options
context:
space:
mode:
authorAlexis Metaireau <alexis@notmyidea.org>2011-09-13 22:58:53 +0200
committerAlexis Metaireau <alexis@notmyidea.org>2011-09-13 22:58:53 +0200
commitb0d41291afade8aec86502d07d1d29d000ff1bca (patch)
tree75116f45eaa6915e554d0c6158069462063733fa /budget/forms.py
parent8528526f0b6dc8828247ef03f11e4894580f8dd5 (diff)
downloadihatemoney-mirror-b0d41291afade8aec86502d07d1d29d000ff1bca.zip
ihatemoney-mirror-b0d41291afade8aec86502d07d1d29d000ff1bca.tar.gz
ihatemoney-mirror-b0d41291afade8aec86502d07d1d29d000ff1bca.tar.bz2
API: Create and Update support
Diffstat (limited to 'budget/forms.py')
-rw-r--r--budget/forms.py24
1 files changed, 20 insertions, 4 deletions
diff --git a/budget/forms.py b/budget/forms.py
index 7ac48cc..cfd5788 100644
--- a/budget/forms.py
+++ b/budget/forms.py
@@ -1,6 +1,6 @@
from flaskext.wtf import *
from wtforms.widgets import html_params
-from models import Project, Person, Bill
+from models import Project, Person, Bill, db
from datetime import datetime
@@ -39,6 +39,15 @@ class ProjectForm(Form):
contact_email=self.contact_email.data)
return project
+ def update(self, project):
+ """Update the project with the information from the form"""
+ project.name = self.name.data
+ project.id = self.id.data
+ project.password = self.password.data
+ project.contact_email = self.contact_email.data
+
+ return project
+
class AuthenticationForm(Form):
id = TextField("Project identifier", validators=[Required()])
@@ -76,19 +85,26 @@ class BillForm(Form):
class MemberForm(Form):
- def __init__(self, project, *args, **kwargs):
- super(MemberForm, self).__init__(*args, **kwargs)
- self.project = project
name = TextField("Name", validators=[Required()])
submit = SubmitField("Add a member")
+ def __init__(self, project, *args, **kwargs):
+ super(MemberForm, self).__init__(*args, **kwargs)
+ self.project = project
+
def validate_name(form, field):
if Person.query.filter(Person.name == field.data)\
.filter(Person.project == form.project)\
.filter(Person.activated == True).all():
raise ValidationError("This project already have this member")
+ def save(self, project, person):
+ # if the user is already bound to the project, just reactivate him
+ person.name = self.name.data
+ person.project = project
+
+ return person
class InviteForm(Form):
emails = TextAreaField("People to notify")