From 335cecee8af872957245e87df977a635d6e7d688 Mon Sep 17 00:00:00 2001 From: Titouan Vervack Date: Thu, 8 Mar 2018 23:22:07 +0100 Subject: [PATCH 01/10] Ignore compiled python files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 5e55b1a..42fa83f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Byte-compiled / optimized / DLL files __pycache__/ +*.pyc # C extensions *.so From 0ff7dca664f037262a431851442ee6112545317e Mon Sep 17 00:00:00 2001 From: Titouan Vervack Date: Thu, 8 Mar 2018 23:22:32 +0100 Subject: [PATCH 02/10] Set utf-8 encoding on required files --- app/database/add_oceans_garden.py | 2 ++ app/database/add_simpizza.py | 2 ++ app/models.py | 2 ++ app/utils.py | 2 ++ 4 files changed, 8 insertions(+) diff --git a/app/database/add_oceans_garden.py b/app/database/add_oceans_garden.py index fcc063f..51a4d00 100644 --- a/app/database/add_oceans_garden.py +++ b/app/database/add_oceans_garden.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + from models import Location, Product from app import db from itertools import product diff --git a/app/database/add_simpizza.py b/app/database/add_simpizza.py index 59bfb2e..4414034 100644 --- a/app/database/add_simpizza.py +++ b/app/database/add_simpizza.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + from models import Location, Product from app import db diff --git a/app/models.py b/app/models.py index 2507e82..5bec32f 100644 --- a/app/models.py +++ b/app/models.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + from datetime import datetime from collections import defaultdict diff --git a/app/utils.py b/app/utils.py index 9742ff9..e17f506 100644 --- a/app/utils.py +++ b/app/utils.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + from datetime import datetime from flask import render_template From 8567d17babf22f6f6dd87db6b2ef1bc88592acdc Mon Sep 17 00:00:00 2001 From: Titouan Vervack Date: Thu, 8 Mar 2018 23:22:51 +0100 Subject: [PATCH 03/10] Use raw_input instead of input --- app/database/create_database.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/database/create_database.py b/app/database/create_database.py index e8d238f..6a4ce1e 100644 --- a/app/database/create_database.py +++ b/app/database/create_database.py @@ -14,7 +14,7 @@ def commit(): def check_if_overwrite(): - answer = input("Do you want to overwrite the previous database? (y/N) ") + answer = raw_input("Do you want to overwrite the previous database? (y/N) ") return answer in yes @@ -25,9 +25,9 @@ def add_all(): def recreate_from_scratch(): - confirmation = "Are you very very sure? (Will delete previous entry's!) (y/N) " + confirmation = "Are you very very sure? (Will delete previous entries!) (y/N) " check = "I acknowledge any repercussions!" - if input(confirmation) in yes and input("Type: '{}' ".format(check)) == check: + if raw_input(confirmation) in yes and raw_input("Type: '{}' ".format(check)) == check: print("Resetting the database!") db.drop_all() db.create_all() @@ -40,9 +40,9 @@ def add_to_current(): def add_numbers(): return " ".join(["{}({}), ".format(loc, i) for i, loc in enumerate(available)]).rstrip(", ") - while input("Do you still want to add something? (Y/n) ") not in no: + while raw_input("Do you still want to add something? (Y/n) ") not in no: print("What do you want to add? (Use numbers, or A for all, or C for chancel) ") - answer = input("Available: {} : ".format(add_numbers())) + answer = raw_input("Available: {} : ".format(add_numbers())) if answer == "A": add_all() available = [] From 8b1b7086954d9cfe16e166f586fca36e5722d153 Mon Sep 17 00:00:00 2001 From: Titouan Vervack Date: Thu, 8 Mar 2018 23:23:02 +0100 Subject: [PATCH 04/10] Added install instructions --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 2455575..b277398 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,12 @@ Haldis is your friendly neighbourhood servant. He exists so lazy fucks like you Start an order and let people add items with a simple mouse-click! No more calculating prices and making lists! Be lazier today! + +Local hosting steps +=================== +1. Run `pip install -r requirements.txt` +2. Copy `config.example.py` to `config.py` and fill in random values for the `ZEUS_KEY` and `ZEUS_SECRET` +3. Copy the python files from `database/` to `app/` (yes, it's sad, I know) +4. Run `python database.py` in `app/` +5. Run `rm -f add_admins.pyc? add_oceans_garden.pyc? add_simpizza.pyc? create_database.pyc?` in `app/` +6. Run `python haldis.py runserver` From 628c5e55c5861ce65810a2df104203cd343e81c0 Mon Sep 17 00:00:00 2001 From: Titouan Vervack Date: Thu, 8 Mar 2018 23:23:40 +0100 Subject: [PATCH 05/10] Added total nr of orders to order.html --- app/templates/order.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/order.html b/app/templates/order.html index 974a0c2..a0064b2 100644 --- a/app/templates/order.html +++ b/app/templates/order.html @@ -78,7 +78,7 @@
-

Ordered products:

+

Ordered products: {% len(order.items) %}

{% for key, value in order.group_by_product().items() -%}
{{ key }}: {{ value["count"] }} From a5a924d5ea0fc73e1f14e390ccf7c6af84395d2f Mon Sep 17 00:00:00 2001 From: Titouan Vervack Date: Fri, 9 Mar 2018 00:58:53 +0100 Subject: [PATCH 06/10] Ignore vscode configs --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 42fa83f..ed4e28e 100644 --- a/.gitignore +++ b/.gitignore @@ -54,6 +54,7 @@ target/ # PyCharm .idea/ +.vscode/ # ConfigFile app/config.py From f9b48969b2dd912432073819b9bd764b62f94c2f Mon Sep 17 00:00:00 2001 From: Titouan Vervack Date: Fri, 9 Mar 2018 00:59:14 +0100 Subject: [PATCH 07/10] Oops, python3 --- app/database/create_database.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/database/create_database.py b/app/database/create_database.py index 6a4ce1e..5c3033e 100644 --- a/app/database/create_database.py +++ b/app/database/create_database.py @@ -14,7 +14,7 @@ def commit(): def check_if_overwrite(): - answer = raw_input("Do you want to overwrite the previous database? (y/N) ") + answer = input("Do you want to overwrite the previous database? (y/N) ") return answer in yes @@ -27,7 +27,7 @@ def add_all(): def recreate_from_scratch(): confirmation = "Are you very very sure? (Will delete previous entries!) (y/N) " check = "I acknowledge any repercussions!" - if raw_input(confirmation) in yes and raw_input("Type: '{}' ".format(check)) == check: + if input(confirmation) in yes and input("Type: '{}' ".format(check)) == check: print("Resetting the database!") db.drop_all() db.create_all() @@ -40,9 +40,9 @@ def add_to_current(): def add_numbers(): return " ".join(["{}({}), ".format(loc, i) for i, loc in enumerate(available)]).rstrip(", ") - while raw_input("Do you still want to add something? (Y/n) ") not in no: + while input("Do you still want to add something? (Y/n) ") not in no: print("What do you want to add? (Use numbers, or A for all, or C for chancel) ") - answer = raw_input("Available: {} : ".format(add_numbers())) + answer = input("Available: {} : ".format(add_numbers())) if answer == "A": add_all() available = [] From 2e3ef91ec3629d4c62fc6286442a3b402064ada6 Mon Sep 17 00:00:00 2001 From: Titouan Vervack Date: Fri, 9 Mar 2018 00:59:33 +0100 Subject: [PATCH 08/10] Count and display total # of orders --- app/models.py | 6 ++++++ app/templates/order.html | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models.py b/app/models.py index 5bec32f..9db3526 100644 --- a/app/models.py +++ b/app/models.py @@ -110,6 +110,12 @@ class Order(db.Model): return group + def len(self): + size = 0 + for _ in self.items: + size = size + 1 + return size + def group_by_product(self): group = dict() for item in self.items: diff --git a/app/templates/order.html b/app/templates/order.html index a0064b2..4ee0619 100644 --- a/app/templates/order.html +++ b/app/templates/order.html @@ -78,7 +78,7 @@
-

Ordered products: {% len(order.items) %}

+

Ordered products: {{ order.len() }}

{% for key, value in order.group_by_product().items() -%}
{{ key }}: {{ value["count"] }} From a911f6ef8883802d8cbb8be23ca99713d4340306 Mon Sep 17 00:00:00 2001 From: Titouan Vervack Date: Fri, 9 Mar 2018 01:02:35 +0100 Subject: [PATCH 09/10] Update install instructions --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b277398..15b44b5 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,10 @@ Be lazier today! Local hosting steps =================== +0. This is a Python 3 project so make sure to use python 3 and pip3 everywhere 1. Run `pip install -r requirements.txt` -2. Copy `config.example.py` to `config.py` and fill in random values for the `ZEUS_KEY` and `ZEUS_SECRET` +2. Copy `config.example.py` to `config.py` and find out some valid values for `ZEUS_KEY` and `ZEUS_SECRET` (try asking an admin) 3. Copy the python files from `database/` to `app/` (yes, it's sad, I know) -4. Run `python database.py` in `app/` -5. Run `rm -f add_admins.pyc? add_oceans_garden.pyc? add_simpizza.pyc? create_database.pyc?` in `app/` +4. Run `python database.py` in `app/` (if you want to fill the DB with sample data be sure to answer `Y` to `Do you still want to add something?`) +5. Run `rm -f add_admins.py* add_oceans_garden.py* add_simpizza.py* create_database.py*` in `app/` 6. Run `python haldis.py runserver` From b611fe5961945304e4160366963bdcaa2663d5f1 Mon Sep 17 00:00:00 2001 From: Titouan Vervack Date: Sat, 10 Mar 2018 00:50:02 +0100 Subject: [PATCH 10/10] Removed UTF-8 annotations, better count --- app/database/add_oceans_garden.py | 2 -- app/database/add_simpizza.py | 2 -- app/models.py | 8 -------- app/templates/order.html | 2 +- app/utils.py | 2 -- 5 files changed, 1 insertion(+), 15 deletions(-) diff --git a/app/database/add_oceans_garden.py b/app/database/add_oceans_garden.py index 51a4d00..fcc063f 100644 --- a/app/database/add_oceans_garden.py +++ b/app/database/add_oceans_garden.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from models import Location, Product from app import db from itertools import product diff --git a/app/database/add_simpizza.py b/app/database/add_simpizza.py index 4414034..59bfb2e 100644 --- a/app/database/add_simpizza.py +++ b/app/database/add_simpizza.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from models import Location, Product from app import db diff --git a/app/models.py b/app/models.py index 9db3526..2507e82 100644 --- a/app/models.py +++ b/app/models.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from datetime import datetime from collections import defaultdict @@ -110,12 +108,6 @@ class Order(db.Model): return group - def len(self): - size = 0 - for _ in self.items: - size = size + 1 - return size - def group_by_product(self): group = dict() for item in self.items: diff --git a/app/templates/order.html b/app/templates/order.html index 4ee0619..fe4db94 100644 --- a/app/templates/order.html +++ b/app/templates/order.html @@ -78,7 +78,7 @@
-

Ordered products: {{ order.len() }}

+

Ordered products: {{ order.items.count() }}

{% for key, value in order.group_by_product().items() -%}
{{ key }}: {{ value["count"] }} diff --git a/app/utils.py b/app/utils.py index e17f506..9742ff9 100644 --- a/app/utils.py +++ b/app/utils.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from datetime import datetime from flask import render_template