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)
form = EditProjectForm(meta={"csrf": False})
if form.validate() and current_app.config.get("ALLOW_PUBLIC_PROJECT_CREATION"):
form.update(project)
db.session.commit()
return "UPDATED"
return form.errors, 400
class ProjectStatsHandler(Resource):
method_decorators = [need_auth]
def get(self, project):
return project.members_stats
class APIMemberForm(MemberForm):
""" Member is not disablable via a Form.
But we want Member.enabled to be togglable via the API.
"""
activated = BooleanField(false_values=("false", "", "False"))
def save(self, project, person):
person.activated = self.activated.data
return super(APIMemberForm, self).save(project, person)
class MembersHandler(Resource):
method_decorators = [need_auth]
def get(self, project):
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 edit_member(member_id):
member = Person.query.get(member_id, g.project)
if not member:
raise NotFound()
form = MemberForm(g.project, edit=True)
if request.method == "POST" and form.validate():
form.save(g.project, member)
db.session.commit()
flash(_("User '%(name)s' has been edited", name=member.name))
return redirect(url_for(".list_bills"))
form.fill(member)
return render_template("edit_member.html", form=form, edit=True)
def list_bills():
bill_form = get_billform_for(g.project)
# set the last selected payer as default choice if exists
if "last_selected_payer" in session:
bill_form.payer.data = session["last_selected_payer"]
# Preload the "owers" relationship for all bills
bills = g.project.get_bills().options(orm.subqueryload(Bill.owers))
return render_template(
"list_bills.html",
bills=bills,
member_form=MemberForm(g.project),
bill_form=bill_form,
add_bill=request.values.get("add_bill", False),
current_view="list_bills",
)
def __init__(self, project, edit=False, *args, **kwargs):
super(MemberForm, self).__init__(*args, **kwargs)
self.project = project
self.edit = edit