From 801802836a648ac0865c1c932e3cf9a01e3a639e Mon Sep 17 00:00:00 2001 From: Alexis Metaireau Date: Fri, 9 Sep 2011 19:14:19 +0200 Subject: [PATCH] Start working on archive management --- budget/forms.py | 5 +++++ budget/models.py | 17 +++++++++++++++++ budget/templates/add_bill.html | 3 +-- budget/templates/create_archive.html | 7 +++++++ budget/templates/forms.html | 16 ++++++++++++++-- budget/templates/list_bills.html | 2 +- budget/web.py | 22 ++++++++++------------ 7 files changed, 55 insertions(+), 17 deletions(-) create mode 100644 budget/templates/create_archive.html diff --git a/budget/forms.py b/budget/forms.py index 6272b7f..7ac48cc 100644 --- a/budget/forms.py +++ b/budget/forms.py @@ -100,3 +100,8 @@ class InviteForm(Form): if not validator.regex.match(email): raise ValidationError("The email %s is not valid" % email) + +class CreateArchiveForm(Form): + start_date = DateField("Start date", validators=[Required(),]) + end_date = DateField("End date", validators=[Required(),]) + name = TextField("Name for this archive (optional)") diff --git a/budget/models.py b/budget/models.py index ab93548..08e46ae 100644 --- a/budget/models.py +++ b/budget/models.py @@ -78,6 +78,8 @@ class Bill(db.Model): date = db.Column(db.Date, default=datetime.now) what = db.Column(db.UnicodeText) + archive = db.Column(db.Integer, db.ForeignKey("archive.id")) + def pay_each(self): """Compute what each person has to pay""" return round(self.amount / len(self.owers), 2) @@ -87,3 +89,18 @@ class Bill(db.Model): self.payer, ", ".join([o.name for o in self.owers])) +class Archive(db.Model): + id = db.Column(db.Integer, primary_key=True) + project_id = db.Column(db.Integer, db.ForeignKey("project.id")) + name = db.Column(db.UnicodeText) + + @property + def start_date(self): + pass + + @property + def end_date(self): + pass + + def __repr__(self): + return "" diff --git a/budget/templates/add_bill.html b/budget/templates/add_bill.html index ec60f43..0b575d7 100644 --- a/budget/templates/add_bill.html +++ b/budget/templates/add_bill.html @@ -5,9 +5,8 @@ {% endblock %} {% block content %} -

{% if edit %}Edit a{% else %}Add a new{% endif %} bill

- {{ forms.add_bill(form) }} + {{ forms.add_bill(form, edit) }}
{% endblock %} diff --git a/budget/templates/create_archive.html b/budget/templates/create_archive.html new file mode 100644 index 0000000..ae96a30 --- /dev/null +++ b/budget/templates/create_archive.html @@ -0,0 +1,7 @@ +{% extends "layout.html" %} + +{% block content %} +
+{{ forms.create_archive(form) }} +
+{% endblock %} diff --git a/budget/templates/forms.html b/budget/templates/forms.html index 8ac458f..7b512ff 100644 --- a/budget/templates/forms.html +++ b/budget/templates/forms.html @@ -52,10 +52,10 @@ {% endmacro %} -{% macro add_bill(form) %} +{% macro add_bill(form, edit=False) %}
- Add a bill + {% if edit %}Edit this {% else %}Add a {% endif %}bill {% include "display_errors.html" %} {{ form.hidden_tag() }} {{ input(form.date) }} @@ -83,3 +83,15 @@ No, thanks {% endmacro %} + +{% macro create_archive(form) %} +
+ Create an archive + {{ form.hidden_tag() }} + {{ input(form.start_date) }} + {{ input(form.end_date) }} +
+
+ +
+{% endmacro %} diff --git a/budget/templates/list_bills.html b/budget/templates/list_bills.html index e9699dd..b485f81 100644 --- a/budget/templates/list_bills.html +++ b/budget/templates/list_bills.html @@ -78,7 +78,7 @@ {% for ower in bill.owers %}{{ ower.name }} {% endfor %} {{ bill.amount }} ({{ bill.pay_each() }} each) edit - delete + delete {% endfor %} diff --git a/budget/web.py b/budget/web.py index be5b1e9..d59d6d9 100644 --- a/budget/web.py +++ b/budget/web.py @@ -5,7 +5,8 @@ from flaskext.mail import Mail, Message # local modules from models import db, Project, Person, Bill -from forms import ProjectForm, AuthenticationForm, BillForm, MemberForm, InviteForm +from forms import (ProjectForm, AuthenticationForm, BillForm, MemberForm, + InviteForm, CreateArchiveForm) from utils import get_billform_for, Redirect303 # create the application, initialize stuff @@ -256,18 +257,15 @@ def compute_bills(): """Compute the sum each one have to pay to each other and display it""" return render_template("compute_bills.html") +@app.route("//archives/create") +def create_archive(): + form = CreateArchiveForm() + if request.method == "POST": + if form.validate(): + pass + flash("The data from XX to XX has been archived") -@app.route("//reset") -def reset_bills(): - """Reset the list of bills""" - # FIXME replace with the archive feature - # get all the bills which are not processed - bills = Bill.query.filter(Bill.processed == False) - for bill in bills: - bill.processed = True - db.session.commit() - - return redirect(url_for('list_bills')) + return render_template("create_archive.html", form=form) def main():