"I volunteer as Tribute"

This commit is contained in:
Feliciaan De Palmenaer 2015-03-28 01:09:59 +01:00
parent c160002a94
commit 7514396669
4 changed files with 31 additions and 5 deletions

View file

@ -1,4 +1,5 @@
from datetime import datetime, timedelta from datetime import datetime, timedelta
from flask.ext.login import current_user
from flask_wtf import Form from flask_wtf import Form
from wtforms import SelectField, DateTimeField, validators, SubmitField, HiddenField from wtforms import SelectField, DateTimeField, validators, SubmitField, HiddenField
from models import User, Location from models import User, Location
@ -15,8 +16,11 @@ class OrderForm(Form):
submit_button = SubmitField('Submit') submit_button = SubmitField('Submit')
def populate(self): def populate(self):
if current_user.is_admin():
self.courrier_id.choices = [(0, None)] + \ self.courrier_id.choices = [(0, None)] + \
[(u.id, u.username) for u in User.query.order_by('username')] [(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) self.location_id.choices = [(l.id, l.name)
for l in Location.query.order_by('name')] for l in Location.query.order_by('name')]
if self.stoptime.data is None: if self.stoptime.data is None:

View file

@ -1,4 +1,5 @@
{% extends "bootstrap/base.html" %} {% extends "bootstrap/base.html" %}
{% import "bootstrap/utils.html" as utils %}
{% set navbar = [ {% set navbar = [
('home', 'Home'), ('home', 'Home'),
@ -52,6 +53,7 @@
{% endblock %} {% endblock %}
{% block content -%} {% block content -%}
{{ utils.flashed_messages() }}
<div class="container"> <div class="container">
{% block container -%} {% block container -%}
{%- endblock %} {%- endblock %}

View file

@ -6,7 +6,11 @@
<div class="row"> <div class="row">
<div class="col-md-7"><!-- Shitty html--> <div class="col-md-7"><!-- Shitty html-->
<h3>Order {{ order.id }}</h3> <h3>Order {{ order.id }}</h3>
Courrier: {{ order.courrier.username }}<br/> Courrier: {{ order.courrier.username }}
{% if order.courrier == None %}
<a href="{{ url_for('.volunteer', id=order.id) }}" class="btn btn-primary">Volunteer</a>
{% endif %}
<br/>
Location: <a href="{{ order.location.website }}">{{ order.location.name }}</a><br/> Location: <a href="{{ order.location.website }}">{{ order.location.name }}</a><br/>
Starttime: {{ order.starttime }}<br/> Starttime: {{ order.starttime }}<br/>
Stoptime: {{ order.stoptime }}<br/> Stoptime: {{ order.stoptime }}<br/>
@ -19,7 +23,7 @@
</div> </div>
<div class="col-md-push-1 col-md-4"> <div class="col-md-push-1 col-md-4">
<h4>Order:</h4> <h4>Order:</h4>
{{ 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') }}
</div> </div>
</div> </div>
{% endblock %} {% endblock %}

View file

@ -1,5 +1,5 @@
__author__ = 'feliciaan' __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 flask.ext.login import current_user, login_required
from datetime import datetime from datetime import datetime
@ -73,4 +73,20 @@ def delete_item(order_id, item_id):
return redirect(url_for('.order', id=order_id)) return redirect(url_for('.order', id=order_id))
abort(404) abort(404)
@order_bp.route('/<id>/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') app.register_blueprint(order_bp, url_prefix='/order')