2011-09-09 21:21:37 +02:00
|
|
|
"""
|
|
|
|
The blueprint for the web interface.
|
2011-07-23 18:45:40 +02:00
|
|
|
|
2011-09-09 21:21:37 +02:00
|
|
|
Contains all the interaction logic with the end user (except forms which
|
|
|
|
are directly handled in the forms module.
|
2011-08-21 21:21:52 +02:00
|
|
|
|
2011-09-09 21:21:37 +02:00
|
|
|
Basically, this blueprint takes care of the authentication and provides
|
2012-02-20 16:58:18 +01:00
|
|
|
some shortcuts to make your life better when coding (see `pull_project`
|
2011-11-27 04:11:22 +01:00
|
|
|
and `add_project_id` for a quick overview)
|
2011-09-09 21:21:37 +02:00
|
|
|
"""
|
2011-08-21 21:21:52 +02:00
|
|
|
|
2012-03-06 18:41:55 +01:00
|
|
|
from flask import Blueprint, current_app, flash, g, redirect, \
|
|
|
|
render_template, request, session, url_for
|
|
|
|
from flaskext.mail import Mail, Message
|
|
|
|
from flaskext.babel import get_locale, gettext as _
|
|
|
|
from smtplib import SMTPRecipientsRefused
|
|
|
|
import werkzeug
|
|
|
|
|
|
|
|
# local modules
|
|
|
|
from models import db, Project, Person, Bill
|
|
|
|
from forms import AuthenticationForm, CreateArchiveForm, EditProjectForm, \
|
|
|
|
InviteForm, MemberForm, PasswordReminder, ProjectForm, get_billform_for
|
|
|
|
from utils import Redirect303
|
|
|
|
|
|
|
|
|
2011-09-09 21:21:37 +02:00
|
|
|
main = Blueprint("main", __name__)
|
|
|
|
mail = Mail()
|
2011-08-21 21:21:52 +02:00
|
|
|
|
2012-03-06 18:41:55 +01:00
|
|
|
|
2011-09-09 21:21:37 +02:00
|
|
|
@main.url_defaults
|
2011-08-21 01:42:10 +02:00
|
|
|
def add_project_id(endpoint, values):
|
2011-09-09 19:57:28 +02:00
|
|
|
"""Add the project id to the url calls if it is expected.
|
|
|
|
|
|
|
|
This is to not carry it everywhere in the templates.
|
|
|
|
"""
|
2011-08-21 01:42:10 +02:00
|
|
|
if 'project_id' in values or not hasattr(g, 'project'):
|
|
|
|
return
|
2011-09-09 21:21:37 +02:00
|
|
|
if current_app.url_map.is_endpoint_expecting(endpoint, 'project_id'):
|
2011-08-21 01:42:10 +02:00
|
|
|
values['project_id'] = g.project.id
|
|
|
|
|
2012-03-06 18:41:55 +01:00
|
|
|
|
2011-09-09 21:21:37 +02:00
|
|
|
@main.url_value_preprocessor
|
2011-08-21 01:42:10 +02:00
|
|
|
def pull_project(endpoint, values):
|
2011-09-09 19:57:28 +02:00
|
|
|
"""When a request contains a project_id value, transform it directly
|
|
|
|
into a project by checking the credentials are stored in session.
|
|
|
|
|
|
|
|
If not, redirect the user to an authentication form
|
|
|
|
"""
|
2011-08-21 02:23:53 +02:00
|
|
|
if endpoint == "authenticate":
|
|
|
|
return
|
2011-08-21 01:42:10 +02:00
|
|
|
if not values:
|
|
|
|
values = {}
|
|
|
|
project_id = values.pop('project_id', None)
|
|
|
|
if project_id:
|
|
|
|
project = Project.query.get(project_id)
|
|
|
|
if not project:
|
2012-03-06 18:41:55 +01:00
|
|
|
raise Redirect303(url_for(".create_project",
|
|
|
|
project_id=project_id))
|
2011-08-21 01:42:10 +02:00
|
|
|
if project.id in session and session[project.id] == project.password:
|
|
|
|
# add project into kwargs and call the original function
|
|
|
|
g.project = project
|
|
|
|
else:
|
|
|
|
# redirect to authentication page
|
2011-08-21 22:35:01 +02:00
|
|
|
raise Redirect303(
|
2011-09-09 21:21:37 +02:00
|
|
|
url_for(".authenticate", project_id=project_id))
|
2011-07-29 15:44:15 +02:00
|
|
|
|
2012-03-06 18:41:55 +01:00
|
|
|
|
2011-09-09 21:21:37 +02:00
|
|
|
@main.route("/authenticate", methods=["GET", "POST"])
|
2011-08-21 22:20:50 +02:00
|
|
|
def authenticate(project_id=None):
|
2011-09-09 19:57:28 +02:00
|
|
|
"""Authentication form"""
|
2011-07-23 18:45:40 +02:00
|
|
|
form = AuthenticationForm()
|
2011-09-14 02:07:26 +02:00
|
|
|
if not form.id.data and request.args.get('project_id'):
|
2011-08-21 22:20:50 +02:00
|
|
|
form.id.data = request.args['project_id']
|
2012-02-20 16:58:18 +01:00
|
|
|
project_id = form.id.data
|
2011-07-30 01:32:55 +02:00
|
|
|
project = Project.query.get(project_id)
|
2012-03-06 18:41:55 +01:00
|
|
|
create_project = False # We don't want to create the project by default
|
2011-07-30 01:32:55 +02:00
|
|
|
if not project:
|
2012-02-20 16:58:18 +01:00
|
|
|
# But if the user try to connect to an unexisting project, we will
|
2011-08-09 17:29:44 +02:00
|
|
|
# propose him a link to the creation form.
|
2011-09-14 02:19:10 +02:00
|
|
|
if request.method == "POST":
|
|
|
|
form.validate()
|
2011-09-14 02:07:26 +02:00
|
|
|
else:
|
|
|
|
create_project = project_id
|
2011-07-30 01:32:55 +02:00
|
|
|
|
2011-08-09 19:28:50 +02:00
|
|
|
else:
|
|
|
|
# if credentials are already in session, redirect
|
|
|
|
if project_id in session and project.password == session[project_id]:
|
2011-08-20 00:28:58 +02:00
|
|
|
setattr(g, 'project', project)
|
2011-09-09 21:21:37 +02:00
|
|
|
return redirect(url_for(".list_bills"))
|
2011-08-09 19:28:50 +02:00
|
|
|
|
|
|
|
# else process the form
|
|
|
|
if request.method == "POST":
|
|
|
|
if form.validate():
|
|
|
|
if not form.password.data == project.password:
|
2012-03-06 18:41:55 +01:00
|
|
|
msg = _("This private code is not the right one")
|
|
|
|
form.errors['password'] = [msg]
|
2011-08-09 19:28:50 +02:00
|
|
|
else:
|
|
|
|
# maintain a list of visited projects
|
|
|
|
if "projects" not in session:
|
|
|
|
session["projects"] = []
|
|
|
|
# add the project on the top of the list
|
|
|
|
session["projects"].insert(0, (project_id, project.name))
|
|
|
|
session[project_id] = form.password.data
|
|
|
|
session.update()
|
2011-08-19 23:44:54 +02:00
|
|
|
setattr(g, 'project', project)
|
2011-09-09 21:21:37 +02:00
|
|
|
return redirect(url_for(".list_bills"))
|
2011-07-29 15:44:15 +02:00
|
|
|
|
2012-02-20 16:58:18 +01:00
|
|
|
return render_template("authenticate.html", form=form,
|
2011-08-09 17:29:44 +02:00
|
|
|
create_project=create_project)
|
2011-07-23 19:11:24 +02:00
|
|
|
|
2012-03-06 18:41:55 +01:00
|
|
|
|
2011-09-09 21:21:37 +02:00
|
|
|
@main.route("/")
|
2011-08-21 01:42:10 +02:00
|
|
|
def home():
|
|
|
|
project_form = ProjectForm()
|
|
|
|
auth_form = AuthenticationForm()
|
2012-02-20 16:58:18 +01:00
|
|
|
return render_template("home.html", project_form=project_form,
|
2011-08-21 01:42:10 +02:00
|
|
|
auth_form=auth_form, session=session)
|
|
|
|
|
2012-03-06 18:41:55 +01:00
|
|
|
|
2011-09-09 21:21:37 +02:00
|
|
|
@main.route("/create", methods=["GET", "POST"])
|
2011-07-23 19:11:24 +02:00
|
|
|
def create_project():
|
2011-07-26 16:03:00 +02:00
|
|
|
form = ProjectForm()
|
2011-07-23 19:11:24 +02:00
|
|
|
if request.method == "GET" and 'project_id' in request.values:
|
|
|
|
form.name.data = request.values['project_id']
|
|
|
|
|
|
|
|
if request.method == "POST":
|
2011-09-11 05:25:42 +02:00
|
|
|
# At first, we don't want the user to bother with the identifier
|
2012-03-06 18:41:55 +01:00
|
|
|
# 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
|
2011-09-11 05:25:42 +02:00
|
|
|
if not form.id.data:
|
|
|
|
form.id.data = form.name.data
|
2011-07-23 19:11:24 +02:00
|
|
|
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] = project.password
|
|
|
|
session.update()
|
|
|
|
|
2011-09-14 01:16:25 +02:00
|
|
|
# send reminder email
|
|
|
|
g.project = project
|
2012-02-20 16:58:18 +01:00
|
|
|
|
2012-03-06 18:41:55 +01:00
|
|
|
message_title = _("You have just created '%(project)s' "
|
|
|
|
"to share your expenses", project=g.project.name)
|
2011-09-14 01:16:25 +02:00
|
|
|
|
2012-03-06 18:41:55 +01:00
|
|
|
message_body = render_template("reminder_mail.%s" %
|
|
|
|
get_locale().language)
|
2011-09-14 01:16:25 +02:00
|
|
|
|
2012-02-20 16:58:18 +01:00
|
|
|
msg = Message(message_title,
|
|
|
|
body=message_body,
|
2011-09-14 01:16:25 +02:00
|
|
|
recipients=[project.contact_email])
|
2012-02-20 17:03:44 +01:00
|
|
|
try:
|
|
|
|
mail.send(msg)
|
|
|
|
except SMTPRecipientsRefused:
|
|
|
|
msg_compl = 'Problem sending mail. '
|
|
|
|
# TODO: destroy the project and cancel instead?
|
|
|
|
else:
|
|
|
|
msg_compl = ''
|
2011-09-14 01:16:25 +02:00
|
|
|
|
2011-07-23 19:11:24 +02:00
|
|
|
# redirect the user to the next step (invite)
|
2012-02-20 17:03:44 +01:00
|
|
|
flash(_("%(msg_compl)sThe project identifier is %(project)s",
|
|
|
|
msg_compl=msg_compl, project=project.id))
|
2011-09-09 21:21:37 +02:00
|
|
|
return redirect(url_for(".invite", project_id=project.id))
|
2011-07-23 19:11:24 +02:00
|
|
|
|
|
|
|
return render_template("create_project.html", form=form)
|
|
|
|
|
2012-03-06 18:41:55 +01:00
|
|
|
|
2011-10-08 15:52:12 +02:00
|
|
|
@main.route("/password-reminder", methods=["GET", "POST"])
|
|
|
|
def remind_password():
|
|
|
|
form = PasswordReminder()
|
|
|
|
if request.method == "POST":
|
|
|
|
if form.validate():
|
|
|
|
# get the project
|
|
|
|
project = Project.query.get(form.id.data)
|
|
|
|
|
|
|
|
# send the password reminder
|
2012-03-06 18:41:55 +01:00
|
|
|
password_reminder = "password_reminder.%s" % get_locale().language
|
2012-02-20 16:58:18 +01:00
|
|
|
mail.send(Message("password recovery",
|
2012-03-06 18:41:55 +01:00
|
|
|
body=render_template(password_reminder, project=project),
|
2011-10-08 15:52:12 +02:00
|
|
|
recipients=[project.contact_email]))
|
2011-10-15 01:19:19 +02:00
|
|
|
flash(_("a mail has been sent to you with the password"))
|
2011-10-08 15:52:12 +02:00
|
|
|
|
|
|
|
return render_template("password_reminder.html", form=form)
|
|
|
|
|
|
|
|
|
2011-09-14 22:03:18 +02:00
|
|
|
@main.route("/<project_id>/edit", methods=["GET", "POST"])
|
|
|
|
def edit_project():
|
|
|
|
form = EditProjectForm()
|
|
|
|
if request.method == "POST":
|
|
|
|
if form.validate():
|
|
|
|
project = form.update(g.project)
|
|
|
|
db.session.commit()
|
|
|
|
session[project.id] = project.password
|
|
|
|
|
|
|
|
return redirect(url_for(".list_bills"))
|
|
|
|
else:
|
|
|
|
form.name.data = g.project.name
|
|
|
|
form.password.data = g.project.password
|
|
|
|
form.contact_email.data = g.project.contact_email
|
|
|
|
|
|
|
|
return render_template("edit_project.html", form=form)
|
|
|
|
|
2012-03-06 18:41:55 +01:00
|
|
|
|
2012-09-02 13:53:01 +02:00
|
|
|
@main.route("/<project_id>/delete")
|
|
|
|
def delete_project():
|
2011-11-02 12:16:01 +01:00
|
|
|
g.project.remove_project()
|
2012-09-02 13:53:01 +02:00
|
|
|
flash(_('Project successfully deleted'))
|
2011-11-02 12:16:01 +01:00
|
|
|
|
|
|
|
return redirect(url_for(".home"))
|
2011-09-14 22:03:18 +02:00
|
|
|
|
2012-03-06 18:41:55 +01:00
|
|
|
|
2011-09-09 21:21:37 +02:00
|
|
|
@main.route("/exit")
|
2011-08-09 23:48:13 +02:00
|
|
|
def exit():
|
2011-07-29 15:44:15 +02:00
|
|
|
# delete the session
|
2011-07-30 01:32:55 +02:00
|
|
|
session.clear()
|
2011-09-09 21:21:37 +02:00
|
|
|
return redirect(url_for(".home"))
|
2011-07-29 15:44:15 +02:00
|
|
|
|
2012-03-06 18:41:55 +01:00
|
|
|
|
2011-09-09 21:21:37 +02:00
|
|
|
@main.route("/demo")
|
2011-08-21 03:27:59 +02:00
|
|
|
def demo():
|
2011-09-09 19:57:28 +02:00
|
|
|
"""
|
|
|
|
Authenticate the user for the demonstration project and redirect him to
|
|
|
|
the bills list for this project.
|
|
|
|
|
|
|
|
Create a demo project if it doesnt exists yet (or has been deleted)
|
|
|
|
"""
|
2011-08-21 03:27:59 +02:00
|
|
|
project = Project.query.get("demo")
|
2011-08-21 20:54:20 +02:00
|
|
|
if not project:
|
2012-02-20 16:58:18 +01:00
|
|
|
project = Project(id="demo", name=u"demonstration", password="demo",
|
2011-08-21 20:54:20 +02:00
|
|
|
contact_email="demo@notmyidea.org")
|
|
|
|
db.session.add(project)
|
|
|
|
db.session.commit()
|
2011-08-21 03:27:59 +02:00
|
|
|
session[project.id] = project.password
|
2011-09-09 21:21:37 +02:00
|
|
|
return redirect(url_for(".list_bills", project_id=project.id))
|
2011-08-21 03:27:59 +02:00
|
|
|
|
2012-03-06 18:41:55 +01:00
|
|
|
|
2011-09-09 21:21:37 +02:00
|
|
|
@main.route("/<project_id>/invite", methods=["GET", "POST"])
|
2011-08-19 23:44:54 +02:00
|
|
|
def invite():
|
2011-09-09 19:57:28 +02:00
|
|
|
"""Send invitations for this particular project"""
|
2011-07-30 15:46:53 +02:00
|
|
|
|
|
|
|
form = InviteForm()
|
|
|
|
|
2012-02-20 16:58:18 +01:00
|
|
|
if request.method == "POST":
|
2011-07-30 15:46:53 +02:00
|
|
|
if form.validate():
|
|
|
|
# send the email
|
|
|
|
|
2012-03-06 18:41:55 +01:00
|
|
|
message_body = render_template("invitation_mail.%s" %
|
|
|
|
get_locale().language)
|
2011-07-30 15:46:53 +02:00
|
|
|
|
2012-03-06 18:41:55 +01:00
|
|
|
message_title = _("You have been invited to share your "
|
|
|
|
"expenses for %(project)s", project=g.project.name)
|
2012-02-20 16:58:18 +01:00
|
|
|
msg = Message(message_title,
|
|
|
|
body=message_body,
|
|
|
|
recipients=[email.strip()
|
2011-08-09 23:48:13 +02:00
|
|
|
for email in form.emails.data.split(",")])
|
2011-07-30 15:46:53 +02:00
|
|
|
mail.send(msg)
|
2011-10-15 01:19:19 +02:00
|
|
|
flash(_("Your invitations have been sent"))
|
2011-09-09 21:21:37 +02:00
|
|
|
return redirect(url_for(".list_bills"))
|
2011-07-30 15:46:53 +02:00
|
|
|
|
2011-08-19 23:44:54 +02:00
|
|
|
return render_template("send_invites.html", form=form)
|
2011-07-23 19:11:24 +02:00
|
|
|
|
2012-03-06 18:41:55 +01:00
|
|
|
|
2011-09-09 21:21:37 +02:00
|
|
|
@main.route("/<project_id>/")
|
2011-08-19 23:44:54 +02:00
|
|
|
def list_bills():
|
2012-03-06 18:41:55 +01:00
|
|
|
bill_form = get_billform_for(g.project)
|
2011-10-20 04:18:12 +02:00
|
|
|
# set the last selected payer as default choice if exists
|
|
|
|
if 'last_selected_payer' in session:
|
|
|
|
bill_form.payer.data = session['last_selected_payer']
|
2011-09-09 19:57:28 +02:00
|
|
|
bills = g.project.get_bills()
|
2011-11-28 01:42:02 +01:00
|
|
|
|
2012-02-20 16:58:18 +01:00
|
|
|
return render_template("list_bills.html",
|
2011-08-19 23:44:54 +02:00
|
|
|
bills=bills, member_form=MemberForm(g.project),
|
2011-11-28 01:42:02 +01:00
|
|
|
bill_form=bill_form,
|
2011-12-03 16:41:46 +01:00
|
|
|
add_bill=request.values.get('add_bill', False)
|
2011-07-31 23:55:18 +02:00
|
|
|
)
|
2011-07-23 20:36:13 +02:00
|
|
|
|
2012-03-06 18:41:55 +01:00
|
|
|
|
2011-09-09 21:21:37 +02:00
|
|
|
@main.route("/<project_id>/members/add", methods=["GET", "POST"])
|
2011-08-19 23:44:54 +02:00
|
|
|
def add_member():
|
2011-07-23 20:36:13 +02:00
|
|
|
# FIXME manage form errors on the list_bills page
|
2011-08-19 23:44:54 +02:00
|
|
|
form = MemberForm(g.project)
|
2011-07-23 20:36:13 +02:00
|
|
|
if request.method == "POST":
|
|
|
|
if form.validate():
|
2011-09-13 22:58:53 +02:00
|
|
|
member = form.save(g.project, Person())
|
2011-07-23 20:36:13 +02:00
|
|
|
db.session.commit()
|
2011-10-15 01:19:19 +02:00
|
|
|
flash(_("%(member)s had been added", member=member.name))
|
2011-09-09 21:21:37 +02:00
|
|
|
return redirect(url_for(".list_bills"))
|
2011-09-13 22:58:53 +02:00
|
|
|
|
2011-08-19 23:44:54 +02:00
|
|
|
return render_template("add_member.html", form=form)
|
2011-07-23 18:45:40 +02:00
|
|
|
|
2012-03-06 18:41:55 +01:00
|
|
|
|
2012-01-28 01:35:04 +01:00
|
|
|
@main.route("/<project_id>/members/<member_id>/reactivate", methods=["POST"])
|
2011-08-25 18:25:58 +02:00
|
|
|
def reactivate(member_id):
|
|
|
|
person = Person.query.filter(Person.id == member_id)\
|
|
|
|
.filter(Project.id == g.project.id).all()
|
|
|
|
if person:
|
|
|
|
person[0].activated = True
|
|
|
|
db.session.commit()
|
2011-10-15 01:19:19 +02:00
|
|
|
flash(_("%(name)s is part of this project again", name=person[0].name))
|
2011-09-09 21:21:37 +02:00
|
|
|
return redirect(url_for(".list_bills"))
|
2011-08-25 18:25:58 +02:00
|
|
|
|
|
|
|
|
2012-01-28 01:35:04 +01:00
|
|
|
@main.route("/<project_id>/members/<member_id>/delete", methods=["POST"])
|
2011-08-19 23:44:54 +02:00
|
|
|
def remove_member(member_id):
|
2011-09-09 19:57:28 +02:00
|
|
|
member = g.project.remove_member(member_id)
|
|
|
|
if member.activated == False:
|
2011-10-15 01:19:19 +02:00
|
|
|
flash(_("User '%(name)s' has been deactivated", name=member.name))
|
2011-09-09 19:57:28 +02:00
|
|
|
else:
|
2011-10-15 01:19:19 +02:00
|
|
|
flash(_("User '%(name)s' has been removed", name=member.name))
|
2011-09-09 19:57:28 +02:00
|
|
|
|
2011-09-09 21:21:37 +02:00
|
|
|
return redirect(url_for(".list_bills"))
|
2011-07-31 23:55:18 +02:00
|
|
|
|
2012-03-06 18:41:55 +01:00
|
|
|
|
2011-09-09 21:21:37 +02:00
|
|
|
@main.route("/<project_id>/add", methods=["GET", "POST"])
|
2011-08-19 23:44:54 +02:00
|
|
|
def add_bill():
|
2011-10-08 13:45:05 +02:00
|
|
|
form = get_billform_for(g.project)
|
2011-07-23 18:45:40 +02:00
|
|
|
if request.method == 'POST':
|
|
|
|
if form.validate():
|
2011-10-20 04:18:12 +02:00
|
|
|
# save last selected payer in session
|
|
|
|
session['last_selected_payer'] = form.payer.data
|
|
|
|
session.update()
|
|
|
|
|
2011-08-10 12:59:30 +02:00
|
|
|
bill = Bill()
|
2011-10-08 13:22:18 +02:00
|
|
|
db.session.add(form.save(bill, g.project))
|
2011-07-23 18:45:40 +02:00
|
|
|
db.session.commit()
|
2011-07-31 00:41:28 +02:00
|
|
|
|
2011-10-15 01:19:19 +02:00
|
|
|
flash(_("The bill has been added"))
|
2011-12-03 16:41:46 +01:00
|
|
|
|
|
|
|
args = {}
|
|
|
|
if form.submit2.data:
|
|
|
|
args['add_bill'] = True
|
|
|
|
|
|
|
|
return redirect(url_for('.list_bills', **args))
|
2011-07-23 18:45:40 +02:00
|
|
|
|
2011-08-19 23:44:54 +02:00
|
|
|
return render_template("add_bill.html", form=form)
|
2011-07-23 18:45:40 +02:00
|
|
|
|
|
|
|
|
2011-09-09 21:21:37 +02:00
|
|
|
@main.route("/<project_id>/delete/<int:bill_id>")
|
2011-08-19 23:44:54 +02:00
|
|
|
def delete_bill(bill_id):
|
2011-09-13 18:15:07 +02:00
|
|
|
# fixme: everyone is able to delete a bill
|
|
|
|
bill = Bill.query.get(g.project, bill_id)
|
|
|
|
if not bill:
|
|
|
|
raise werkzeug.exceptions.NotFound()
|
|
|
|
|
2011-08-10 12:59:30 +02:00
|
|
|
db.session.delete(bill)
|
|
|
|
db.session.commit()
|
2011-10-15 01:19:19 +02:00
|
|
|
flash(_("The bill has been deleted"))
|
2011-08-10 12:59:30 +02:00
|
|
|
|
2011-09-09 21:21:37 +02:00
|
|
|
return redirect(url_for('.list_bills'))
|
2011-08-10 12:59:30 +02:00
|
|
|
|
|
|
|
|
2011-09-09 21:21:37 +02:00
|
|
|
@main.route("/<project_id>/edit/<int:bill_id>", methods=["GET", "POST"])
|
2011-08-19 23:44:54 +02:00
|
|
|
def edit_bill(bill_id):
|
2011-09-13 18:15:07 +02:00
|
|
|
# FIXME: Test this bill belongs to this project !
|
|
|
|
bill = Bill.query.get(g.project, bill_id)
|
|
|
|
if not bill:
|
|
|
|
raise werkzeug.exceptions.NotFound()
|
|
|
|
|
2011-10-08 13:45:05 +02:00
|
|
|
form = get_billform_for(g.project, set_default=False)
|
2011-09-18 23:38:12 +02:00
|
|
|
|
2011-08-10 12:59:30 +02:00
|
|
|
if request.method == 'POST' and form.validate():
|
2011-10-08 13:22:18 +02:00
|
|
|
form.save(bill, g.project)
|
2011-08-10 12:59:30 +02:00
|
|
|
db.session.commit()
|
|
|
|
|
2011-10-15 01:19:19 +02:00
|
|
|
flash(_("The bill has been modified"))
|
2011-09-09 21:21:37 +02:00
|
|
|
return redirect(url_for('.list_bills'))
|
2011-08-10 12:59:30 +02:00
|
|
|
|
2011-11-28 01:07:06 +01:00
|
|
|
if not form.errors:
|
|
|
|
form.fill(bill)
|
|
|
|
|
2011-08-21 01:42:10 +02:00
|
|
|
return render_template("add_bill.html", form=form, edit=True)
|
2011-08-10 12:59:30 +02:00
|
|
|
|
2012-03-06 18:41:55 +01:00
|
|
|
|
2011-10-17 00:03:41 +02:00
|
|
|
@main.route("/lang/<lang>")
|
|
|
|
def change_lang(lang):
|
|
|
|
session['lang'] = lang
|
|
|
|
session.update()
|
|
|
|
|
|
|
|
return redirect(request.headers.get('Referer') or url_for('.home'))
|
|
|
|
|
2012-03-06 18:41:55 +01:00
|
|
|
|
2011-09-09 21:21:37 +02:00
|
|
|
@main.route("/<project_id>/compute")
|
2011-08-19 23:44:54 +02:00
|
|
|
def compute_bills():
|
2011-07-23 18:45:40 +02:00
|
|
|
"""Compute the sum each one have to pay to each other and display it"""
|
2011-08-19 23:44:54 +02:00
|
|
|
return render_template("compute_bills.html")
|
2011-07-23 18:45:40 +02:00
|
|
|
|
2012-03-06 18:41:55 +01:00
|
|
|
|
2012-11-26 21:52:25 +01:00
|
|
|
@main.route("/<project_id>/archives/create", methods=["GET", "POST"])
|
2011-09-09 19:14:19 +02:00
|
|
|
def create_archive():
|
2012-02-20 16:58:18 +01:00
|
|
|
form = CreateArchiveForm()
|
2011-09-09 19:14:19 +02:00
|
|
|
if request.method == "POST":
|
|
|
|
if form.validate():
|
|
|
|
pass
|
2011-10-15 01:19:19 +02:00
|
|
|
flash(_("The data from XX to XX has been archived"))
|
2011-07-23 18:45:40 +02:00
|
|
|
|
2011-09-09 19:14:19 +02:00
|
|
|
return render_template("create_archive.html", form=form)
|
2011-11-28 00:36:00 +01:00
|
|
|
|
2012-03-06 18:41:55 +01:00
|
|
|
|
2011-11-28 00:36:00 +01:00
|
|
|
@main.route("/dashboard")
|
|
|
|
def dashboard():
|
|
|
|
return render_template("dashboard.html", projects=Project.query.all())
|