From 3d50650d8eef474ac0db299dab888bc1dfb4f30f Mon Sep 17 00:00:00 2001 From: Feliciaan De Palmenaer Date: Tue, 9 Jun 2015 22:24:48 +0200 Subject: [PATCH 1/6] Add fancy debugtoolbar when debugging --- app/app.py | 3 +++ requirements.txt | 1 + 2 files changed, 4 insertions(+) diff --git a/app/app.py b/app/app.py index 2875171..4a502f6 100644 --- a/app/app.py +++ b/app/app.py @@ -3,6 +3,7 @@ from logging.handlers import TimedRotatingFileHandler from flask import Flask from flask.ext.bootstrap import Bootstrap, StaticCDN from flask.ext.sqlalchemy import SQLAlchemy +from flask_debugtoolbar import DebugToolbarExtension from airbrake import Airbrake, AirbrakeHandler @@ -16,6 +17,8 @@ app.extensions['bootstrap']['cdns']['bootstrap'] = StaticCDN() db = SQLAlchemy(app) +toolbar = DebugToolbarExtension(app) + class PrefixFix(object): def __init__(self, app, script_name): diff --git a/requirements.txt b/requirements.txt index ed260b9..021899d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ Flask==0.10.1 Flask-Admin==1.1.0 Flask-Bootstrap==3.3.4.1 +Flask-DebugToolbar==0.10.0 Flask-Login==0.2.11 Flask-Migrate==1.4.0 Flask-OAuthlib==0.9.1 From f0a0d4f00106837ae0378b0ea1012374edcd3267 Mon Sep 17 00:00:00 2001 From: Feliciaan De Palmenaer Date: Thu, 18 Jun 2015 14:39:42 +0200 Subject: [PATCH 2/6] Show order stoptime --- app/templates/order_edit.html | 2 +- app/templates/orders.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/templates/order_edit.html b/app/templates/order_edit.html index 84a68d6..299ba11 100644 --- a/app/templates/order_edit.html +++ b/app/templates/order_edit.html @@ -35,7 +35,7 @@ {{ util.render_form_field_errors(form.starttime) }} {% endif %} -
+
{{ form.stoptime.label(class='control-label') }}
{{ form.stoptime(class='form-control datetimepicker') }} diff --git a/app/templates/orders.html b/app/templates/orders.html index 9757ca0..ed5cf63 100644 --- a/app/templates/orders.html +++ b/app/templates/orders.html @@ -50,7 +50,7 @@ {{ util.render_form_field_errors(form.starttime) }}
{% endif %} -
+
{{ form.stoptime.label(class='control-label') }}
{{ form.stoptime(class='form-control datetimepicker') }} From a689dcfa1a7e3a73dbc6d68d0e624863c88868a5 Mon Sep 17 00:00:00 2001 From: Feliciaan De Palmenaer Date: Fri, 19 Jun 2015 20:44:58 +0200 Subject: [PATCH 3/6] Fixing a little bug --- app/templates/home.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/home.html b/app/templates/home.html index d5826a8..5b87aa7 100644 --- a/app/templates/home.html +++ b/app/templates/home.html @@ -27,7 +27,7 @@ {%- endif %}
- {% if orders|count > 0 -%} + {% if recently_closed|count > 0 -%}

Recently closed orders:

{% for order in recently_closed %} {{ util.render_order(order) }} From 4de65752ecfa82bbce09125f9a516128d1490b33 Mon Sep 17 00:00:00 2001 From: Feliciaan De Palmenaer Date: Wed, 24 Jun 2015 22:10:26 +0200 Subject: [PATCH 4/6] Extras --- app/forms.py | 1 + app/migrations/versions/4e94c0b08ed_.py | 26 +++++++++++++++++++++++++ app/models.py | 11 +++++++++-- app/static/css/main.css | 4 ++++ app/templates/order.html | 19 ++++++++++++++++-- 5 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 app/migrations/versions/4e94c0b08ed_.py diff --git a/app/forms.py b/app/forms.py index 48ee503..ca6a047 100644 --- a/app/forms.py +++ b/app/forms.py @@ -30,6 +30,7 @@ class OrderForm(Form): class OrderItemForm(Form): product_id = SelectField('Item', coerce=int) + extra = StringField('Extra') submit_button = SubmitField('Submit') def populate(self, location): diff --git a/app/migrations/versions/4e94c0b08ed_.py b/app/migrations/versions/4e94c0b08ed_.py new file mode 100644 index 0000000..550e057 --- /dev/null +++ b/app/migrations/versions/4e94c0b08ed_.py @@ -0,0 +1,26 @@ +"""Add extra message + +Revision ID: 4e94c0b08ed +Revises: 42709384216 +Create Date: 2015-06-24 21:42:41.466973 + +""" + +# revision identifiers, used by Alembic. +revision = '4e94c0b08ed' +down_revision = '42709384216' + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import mysql + +def upgrade(): + ### commands auto generated by Alembic - please adjust! ### + op.add_column('order_item', sa.Column('extra', sa.String(length=254), nullable=True)) + ### end Alembic commands ### + + +def downgrade(): + ### commands auto generated by Alembic - please adjust! ### + op.drop_column('order_item', 'extra') + ### end Alembic commands ### diff --git a/app/models.py b/app/models.py index b4b8d85..e4cb847 100644 --- a/app/models.py +++ b/app/models.py @@ -102,12 +102,18 @@ class Order(db.Model): user["paid"] = user.get("paid", True) and item.paid user["products"] = user.get("products", []) + [item.product] group[item.get_name()] = user + return group def group_by_product(self): - group = defaultdict(int) + group = dict() for item in self.items: - group[item.product.name] += 1 + product = group.get(item.product.name, dict()) + product['count'] = product.get("count", 0) + 1 + if item.extra: + product["extras"] = product.get("extras", []) + [item.extra] + group[item.product.name] = product + return group def can_close(self, user_id): @@ -128,6 +134,7 @@ class OrderItem(db.Model): order_id = db.Column(db.Integer, db.ForeignKey('order.id'), nullable=False) product_id = db.Column(db.Integer, db.ForeignKey('product.id')) paid = db.Column(db.Boolean, default=False) + extra = db.Column(db.String(254), nullable=True) name = db.Column(db.String(120)) def configure(self, user, order, product): diff --git a/app/static/css/main.css b/app/static/css/main.css index 34bf47a..451f630 100644 --- a/app/static/css/main.css +++ b/app/static/css/main.css @@ -18,3 +18,7 @@ body { .full-width { width: 100%; } + +.product .extras { + padding-left: 20px; +} \ No newline at end of file diff --git a/app/templates/order.html b/app/templates/order.html index ca7f1dc..0c1842f 100644 --- a/app/templates/order.html +++ b/app/templates/order.html @@ -38,6 +38,11 @@ {{ form.product_id(class='form-control select') }} {{ util.render_form_field_errors(form.product_id) }}
+
+ {{ form.extra.label(class='control-label') }}
+ {{ form.extra(class='form-control', placeholder='Fill in extras, when applicable') }} + {{ util.render_form_field_errors(form.extra) }} +
{% if current_user.is_anonymous() %}
{{ form.name.label(class='control-label') }} @@ -57,7 +62,7 @@

Items

- {% if courier_or_admin %}{% endif %} + {% if courier_or_admin %}{% endif %} {% for item in order.items -%} @@ -65,6 +70,7 @@ + {% if courier_or_admin %}{% endif %} @@ -75,7 +81,16 @@

Ordered products:

{% for key, value in order.group_by_product().items() -%} - {{ key }} - {{ value }}
+
+ {{ key }}: {{ value["count"] }} + {% if value["extras"] -%} +
+ {% for extra in value["extras"] -%} +
{{ extra }}
+ {% endfor %} +
+ {%- endif %} +
{%- endfor %}
From 2497686abef35e1aac5c91e73ea594fcfd252a63 Mon Sep 17 00:00:00 2001 From: Feliciaan De Palmenaer Date: Wed, 24 Jun 2015 22:24:21 +0200 Subject: [PATCH 5/6] Better table Fixes #58 --- app/templates/order.html | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/templates/order.html b/app/templates/order.html index 0c1842f..974a0c2 100644 --- a/app/templates/order.html +++ b/app/templates/order.html @@ -62,15 +62,14 @@

Items

NameItemPricePaid?Delete
NameItemPriceExtraPaid?Delete
{{ item.get_name() }} {{ item.product.name }} {{ item.product.price|euro }}{{ item.extra if item.extra }}{% if not item.paid %} Pay {% else %} {% endif %}{% if item.can_delete(order.id, current_user.id, session.get('anon_name', '')) -%}{%- endif %}
- {% if courier_or_admin %}{% endif %} + {% if courier_or_admin %}{% endif %} {% for item in order.items -%} - + - {% if courier_or_admin %}{% endif %} From 47d4300e83577ac7d9993d21ee9a92be24e47c42 Mon Sep 17 00:00:00 2001 From: Stijn Seghers Date: Tue, 18 Aug 2015 20:47:49 +0200 Subject: [PATCH 6/6] Product and paid status of an order can't be NULL --- app/models.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models.py b/app/models.py index e4cb847..9bcbafb 100644 --- a/app/models.py +++ b/app/models.py @@ -132,8 +132,9 @@ class OrderItem(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) order_id = db.Column(db.Integer, db.ForeignKey('order.id'), nullable=False) - product_id = db.Column(db.Integer, db.ForeignKey('product.id')) - paid = db.Column(db.Boolean, default=False) + product_id = db.Column(db.Integer, db.ForeignKey('product.id'), + nullable=False) + paid = db.Column(db.Boolean, default=False, nullable=False) extra = db.Column(db.String(254), nullable=True) name = db.Column(db.String(120))
NameItemPriceExtraPaid?Delete
NameItemPricePaid?Delete
{{ item.get_name() }}{{ item.product.name }}{{ item.product.name }}{{ "*" if item.extra }} {{ item.product.price|euro }}{{ item.extra if item.extra }}{% if not item.paid %} Pay {% else %} {% endif %}{% if item.can_delete(order.id, current_user.id, session.get('anon_name', '')) -%}{%- endif %}