2015-03-27 21:57:37 +01:00
|
|
|
from datetime import datetime, timedelta
|
|
|
|
from flask_wtf import Form
|
2015-03-28 00:02:12 +01:00
|
|
|
from wtforms import SelectField, DateTimeField, validators, SubmitField, HiddenField
|
2015-03-27 21:57:37 +01:00
|
|
|
from models import User, Location
|
2015-03-28 00:02:12 +01:00
|
|
|
from utils import euro
|
2015-03-27 21:57:37 +01:00
|
|
|
|
|
|
|
__author__ = 'feliciaan'
|
|
|
|
|
|
|
|
|
|
|
|
class OrderForm(Form):
|
|
|
|
courrier_id = SelectField('Courrier', coerce=int)
|
2015-03-28 00:02:12 +01:00
|
|
|
location_id = SelectField('Location', coerce=int, validators=[validators.required()])
|
2015-03-27 21:57:37 +01:00
|
|
|
starttime = DateTimeField('Starttime', default=datetime.now)
|
|
|
|
stoptime = DateTimeField('Stoptime')
|
2015-03-28 00:02:12 +01:00
|
|
|
submit_button = SubmitField('Submit')
|
2015-03-27 21:57:37 +01:00
|
|
|
|
|
|
|
def populate(self):
|
|
|
|
self.courrier_id.choices = [(0, None)] + \
|
|
|
|
[(u.id, u.username) for u in User.query.order_by('username')]
|
|
|
|
self.location_id.choices = [(l.id, l.name)
|
|
|
|
for l in Location.query.order_by('name')]
|
|
|
|
if self.stoptime.data is None:
|
|
|
|
self.stoptime.data = datetime.now() + timedelta(hours=1)
|
|
|
|
|
|
|
|
|
2015-03-28 00:02:12 +01:00
|
|
|
class OrderItemForm(Form):
|
|
|
|
food_id = SelectField('Item', coerce=int)
|
|
|
|
submit_button = SubmitField('Submit')
|
|
|
|
|
|
|
|
def populate(self, location):
|
|
|
|
self.food_id.choices = [(i.id, (i.name + ": " + euro(i.price))) for i in location.food]
|