Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
form = ProjectForm()
if request.method == "GET" and "project_id" in request.values:
form.name.data = request.values["project_id"]
if request.method == "POST":
# At first, we don't want the user to bother with the identifier
# so it will automatically be missing because not displayed into
# the form
# Thus we fill it with the same value as the filled name,
# the validation will take care of the slug
if not form.id.data:
form.id.data = form.name.data
if form.validate():
# save the object in the db
project = form.save()
db.session.add(project)
db.session.commit()
# create the session object (authenticate)
session[project.id] = True
session.update()
# send reminder email
g.project = project
message_title = _(
"You have just created '%(project)s' " "to share your expenses",
project=g.project.name,
)
message_body = render_template(
"reminder_mail.%s.j2" % get_locale().language
"reset_password.html", form=form, error=_("No token provided")
)
project_id = Project.verify_token(token)
if not project_id:
return render_template(
"reset_password.html", form=form, error=_("Invalid token")
)
project = Project.query.get(project_id)
if not project:
return render_template(
"reset_password.html", form=form, error=_("Unknown project")
)
if request.method == "POST" and form.validate():
project.password = generate_password_hash(form.password.data)
db.session.add(project)
db.session.commit()
flash(_("Password successfully reset."))
return redirect(url_for(".home"))
return render_template("reset_password.html", form=form)
def post(self):
form = ProjectForm(meta={"csrf": False})
if form.validate() and current_app.config.get("ALLOW_PUBLIC_PROJECT_CREATION"):
project = form.save()
db.session.add(project)
db.session.commit()
return project.id, 201
return form.errors, 400
def post(self, project):
form = get_billform_for(project, True, meta={"csrf": False})
if form.validate():
bill = Bill()
form.save(bill, project)
db.session.add(bill)
db.session.commit()
return bill.id, 201
return form.errors, 400
Create a demo project if it doesn't exists yet (or has been deleted)
If the demo project is deactivated, one is redirected to the create project form
"""
is_demo_project_activated = current_app.config["ACTIVATE_DEMO_PROJECT"]
project = Project.query.get("demo")
if not project and not is_demo_project_activated:
raise Redirect303(url_for(".create_project", project_id="demo"))
if not project and is_demo_project_activated:
project = Project(
id="demo",
name="demonstration",
password=generate_password_hash("demo"),
contact_email="demo@notmyidea.org",
)
db.session.add(project)
db.session.commit()
session[project.id] = True
return redirect(url_for(".list_bills", project_id=project.id))
def add_bill():
form = get_billform_for(g.project)
if request.method == "POST":
if form.validate():
# save last selected payer in session
session["last_selected_payer"] = form.payer.data
session.update()
bill = Bill()
db.session.add(form.save(bill, g.project))
db.session.commit()
flash(_("The bill has been added"))
args = {}
if form.submit2.data:
args["add_bill"] = True
return redirect(url_for(".list_bills", **args))
return render_template("add_bill.html", form=form)
def edit_project():
edit_form = EditProjectForm()
if request.method == "POST":
if edit_form.validate():
project = edit_form.update(g.project)
db.session.add(project)
db.session.commit()
return redirect(url_for(".list_bills"))
else:
edit_form.name.data = g.project.name
edit_form.contact_email.data = g.project.contact_email
return render_template(
"edit_project.html", edit_form=edit_form, current_view="edit_project"
)