Added orders form (simple bootstrap), using new bootstrap package
This commit is contained in:
parent
d2f9b4dc9d
commit
424af3e2cb
15 changed files with 106 additions and 29 deletions
|
@ -1,8 +1,10 @@
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
|
from flask.ext.bootstrap import Bootstrap
|
||||||
from flask.ext.sqlalchemy import SQLAlchemy
|
from flask.ext.sqlalchemy import SQLAlchemy
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config.from_object('config.Configuration')
|
app.config.from_object('config.Configuration')
|
||||||
|
Bootstrap(app)
|
||||||
|
|
||||||
db = SQLAlchemy(app)
|
db = SQLAlchemy(app)
|
||||||
|
|
|
@ -10,6 +10,7 @@ from app import app, db
|
||||||
from admin import admin
|
from admin import admin
|
||||||
from login import login_manager
|
from login import login_manager
|
||||||
from models import *
|
from models import *
|
||||||
|
from forms import *
|
||||||
from utils import *
|
from utils import *
|
||||||
from views import *
|
from views import *
|
||||||
|
|
||||||
|
|
24
app/forms.py
Normal file
24
app/forms.py
Normal 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)
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ Flask-Admin==1.0.9
|
||||||
Flask-Login==0.2.11
|
Flask-Login==0.2.11
|
||||||
Flask-SQLAlchemy==2.0
|
Flask-SQLAlchemy==2.0
|
||||||
Flask-WTF==0.10.3
|
Flask-WTF==0.10.3
|
||||||
|
Flask-Bootstrap==3.3.2.1
|
||||||
Jinja2==2.7.2
|
Jinja2==2.7.2
|
||||||
MarkupSafe==0.23
|
MarkupSafe==0.23
|
||||||
SQLAlchemy==0.9.8
|
SQLAlchemy==0.9.8
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{% extends "layout.html" -%}
|
{% extends "layout.html" -%}
|
||||||
{% set active_page = "about" -%}
|
{% set active_page = "about" -%}
|
||||||
|
|
||||||
{% block content %}
|
{% block container %}
|
||||||
<h1>About</h1>
|
<h1>About</h1>
|
||||||
<p>This is an About page for FoodBot. Don't I look good? Oh stop, you're making me blush.</p>
|
<p>This is an About page for FoodBot. Don't I look good? Oh stop, you're making me blush.</p>
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -1,6 +1,6 @@
|
||||||
{% extends "layout.html" -%}
|
{% extends "layout.html" -%}
|
||||||
|
|
||||||
{% block content %}
|
{% block container %}
|
||||||
<div class="jumbotron">
|
<div class="jumbotron">
|
||||||
<h1>Unauthorized</h1>
|
<h1>Unauthorized</h1>
|
||||||
<p>You're not authorized to look to this page!</p>
|
<p>You're not authorized to look to this page!</p>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{% extends "layout.html" -%}
|
{% extends "layout.html" -%}
|
||||||
|
|
||||||
{% block content %}
|
{% block container %}
|
||||||
<div class="jumbotron">
|
<div class="jumbotron">
|
||||||
<h1>Page Not Found</h1>
|
<h1>Page Not Found</h1>
|
||||||
<p>What you were looking for is just not there.</p>
|
<p>What you were looking for is just not there.</p>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{% extends "layout.html" -%}
|
{% extends "layout.html" -%}
|
||||||
{% set active_page = "home" -%}
|
{% set active_page = "home" -%}
|
||||||
{% block content %}
|
{% block container %}
|
||||||
<div class="jumbotron">
|
<div class="jumbotron">
|
||||||
<h2>Welcome to FoodBot</h2>
|
<h2>Welcome to FoodBot</h2>
|
||||||
<h3>This is the home page for FoodBot</h3>
|
<h3>This is the home page for FoodBot</h3>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{% extends "home.html" %}
|
{% extends "home.html" %}
|
||||||
{% block content %}
|
{% block container %}
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
|
{% extends "bootstrap/base.html" %}
|
||||||
|
|
||||||
{% set navbar = [
|
{% set navbar = [
|
||||||
('home', 'Home'),
|
('home', 'Home'),
|
||||||
|
('orders', 'Orders'),
|
||||||
('about', 'About'),
|
('about', 'About'),
|
||||||
('stats', 'Stats'),
|
('stats', 'Stats'),
|
||||||
] -%}
|
] -%}
|
||||||
|
@ -7,19 +10,15 @@
|
||||||
{% set navbar = navbar + [('admin.index', 'Admin')] -%}
|
{% set navbar = navbar + [('admin.index', 'Admin')] -%}
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
{% set active_page = active_page|default('index') -%}
|
{% 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') }}">
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
|
||||||
|
{% endblock %}
|
||||||
</head>
|
{% block navbar %}
|
||||||
<body>
|
|
||||||
<nav class="navbar navbar-default navbar-fixed-top">
|
<nav class="navbar navbar-default navbar-fixed-top">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="navbar-header">
|
<div class="navbar-header">
|
||||||
|
@ -50,13 +49,11 @@
|
||||||
</div><!--/.nav-collapse -->
|
</div><!--/.nav-collapse -->
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content -%}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{% block content %}
|
{% block container -%}
|
||||||
{% endblock %}
|
{%- endblock %}
|
||||||
</div>
|
</div>
|
||||||
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
|
{%- endblock %}
|
||||||
<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>
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
{% extends "layout.html" %}
|
{% extends "layout.html" %}
|
||||||
{% block content %}
|
{% set active_page = "orders" -%}
|
||||||
|
|
||||||
|
{% block container %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12"><!-- Shitty html-->
|
<div class="col-md-12"><!-- Shitty html-->
|
||||||
<h3>Order {{ order.id }}</h3>
|
<h3>Order {{ order.id }}</h3>
|
||||||
|
|
9
app/templates/order_form.html
Normal file
9
app/templates/order_form.html
Normal 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
18
app/templates/orders.html
Normal 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 %}
|
|
@ -1,6 +1,6 @@
|
||||||
{% extends "layout.html" -%}
|
{% extends "layout.html" -%}
|
||||||
{% set active_page = "stats" -%}
|
{% set active_page = "stats" -%}
|
||||||
{% block content %}
|
{% block container %}
|
||||||
<h1>Stats bruh</h1>
|
<h1>Stats bruh</h1>
|
||||||
<p>TOP 4</p>
|
<p>TOP 4</p>
|
||||||
{% endblock %}
|
{% endblock %}
|
29
app/views.py
29
app/views.py
|
@ -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 flask.ext.login import current_user, login_required
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from app import app
|
from app import app, db
|
||||||
|
from forms import OrderForm
|
||||||
from models import Order
|
from models import Order
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,7 +11,7 @@ from models import Order
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def home():
|
def home():
|
||||||
if not current_user.is_anonymous():
|
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_loggedin.html', orders=orders)
|
||||||
return render_template('home.html')
|
return render_template('home.html')
|
||||||
|
|
||||||
|
@ -34,6 +35,28 @@ def order(id):
|
||||||
return render_template('order.html', order=order)
|
return render_template('order.html', order=order)
|
||||||
return abort(404)
|
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
|
if app.debug: # add route information
|
||||||
@app.route('/routes')
|
@app.route('/routes')
|
||||||
@login_required
|
@login_required
|
||||||
|
|
Loading…
Reference in a new issue