"I volunteer as Tribute"
This commit is contained in:
parent
c160002a94
commit
7514396669
4 changed files with 31 additions and 5 deletions
|
@ -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:
|
||||
|
|
|
@ -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() }}
|
||||
<div class="container">
|
||||
{% block container -%}
|
||||
{%- endblock %}
|
||||
|
|
|
@ -6,7 +6,11 @@
|
|||
<div class="row">
|
||||
<div class="col-md-7"><!-- Shitty html-->
|
||||
<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/>
|
||||
Starttime: {{ order.starttime }}<br/>
|
||||
Stoptime: {{ order.stoptime }}<br/>
|
||||
|
@ -19,7 +23,7 @@
|
|||
</div>
|
||||
<div class="col-md-push-1 col-md-4">
|
||||
<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>
|
||||
{% endblock %}
|
|
@ -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('/<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')
|
Loading…
Reference in a new issue