aboutsummaryrefslogtreecommitdiff
path: root/budget
diff options
context:
space:
mode:
authorFeth AREZKI <feth@tuttu.info>2012-03-06 18:42:44 +0100
committerFeth AREZKI <feth@tuttu.info>2012-03-06 18:42:44 +0100
commit6a50e7318b84cc42f1d6bd24e677a5811005de62 (patch)
tree28c3166358cb147df4c6c4132b7126d3d2f0a1af /budget
parentfddf60a662ba7b696861f0450e3643cff60bba41 (diff)
downloadihatemoney-mirror-6a50e7318b84cc42f1d6bd24e677a5811005de62.zip
ihatemoney-mirror-6a50e7318b84cc42f1d6bd24e677a5811005de62.tar.gz
ihatemoney-mirror-6a50e7318b84cc42f1d6bd24e677a5811005de62.tar.bz2
pep8 <3 and '*' imports removal
Diffstat (limited to 'budget')
-rw-r--r--budget/forms.py54
1 files changed, 34 insertions, 20 deletions
diff --git a/budget/forms.py b/budget/forms.py
index dccf5fa..ac2c1e2 100644
--- a/budget/forms.py
+++ b/budget/forms.py
@@ -1,9 +1,11 @@
-from flaskext.wtf import *
+from flaskext.wtf import DateField, DecimalField, Email, Form, PasswordField, \
+ Required, SelectField, SelectMultipleField, SubmitField, TextAreaField, \
+ TextField, ValidationError
from flaskext.babel import lazy_gettext as _
from flask import request
from wtforms.widgets import html_params
-from models import Project, Person, Bill, db
+from models import Project, Person
from datetime import datetime
from jinja2 import Markup
from utils import slugify
@@ -18,14 +20,16 @@ def select_multi_checkbox(field, ul_class='', **kwargs):
js_function = u'toggle();'
options = dict(kwargs, id=choice_id, onclick=js_function)
label = _("Select All/None")
- html.append(u'<li><label for="%s">%s<span>%s</span></label></li>' % (choice_id, '<input %s /> ' % html_params(**options), label))
+ html.append(u'<li><label for="%s">%s<span>%s</span></label></li>'
+ % (choice_id, '<input %s /> ' % html_params(**options), label))
for value, label, checked in field.iter_choices():
choice_id = u'%s-%s' % (field_id, value)
options = dict(kwargs, name=field.name, value=value, id=choice_id)
if checked:
options['checked'] = 'checked'
- html.append(u'<li><label for="%s">%s<span>%s</span></label></li>' % (choice_id, '<input %s /> ' % html_params(**options), label))
+ html.append(u'<li><label for="%s">%s<span>%s</span></label></li>'
+ % (choice_id, '<input %s /> ' % html_params(**options), label))
html.append(u'</ul>')
return u''.join(html)
@@ -33,18 +37,20 @@ def select_multi_checkbox(field, ul_class='', **kwargs):
def get_billform_for(project, set_default=True, **kwargs):
"""Return an instance of BillForm configured for a particular project.
- :set_default: if set to True, on GET methods (usually when we want to
+ :set_default: if set to True, on GET methods (usually when we want to
display the default form, it will call set_default on it.
-
+
"""
form = BillForm(**kwargs)
- form.payed_for.choices = form.payer.choices = [(m.id, m.name) for m in project.active_members]
+ form.payed_for.choices = form.payer.choices = [(m.id, m.name)
+ for m in project.active_members]
form.payed_for.default = [m.id for m in project.active_members]
if set_default and request.method == "GET":
form.set_default()
return form
+
class CommaDecimalField(DecimalField):
"""A class to deal with comma in Decimal Field"""
def process_formdata(self, value):
@@ -63,8 +69,8 @@ class EditProjectForm(Form):
Returns the created instance
"""
- project = Project(name=self.name.data, id=self.id.data,
- password=self.password.data,
+ project = Project(name=self.name.data, id=self.id.data,
+ password=self.password.data,
contact_email=self.contact_email.data)
return project
@@ -85,7 +91,12 @@ class ProjectForm(EditProjectForm):
def validate_id(form, field):
form.id.data = slugify(field.data)
if Project.query.get(form.id.data):
- raise ValidationError(Markup(_("The project identifier is used to log in and for the URL of the project. We tried to generate an identifier for you but a project with this identifier already exists. Please create a new identifier you will be able to remember.")))
+ raise ValidationError(Markup(_("The project identifier is used "
+ "to log in and for the URL of the project. "
+ "We tried to generate an identifier for you but a project "
+ "with this identifier already exists. "
+ "Please create a new identifier "
+ "that you will be able to remember.")))
class AuthenticationForm(Form):
@@ -108,17 +119,18 @@ class BillForm(Form):
what = TextField(_("What?"), validators=[Required()])
payer = SelectField(_("Payer"), validators=[Required()], coerce=int)
amount = CommaDecimalField(_("Amount paid"), validators=[Required()])
- payed_for = SelectMultipleField(_("For whom?"),
+ payed_for = SelectMultipleField(_("For whom?"),
validators=[Required()], widget=select_multi_checkbox, coerce=int)
submit = SubmitField(_("Submit"))
submit2 = SubmitField(_("Submit and add a new one"))
def save(self, bill, project):
- bill.payer_id=self.payer.data
- bill.amount=self.amount.data
- bill.what=self.what.data
- bill.date=self.date.data
- bill.owers = [Person.query.get(ower, project) for ower in self.payed_for.data]
+ bill.payer_id = self.payer.data
+ bill.amount = self.amount.data
+ bill.what = self.what.data
+ bill.date = self.date.data
+ bill.owers = [Person.query.get(ower, project)
+ for ower in self.payed_for.data]
return bill
@@ -141,7 +153,8 @@ class BillForm(Form):
class MemberForm(Form):
- name = TextField(_("Name"), validators=[Required()], default=_("Type user name here"))
+ name = TextField(_("Name"), validators=[Required()],
+ default=_("Type user name here"))
submit = SubmitField(_("Add"))
def __init__(self, project, *args, **kwargs):
@@ -163,6 +176,7 @@ class MemberForm(Form):
return person
+
class InviteForm(Form):
emails = TextAreaField(_("People to notify"))
submit = SubmitField(_("Send invites"))
@@ -171,11 +185,11 @@ class InviteForm(Form):
validator = Email()
for email in [email.strip() for email in form.emails.data.split(",")]:
if not validator.regex.match(email):
- raise ValidationError(_("The email %(email)s is not valid",
+ raise ValidationError(_("The email %(email)s is not valid",
email=email))
class CreateArchiveForm(Form):
- start_date = DateField(_("Start date"), validators=[Required(),])
- end_date = DateField(_("End date"), validators=[Required(),])
+ start_date = DateField(_("Start date"), validators=[Required(), ])
+ end_date = DateField(_("End date"), validators=[Required(), ])
name = TextField(_("Name for this archive (optional)"))