mirror of
https://github.com/YunoHost-Apps/ihatemoney_ynh.git
synced 2024-09-03 19:26:15 +02:00
e214b39b44
Doing a query with an AND SQL statement needs to be done with multiple "filter" callswith SQLAlchemy. Here, we want to be sure that the username is not used AND that the project is the same than the eventual users that would match. The previous version of the code returned an user with the same name, even if the user wasn't in the right group.
49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
from flaskext.wtf import *
|
|
from models import Project, Person
|
|
|
|
# define forms
|
|
class ProjectForm(Form):
|
|
name = TextField("Project name", validators=[Required()])
|
|
id = TextField("Project identifier", validators=[Required()])
|
|
password = PasswordField("Password", validators=[Required()])
|
|
contact_email = TextField("Email", validators=[Required(), Email()])
|
|
submit = SubmitField("Get in")
|
|
|
|
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()])
|
|
password = TextField("Password", validators=[Required()])
|
|
submit = SubmitField("Get in")
|
|
|
|
|
|
class BillForm(Form):
|
|
what = TextField("What?", validators=[Required()])
|
|
payer = SelectField("Payer", validators=[Required()])
|
|
amount = DecimalField("Amount payed", validators=[Required()])
|
|
payed_for = SelectMultipleField("Who has to pay for this?",
|
|
validators=[Required()])
|
|
submit = SubmitField("Add the bill")
|
|
|
|
|
|
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 validate_name(form, field):
|
|
if Person.query.filter(Person.name == field.data)\
|
|
.filter(Person.project == form.project).all():
|
|
raise ValidationError("This project already have this member")
|