mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-04-29 01:42:37 +02:00
Project creation.
This commit is contained in:
parent
adabd8beec
commit
f09d86a06c
3 changed files with 56 additions and 28 deletions
|
@ -1,4 +1,5 @@
|
||||||
from flaskext.wtf import *
|
from flaskext.wtf import *
|
||||||
|
from models import Project
|
||||||
|
|
||||||
# define forms
|
# define forms
|
||||||
class CreationForm(Form):
|
class CreationForm(Form):
|
||||||
|
@ -8,6 +9,16 @@ class CreationForm(Form):
|
||||||
contact_email = TextField("Email", validators=[Required(), Email()])
|
contact_email = TextField("Email", validators=[Required(), Email()])
|
||||||
submit = SubmitField("Get in")
|
submit = SubmitField("Get in")
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
"""Create a new project with the information given by this form.
|
||||||
|
|
||||||
|
Returns the created instance
|
||||||
|
"""
|
||||||
|
project = Project(name=self.name.data, id=self.id.data,
|
||||||
|
password=self.password.data,
|
||||||
|
contact_email=self.contact_email.data)
|
||||||
|
return project
|
||||||
|
|
||||||
|
|
||||||
class AuthenticationForm(Form):
|
class AuthenticationForm(Form):
|
||||||
password = TextField("Password", validators=[Required()])
|
password = TextField("Password", validators=[Required()])
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<ul>{% for error in form.errors %}<li>{{ error }}</li>{% endfor %}</ul>
|
<ul>{% for error in form.errors %}<li>{{ error }}</li>{% endfor %}</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<form method="POST" class="container span-24 add-bill">
|
<form method="post" class="container span-24 add-bill">
|
||||||
{{ form.hidden_tag() }}
|
{{ form.hidden_tag() }}
|
||||||
|
|
||||||
<p>{{ form.name.label }}<br /> {{ form.name }}</p>
|
<p>{{ form.name.label }}<br /> {{ form.name }}</p>
|
||||||
|
|
|
@ -8,31 +8,6 @@ from utils import get_billform_for, requires_auth
|
||||||
# create the application, initialize stuff
|
# create the application, initialize stuff
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@app.route("/")
|
|
||||||
def home():
|
|
||||||
return "this is the homepage"
|
|
||||||
|
|
||||||
@app.route("/create")
|
|
||||||
def create_project():
|
|
||||||
form = CreationForm()
|
|
||||||
if 'project_id' in request.values:
|
|
||||||
form.name.data = request.values['project_id']
|
|
||||||
|
|
||||||
if request.method == "POST":
|
|
||||||
if form.validate():
|
|
||||||
# populate object & redirect
|
|
||||||
pass
|
|
||||||
|
|
||||||
return render_template("create_project.html", form=form)
|
|
||||||
|
|
||||||
@app.route("/<string:project_id>/")
|
|
||||||
@requires_auth
|
|
||||||
def list_bills(project):
|
|
||||||
bills = Bill.query.order_by(Bill.id.asc())
|
|
||||||
return render_template("list_bills.html",
|
|
||||||
bills=bills, project=project)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/<string:project_id>/authenticate", methods=["GET", "POST"])
|
@app.route("/<string:project_id>/authenticate", methods=["GET", "POST"])
|
||||||
def authenticate(project_id, redirect_url=None):
|
def authenticate(project_id, redirect_url=None):
|
||||||
project = Project.query.get(project_id)
|
project = Project.query.get(project_id)
|
||||||
|
@ -56,10 +31,52 @@ def authenticate(project_id, redirect_url=None):
|
||||||
|
|
||||||
return render_template("authenticate.html", form=form, project=project)
|
return render_template("authenticate.html", form=form, project=project)
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
def home():
|
||||||
|
# FIXME create a real homepage
|
||||||
|
return "this is the homepage"
|
||||||
|
|
||||||
|
@app.route("/create", methods=["GET", "POST"])
|
||||||
|
def create_project():
|
||||||
|
from ipdb import set_trace; set_trace()
|
||||||
|
form = CreationForm()
|
||||||
|
if request.method == "GET" and 'project_id' in request.values:
|
||||||
|
form.name.data = request.values['project_id']
|
||||||
|
|
||||||
|
if request.method == "POST":
|
||||||
|
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()
|
||||||
|
|
||||||
|
# redirect the user to the next step (invite)
|
||||||
|
return redirect(url_for("invite", project_id=project.id))
|
||||||
|
|
||||||
|
return render_template("create_project.html", form=form)
|
||||||
|
|
||||||
|
@app.route("/<string:project_id>/invite")
|
||||||
|
@requires_auth
|
||||||
|
def invite(project):
|
||||||
|
# FIXME create a real page: form + send emails
|
||||||
|
return "invite ppl"
|
||||||
|
|
||||||
|
@app.route("/<string:project_id>/")
|
||||||
|
@requires_auth
|
||||||
|
def list_bills(project):
|
||||||
|
# FIXME filter to only get the bills for this particular project
|
||||||
|
bills = Bill.query.order_by(Bill.id.asc())
|
||||||
|
return render_template("list_bills.html",
|
||||||
|
bills=bills, project=project)
|
||||||
|
|
||||||
@app.route("/<string:project_id>/add", methods=["GET", "POST"])
|
@app.route("/<string:project_id>/add", methods=["GET", "POST"])
|
||||||
@requires_auth
|
@requires_auth
|
||||||
def add_bill(project):
|
def add_bill(project):
|
||||||
|
# FIXME: make it work.
|
||||||
form = get_billform_for(project.id)
|
form = get_billform_for(project.id)
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
if form.validate():
|
if form.validate():
|
||||||
|
@ -72,8 +89,6 @@ def add_bill(project):
|
||||||
bill.owers.append(ower)
|
bill.owers.append(ower)
|
||||||
|
|
||||||
db.session.add(bill)
|
db.session.add(bill)
|
||||||
|
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash("The bill have been added")
|
flash("The bill have been added")
|
||||||
return redirect(url_for('list_bills'))
|
return redirect(url_for('list_bills'))
|
||||||
|
@ -85,6 +100,7 @@ def add_bill(project):
|
||||||
@requires_auth
|
@requires_auth
|
||||||
def compute_bills(project):
|
def compute_bills(project):
|
||||||
"""Compute the sum each one have to pay to each other and display it"""
|
"""Compute the sum each one have to pay to each other and display it"""
|
||||||
|
# FIXME make it work
|
||||||
|
|
||||||
balances, should_pay, should_receive = {}, {}, {}
|
balances, should_pay, should_receive = {}, {}, {}
|
||||||
# for each person, get the list of should_pay other have for him
|
# for each person, get the list of should_pay other have for him
|
||||||
|
@ -108,6 +124,7 @@ def compute_bills(project):
|
||||||
@requires_auth
|
@requires_auth
|
||||||
def reset_bills(project):
|
def reset_bills(project):
|
||||||
"""Reset the list of bills"""
|
"""Reset the list of bills"""
|
||||||
|
# FIXME replace with the archive feature
|
||||||
# get all the bills which are not processed
|
# get all the bills which are not processed
|
||||||
bills = Bill.query.filter(Bill.processed == False)
|
bills = Bill.query.filter(Bill.processed == False)
|
||||||
for bill in bills:
|
for bill in bills:
|
||||||
|
|
Loading…
Reference in a new issue