diff --git a/app/templates/home.html b/app/templates/home.html index 2d42adc..c280c45 100644 --- a/app/templates/home.html +++ b/app/templates/home.html @@ -14,5 +14,13 @@ {% endfor %} +
+

Recently closed orders:

+ +
{% endblock %} \ No newline at end of file diff --git a/app/views/__init__.py b/app/views/__init__.py index 06aa7e2..0a668fd 100644 --- a/app/views/__init__.py +++ b/app/views/__init__.py @@ -2,17 +2,19 @@ __author__ = 'feliciaan' from flask import url_for, render_template, abort, redirect, request from flask.ext.login import current_user, login_required -from datetime import datetime +from datetime import datetime, timedelta from app import app, db from models import Order, OrderItem # import views -import views.order +from views.order import get_orders @app.route('/') def home(): - return render_template('home.html', orders=views.order.get_orders()) + prev_day = datetime.now() - timedelta(days=1) + recently_closed = get_orders(((Order.stoptime > prev_day) & (Order.stoptime < datetime.now()))) + return render_template('home.html', orders=get_orders(), recently_closed=recently_closed) @app.route('/about/') diff --git a/app/views/order.py b/app/views/order.py index 267a921..91bb2f6 100644 --- a/app/views/order.py +++ b/app/views/order.py @@ -143,10 +143,10 @@ def select_user(items): return user -def get_orders(): +def get_orders(expression=(Order.stoptime > datetime.now()) | (Order.stoptime == None)): orders = [] if not current_user.is_anonymous(): - orders = Order.query.filter((Order.stoptime > datetime.now()) | (Order.stoptime == None)).all() + orders = Order.query.filter(expression).all() else: - orders = Order.query.filter(((Order.stoptime > datetime.now()) | (Order.stoptime == None) & (Order.public == True))).all() + orders = Order.query.filter((expression & (Order.public == True))).all() return orders