Added orders form (simple bootstrap), using new bootstrap package

This commit is contained in:
Feliciaan De Palmenaer 2015-03-27 21:57:37 +01:00
parent d2f9b4dc9d
commit 424af3e2cb
15 changed files with 106 additions and 29 deletions

View file

@ -1,8 +1,10 @@
from flask import Flask
from flask.ext.bootstrap import Bootstrap
from flask.ext.sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config.from_object('config.Configuration')
Bootstrap(app)
db = SQLAlchemy(app)

View file

@ -10,6 +10,7 @@ from app import app, db
from admin import admin
from login import login_manager
from models import *
from forms import *
from utils import *
from views import *

24
app/forms.py Normal file
View file

@ -0,0 +1,24 @@
from datetime import datetime, timedelta
from flask_wtf import Form
from wtforms import SelectField, DateTimeField, validators, SubmitField
from models import User, Location
__author__ = 'feliciaan'
class OrderForm(Form):
courrier_id = SelectField('Courrier', coerce=int)
location_id = SelectField('Location', coerce=int, validators=[validators.optional()])
starttime = DateTimeField('Starttime', default=datetime.now)
stoptime = DateTimeField('Stoptime')
submit_button = SubmitField('Submit Form')
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)

View file

@ -3,6 +3,7 @@ Flask-Admin==1.0.9
Flask-Login==0.2.11
Flask-SQLAlchemy==2.0
Flask-WTF==0.10.3
Flask-Bootstrap==3.3.2.1
Jinja2==2.7.2
MarkupSafe==0.23
SQLAlchemy==0.9.8

View file

@ -1,7 +1,7 @@
{% extends "layout.html" -%}
{% set active_page = "about" -%}
{% block content %}
{% block container %}
<h1>About</h1>
<p>This is an About page for FoodBot. Don't I look good? Oh stop, you're making me blush.</p>
{% endblock %}

View file

@ -1,6 +1,6 @@
{% extends "layout.html" -%}
{% block content %}
{% block container %}
<div class="jumbotron">
<h1>Unauthorized</h1>
<p>You're not authorized to look to this page!</p>

View file

@ -1,6 +1,6 @@
{% extends "layout.html" -%}
{% block content %}
{% block container %}
<div class="jumbotron">
<h1>Page Not Found</h1>
<p>What you were looking for is just not there.</p>

View file

@ -1,6 +1,6 @@
{% extends "layout.html" -%}
{% set active_page = "home" -%}
{% block content %}
{% block container %}
<div class="jumbotron">
<h2>Welcome to FoodBot</h2>
<h3>This is the home page for FoodBot</h3>

View file

@ -1,5 +1,5 @@
{% extends "home.html" %}
{% block content %}
{% block container %}
{{ super() }}
<div class="row">
<div class="col-md-4">

View file

@ -1,5 +1,8 @@
{% extends "bootstrap/base.html" %}
{% set navbar = [
('home', 'Home'),
('orders', 'Orders'),
('about', 'About'),
('stats', 'Stats'),
] -%}
@ -7,19 +10,15 @@
{% set navbar = navbar + [('admin.index', 'Admin')] -%}
{% endif -%}
{% set active_page = active_page|default('index') -%}
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>FoodBot</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
{% block title %}
FoodBot
{% endblock %}
{% block styles %}
{{ super() }}
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
</head>
<body>
{% endblock %}
{% block navbar %}
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
@ -50,13 +49,11 @@
</div><!--/.nav-collapse -->
</div>
</nav>
{% endblock %}
{% block content -%}
<div class="container">
{% block content %}
{% endblock %}
{% block container -%}
{%- endblock %}
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
</body>
</html>
{%- endblock %}

View file

@ -1,5 +1,7 @@
{% extends "layout.html" %}
{% block content %}
{% set active_page = "orders" -%}
{% block container %}
<div class="row">
<div class="col-md-12"><!-- Shitty html-->
<h3>Order {{ order.id }}</h3>

View file

@ -0,0 +1,9 @@
{% extends "layout.html" %}
{% set active_page = "orders" -%}
{% import "bootstrap/wtf.html" as wtf %}
{% block container %}
<div class="row">
{{ wtf.quick_form(form, action=url_for('order_create'), button_map={'submit_button': 'primary'}) }}
</div>
{% endblock %}

18
app/templates/orders.html Normal file
View file

@ -0,0 +1,18 @@
{% extends 'layout.html' %}
{% set active_page = "orders" -%}
{% block container %}
<div class="row">
<div class="col-md-7">
<h3>Open orders:</h3>
<ul>
{% for order in orders %}
<li><a href="{{ url_for('order', id=order.id) }}">{{ order.location.name }}-{{ order.stoptime }}</a></li>
{% endfor %}
</ul>
</div>
<div class="col-md-push-2">
<a class="btn btn-large btn-default" href="{{ url_for('order_create') }}">Create new order</a>
</div>
</div>
{% endblock %}

View file

@ -1,6 +1,6 @@
{% extends "layout.html" -%}
{% set active_page = "stats" -%}
{% block content %}
{% block container %}
<h1>Stats bruh</h1>
<p>TOP 4</p>
{% endblock %}

View file

@ -1,8 +1,9 @@
from flask import url_for, render_template, abort
from flask import url_for, render_template, abort, redirect, request
from flask.ext.login import current_user, login_required
from datetime import datetime
from app import app
from app import app, db
from forms import OrderForm
from models import Order
@ -10,7 +11,7 @@ from models import Order
@app.route('/')
def home():
if not current_user.is_anonymous():
orders = Order.query.filter(Order.stoptime > datetime.now()).all()
orders = Order.query.filter((Order.stoptime > datetime.now()) | (Order.stoptime == None)).all()
return render_template('home_loggedin.html', orders=orders)
return render_template('home.html')
@ -34,6 +35,28 @@ def order(id):
return render_template('order.html', order=order)
return abort(404)
@app.route('/order/create', methods=['GET', 'POST'])
@login_required
def order_create():
orderForm = OrderForm()
orderForm.populate()
if orderForm.validate_on_submit():
order = Order()
orderForm.populate_obj(order)
db.session.add(order)
db.session.commit()
print(order.id)
return redirect(url_for('home'))
return render_template('order_form.html', form=orderForm)
@app.route('/order')
@login_required
def orders():
orders = Order.query.filter((Order.stoptime > datetime.now()) | (Order.stoptime == None)).all()
return render_template('orders.html', orders=orders)
if app.debug: # add route information
@app.route('/routes')
@login_required