Also show recently closed orders

This commit is contained in:
Feliciaan De Palmenaer 2015-03-28 21:25:55 +01:00
parent 08c0922591
commit b4d1868988
3 changed files with 16 additions and 6 deletions

View file

@ -14,5 +14,13 @@
{% endfor %} {% endfor %}
</ul> </ul>
</div> </div>
<div class="col-md-4 col-md-push-4">
<h3>Recently closed orders:</h3>
<ul>
{% for order in recently_closed %}
<li><a href="{{ url_for('order_bp.order', id=order.id) }}">{{ order.location.name }}-{{ order.stoptime }}</a></li>
{% endfor %}
</ul>
</div>
</div> </div>
{% endblock %} {% endblock %}

View file

@ -2,17 +2,19 @@ __author__ = 'feliciaan'
from flask import url_for, render_template, abort, redirect, request from flask import url_for, render_template, abort, redirect, request
from flask.ext.login import current_user, login_required from flask.ext.login import current_user, login_required
from datetime import datetime from datetime import datetime, timedelta
from app import app, db from app import app, db
from models import Order, OrderItem from models import Order, OrderItem
# import views # import views
import views.order from views.order import get_orders
@app.route('/') @app.route('/')
def home(): 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/') @app.route('/about/')

View file

@ -143,10 +143,10 @@ def select_user(items):
return user return user
def get_orders(): def get_orders(expression=(Order.stoptime > datetime.now()) | (Order.stoptime == None)):
orders = [] orders = []
if not current_user.is_anonymous(): 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: 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 return orders