From 4de65752ecfa82bbce09125f9a516128d1490b33 Mon Sep 17 00:00:00 2001 From: Feliciaan De Palmenaer Date: Wed, 24 Jun 2015 22:10:26 +0200 Subject: [PATCH 1/2] 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 2/2] 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 %}
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 %}