diff options
| author | Arnaud Bos <arnaud.tlse@gmail.com> | 2011-09-18 23:38:12 +0200 |
|---|---|---|
| committer | Arnaud Bos <arnaud.tlse@gmail.com> | 2011-09-18 23:39:10 +0200 |
| commit | 681f22f3e47c3fb75fdb1d858b179e945c952596 (patch) | |
| tree | e83246b13d33f30083488b6913e96e261605f5e3 /budget/forms.py | |
| parent | 89e1bbe134bc770d4a3f999a1329bd07522b07cf (diff) | |
| parent | 20ab40690d74befcd8fc75f24f301759840bf43a (diff) | |
| download | ihatemoney-mirror-681f22f3e47c3fb75fdb1d858b179e945c952596.zip ihatemoney-mirror-681f22f3e47c3fb75fdb1d858b179e945c952596.tar.gz ihatemoney-mirror-681f22f3e47c3fb75fdb1d858b179e945c952596.tar.bz2 | |
Merge branch 'master' into auth-forms-usability
Diffstat (limited to 'budget/forms.py')
| -rw-r--r-- | budget/forms.py | 53 |
1 files changed, 36 insertions, 17 deletions
diff --git a/budget/forms.py b/budget/forms.py index bb19142..33d7b38 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 from jinja2 import Markup from utils import slugify @@ -36,11 +36,33 @@ def get_billform_for(request, project, set_default=True): return form -class ProjectForm(Form): +class EditProjectForm(Form): name = TextField("Project name", validators=[Required()]) - id = TextField("Project identifier", validators=[Required()]) - password = PasswordField("Private code", validators=[Required()]) + password = TextField("Private code", validators=[Required()]) contact_email = TextField("Email", validators=[Required(), Email()]) + submit = SubmitField("Edit the project") + + def save(self): + """Create a new project with the information given by this form. + + Returns the created instance + """ + project = Project(name=self.name.data, id=self.id.data, + password=self.password.data, + 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.password = self.password.data + project.contact_email = self.contact_email.data + + return project + + +class ProjectForm(EditProjectForm): + id = TextField("Project identifier", validators=[Required()]) submit = SubmitField("Create the project") def validate_id(form, field): @@ -56,16 +78,6 @@ class ProjectForm(Form): to remember. """)) - def save(self): - """Create a new project with the information given by this form. - - Returns the created instance - """ - project = Project(name=self.name.data, id=self.id.data, - password=self.password.data, - contact_email=self.contact_email.data) - return project - class AuthenticationForm(Form): id = TextField("Project identifier", validators=[Required()]) @@ -103,19 +115,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") |
