From 7514396669051197adeaa1b3261f21478d29e26b Mon Sep 17 00:00:00 2001 From: Feliciaan De Palmenaer Date: Sat, 28 Mar 2015 01:09:59 +0100 Subject: [PATCH] "I volunteer as Tribute" --- app/forms.py | 8 ++++++-- app/templates/layout.html | 2 ++ app/templates/order.html | 8 ++++++-- app/views/order.py | 18 +++++++++++++++++- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/app/forms.py b/app/forms.py index 8aa1a20..873c9cb 100644 --- a/app/forms.py +++ b/app/forms.py @@ -1,4 +1,5 @@ from datetime import datetime, timedelta +from flask.ext.login import current_user from flask_wtf import Form from wtforms import SelectField, DateTimeField, validators, SubmitField, HiddenField from models import User, Location @@ -15,8 +16,11 @@ class OrderForm(Form): submit_button = SubmitField('Submit') def populate(self): - self.courrier_id.choices = [(0, None)] + \ - [(u.id, u.username) for u in User.query.order_by('username')] + if current_user.is_admin(): + self.courrier_id.choices = [(0, None)] + \ + [(u.id, u.username) for u in User.query.order_by('username')] + else: + self.courrier_id.choices = [(0, None), (current_user.id, current_user.username)] self.location_id.choices = [(l.id, l.name) for l in Location.query.order_by('name')] if self.stoptime.data is None: diff --git a/app/templates/layout.html b/app/templates/layout.html index 8f4c712..0971737 100644 --- a/app/templates/layout.html +++ b/app/templates/layout.html @@ -1,4 +1,5 @@ {% extends "bootstrap/base.html" %} +{% import "bootstrap/utils.html" as utils %} {% set navbar = [ ('home', 'Home'), @@ -52,6 +53,7 @@ {% endblock %} {% block content -%} + {{ utils.flashed_messages() }}
{% block container -%} {%- endblock %} diff --git a/app/templates/order.html b/app/templates/order.html index 39e13b0..ab64a8b 100644 --- a/app/templates/order.html +++ b/app/templates/order.html @@ -6,7 +6,11 @@

Order {{ order.id }}

- Courrier: {{ order.courrier.username }}
+ Courrier: {{ order.courrier.username }} + {% if order.courrier == None %} + Volunteer + {% endif %} +
Location: {{ order.location.name }}
Starttime: {{ order.starttime }}
Stoptime: {{ order.stoptime }}
@@ -19,7 +23,7 @@

Order:

- {{ wtf.quick_form(form, action=url_for('.order_create'), button_map={'submit_button': 'primary'}, form_type='horizontal') }} + {{ wtf.quick_form(form, action=url_for('.order_item_create', id=order.id), button_map={'submit_button': 'primary'}, form_type='horizontal') }}
{% endblock %} \ No newline at end of file diff --git a/app/views/order.py b/app/views/order.py index a12ba3d..92b59e9 100644 --- a/app/views/order.py +++ b/app/views/order.py @@ -1,5 +1,5 @@ __author__ = 'feliciaan' -from flask import url_for, render_template, abort, redirect, Blueprint +from flask import url_for, render_template, abort, redirect, Blueprint, flash from flask.ext.login import current_user, login_required from datetime import datetime @@ -73,4 +73,20 @@ def delete_item(order_id, item_id): return redirect(url_for('.order', id=order_id)) abort(404) + +@order_bp.route('//volunteer') +@login_required +def volunteer(id): + order = Order.query.filter(Order.id == id).first() + if order is not None: + print(order.courrier_id) + if order.courrier_id == 0: + order.courrier_id = current_user.id + db.session.commit() + flash("Thank you for volunteering!") + else: + flash("Volunteering not possible!") + return redirect(url_for('.order', id=id)) + abort(404) + app.register_blueprint(order_bp, url_prefix='/order') \ No newline at end of file