diff options
Diffstat (limited to 'budget/web.py')
| -rw-r--r-- | budget/web.py | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/budget/web.py b/budget/web.py index 250359d..37c6415 100644 --- a/budget/web.py +++ b/budget/web.py @@ -6,9 +6,9 @@ import werkzeug # local modules from models import db, Project, Person, Bill -from forms import (ProjectForm, AuthenticationForm, BillForm, MemberForm, - InviteForm, CreateArchiveForm, EditProjectForm) -from utils import get_billform_for, Redirect303 +from forms import (get_billform_for, ProjectForm, AuthenticationForm, BillForm, + MemberForm, InviteForm, CreateArchiveForm, EditProjectForm) +from utils import Redirect303 """ The blueprint for the web interface. @@ -86,7 +86,7 @@ def authenticate(project_id=None): if request.method == "POST": if form.validate(): if not form.password.data == project.password: - form.errors['password'] = ["The password is not the right one"] + form.errors['password'] = ["This private code is not the right one"] else: # maintain a list of visited projects if "projects" not in session: @@ -115,6 +115,12 @@ def create_project(): 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() @@ -125,7 +131,20 @@ def create_project(): session[project.id] = project.password session.update() + # send reminder email + g.project = project + + message_title = "You have just created '%s' to share your expenses" % g.project.name + + message_body = render_template("reminder_mail") + + msg = Message(message_title, + body=message_body, + recipients=[project.contact_email]) + mail.send(msg) + # redirect the user to the next step (invite) + flash("The project identifier is %s" % project.id) return redirect(url_for(".invite", project_id=project.id)) return render_template("create_project.html", form=form) @@ -200,7 +219,7 @@ def list_bills(): bills = g.project.get_bills() return render_template("list_bills.html", bills=bills, member_form=MemberForm(g.project), - bill_form=get_billform_for(g.project) + bill_form=get_billform_for(request, g.project) ) @main.route("/<project_id>/members/add", methods=["GET", "POST"]) @@ -239,7 +258,7 @@ def remove_member(member_id): @main.route("/<project_id>/add", methods=["GET", "POST"]) def add_bill(): - form = get_billform_for(g.project) + form = get_billform_for(request, g.project) if request.method == 'POST': if form.validate(): bill = Bill() @@ -273,7 +292,8 @@ def edit_bill(bill_id): if not bill: raise werkzeug.exceptions.NotFound() - form = get_billform_for(g.project, set_default=False) + form = get_billform_for(request, g.project, set_default=False) + if request.method == 'POST' and form.validate(): form.save(bill) db.session.commit() |
