Also show recently closed orders
This commit is contained in:
parent
08c0922591
commit
b4d1868988
3 changed files with 16 additions and 6 deletions
|
@ -14,5 +14,13 @@
|
|||
{% endfor %}
|
||||
</ul>
|
||||
</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>
|
||||
{% endblock %}
|
|
@ -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/')
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue