Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def add_member():
# FIXME manage form errors on the list_bills page
form = MemberForm(g.project)
if request.method == "POST":
if form.validate():
member = form.save(g.project, Person())
db.session.commit()
flash(_("%(member)s had been added", member=member.name))
return redirect(url_for(".list_bills"))
return render_template("add_member.html", form=form)
def post(self, project):
form = MemberForm(project, meta={"csrf": False})
if form.validate():
member = Person()
form.save(project, member)
db.session.commit()
return member.id, 201
return form.errors, 400
def get(self, project, id):
try:
return (
self.join(Person, Project)
.filter(Bill.payer_id == Person.id)
.filter(Person.project_id == Project.id)
.filter(Project.id == project.id)
.filter(Bill.id == id)
.one()
)
except orm.exc.NoResultFound:
return None
def validate_name(form, field):
if field.data == form.name.default:
raise ValidationError(_("User name incorrect"))
if (
not form.edit
and Person.query.filter(
Person.name == field.data,
Person.project == form.project,
Person.activated == True,
).all()
): # NOQA
raise ValidationError(_("This project already have this member"))
def validate_name(form, field):
if field.data == form.name.default:
raise ValidationError(_("User name incorrect"))
if (
not form.edit
and Person.query.filter(
Person.name == field.data,
Person.project == form.project,
Person.activated == True,
).all()
): # NOQA
raise ValidationError(_("This project already have this member"))
def get_bills(self):
"""Return the list of bills related to this project"""
return (
Bill.query.join(Person, Project)
.filter(Bill.payer_id == Person.id)
.filter(Person.project_id == Project.id)
.filter(Project.id == self.id)
.order_by(Bill.date.desc())
.order_by(Bill.creation_date.desc())
.order_by(Bill.id.desc())
)