1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/ihatemoney_ynh.git synced 2024-09-03 19:26:15 +02:00

Manage users creation

This commit is contained in:
Alexis Metaireau 2011-07-23 20:36:13 +02:00
parent f09d86a06c
commit a3b49a231f
5 changed files with 66 additions and 37 deletions

View file

@ -1,5 +1,5 @@
from flaskext.wtf import * from flaskext.wtf import *
from models import Project from models import Project, Person
# define forms # define forms
class CreationForm(Form): class CreationForm(Form):
@ -33,3 +33,16 @@ class BillForm(Form):
validators=[Required()]) validators=[Required()])
submit = SubmitField("Add the bill") submit = SubmitField("Add the bill")
class MemberForm(Form):
def __init__(self, project, *args, **kwargs):
super(MemberForm, self).__init__(*args, **kwargs)
self.project = project
name = TextField("Name", validators=[Required()])
submit = SubmitField("Add a member")
def validate_name(form, field):
if Person.query.filter(
Person.name == field.data and Person.project == self.project).all():
raise ValidationError("This project already have this member")

View file

@ -22,7 +22,7 @@ class Person(db.Model):
bills = db.relationship("Bill", backref="payer") bills = db.relationship("Bill", backref="payer")
name = db.Column(db.UnicodeText) name = db.Column(db.UnicodeText)
status = db.Column(db.Boolean) # activated = db.Column(db.Boolean, default=True)
def __repr__(self): def __repr__(self):
return "<Person %s for project %s>" % (self.name, self.project.name) return "<Person %s for project %s>" % (self.name, self.project.name)

View file

@ -16,16 +16,11 @@
</div> </div>
</div> </div>
<hr> <hr>
<div id="content" class="span-24">
{% for message in get_flashed_messages() %} {% for message in get_flashed_messages() %}
<div class=info>{{ message }}</div> <div class=info>{{ message }}</div>
{% endfor %} {% endfor %}
{% block content %} {% block content %}
{% endblock %} {% endblock %}
</div>
<div id="footer"></div> <div id="footer"></div>
</div> </div>
</body> </body>

View file

@ -1,26 +1,37 @@
{% extends "layout.html" %} {% extends "layout.html" %}
{% block content %} {% block content %}
{% if bills.count() > 0 %} <div id="leftmenu" class="span-6">
<table> <ul>
{% for member in project.members %}
<li>{{ member.name }}</li>
{% endfor %}
</ul>
{% set form=member_form %}
{% include "member_form.html" %}
</div>
<div id="content" class="span-18 last">
{% if bills.count() > 0 %}
<table>
<thead><tr><th>When ?</th><th>Who paid?</th><th>for what ?</th><th>Owers</th><th>How much ?</th><th>Actions</th></tr></thead> <thead><tr><th>When ?</th><th>Who paid?</th><th>for what ?</th><th>Owers</th><th>How much ?</th><th>Actions</th></tr></thead>
<tbody> <tbody>
{% for bill in bills %} {% for bill in bills %}
<tr class="{{ loop.cycle("odd", "even") }}"> <tr class="{{ loop.cycle("odd", "even") }}">
<td>{{ bill.date }}</td> <td>{{ bill.date }}</td>
<td>{{ bill.payer }}</td> <td>{{ bill.payer }}</td>
<td>{{ bill.what }}</td> <td>{{ bill.what }}</td>
<td>{% for ower in bill.owers %}{{ ower.name }} {% endfor %}</td> <td>{% for ower in bill.owers %}{{ ower.name }} {% endfor %}</td>
<td>{{ bill.amount }} ({{ bill.pay_each() }} each)</td> <td>{{ bill.amount }} ({{ bill.pay_each() }} each)</td>
<td><a href="{{ url_for("delete_bill", bill_id=bill.id, project_id=project.id) }}">delete</a></td> <td><a href="{{ url_for("delete_bill", bill_id=bill.id, project_id=project.id) }}">delete</a></td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
<a class="awesome large green button fleft" href="{{ url_for("compute_bills", project_id=project.id) }}">Compute bills</a> <a class="awesome large green button fleft" href="{{ url_for("compute_bills", project_id=project.id) }}">Compute bills</a>
<p> Periodically (probably at the end of each month, you can compute the balance of each people, in order to reset all the debts. You can also let this "as-is" and try to find a good balance, that's up to you</p> <p> Periodically (probably at the end of each month, you can compute the balance of each people, in order to reset all the debts. You can also let this "as-is" and try to find a good balance, that's up to you</p>
{% else %} {% else %}
<p>Nothing to list yet. You probably want to <a href="{{ url_for("add_bill", project_id=project.id) }}">add a bill</a> ?</p> <p>Nothing to list yet. You probably want to <a href="{{ url_for("add_bill", project_id=project.id) }}">add a bill</a> ?</p>
{% endif %} {% endif %}
</div>
{% endblock %} {% endblock %}

View file

@ -2,7 +2,7 @@ from flask import Flask, session, request, redirect, url_for, render_template
# local modules # local modules
from models import db, Project, Person, Bill from models import db, Project, Person, Bill
from forms import CreationForm, AuthenticationForm, BillForm from forms import CreationForm, AuthenticationForm, BillForm, MemberForm
from utils import get_billform_for, requires_auth from utils import get_billform_for, requires_auth
# create the application, initialize stuff # create the application, initialize stuff
@ -26,7 +26,6 @@ def authenticate(project_id, redirect_url=None):
else: else:
session[project_id] = form.password.data session[project_id] = form.password.data
session.update() session.update()
from ipdb import set_trace; set_trace()
return redirect(redirect_url) return redirect(redirect_url)
return render_template("authenticate.html", form=form, project=project) return render_template("authenticate.html", form=form, project=project)
@ -38,7 +37,6 @@ def home():
@app.route("/create", methods=["GET", "POST"]) @app.route("/create", methods=["GET", "POST"])
def create_project(): def create_project():
from ipdb import set_trace; set_trace()
form = CreationForm() form = CreationForm()
if request.method == "GET" and 'project_id' in request.values: if request.method == "GET" and 'project_id' in request.values:
form.name.data = request.values['project_id'] form.name.data = request.values['project_id']
@ -71,7 +69,19 @@ def list_bills(project):
# FIXME filter to only get the bills for this particular project # FIXME filter to only get the bills for this particular project
bills = Bill.query.order_by(Bill.id.asc()) bills = Bill.query.order_by(Bill.id.asc())
return render_template("list_bills.html", return render_template("list_bills.html",
bills=bills, project=project) bills=bills, project=project, member_form=MemberForm(project))
@app.route("/<string:project_id>/members/add", methods=["GET", "POST"])
@requires_auth
def add_member(project):
# FIXME manage form errors on the list_bills page
form = MemberForm(project)
if request.method == "POST":
if form.validate():
db.session.add(Person(name=form.name.data, project=project))
db.session.commit()
return redirect(url_for("list_bills", project_id=project.id))
return render_template("add_member.html", form=form, project=project)
@app.route("/<string:project_id>/add", methods=["GET", "POST"]) @app.route("/<string:project_id>/add", methods=["GET", "POST"])
@requires_auth @requires_auth