Předpokládám, že bude ještě jeden patch, který mění HTML.

7. března 2019 14:47:03 SEČ, Jaroslav Klapalek <klapajar@fel.cvut.cz> napsal:
Required to run on the server database before using this patch:
```
alter table flavors add ord integer not null default 999;
update flavors set ord=1 where name='cappuccino';
update flavors set ord=2 where name='espresso';
update flavors set ord=3 where name='espresso lungo';
update flavors set ord=4 where name='latte macchiato';
```

This patch slightly changes structure of a `flavors` table. It adds
another column called `ord`, which is used for ordering of coffee
flavors / beverages on the graphs (to maintain the same color scheme).

Scripts `app.py` and `coffee_db.py` are modified to work with this
change.
Patch pro přidání dalších nápojů, teď obsahuje i malé Mate.
app.py | 4 ++--
coffee_db.py | 3 ++-
coffee_db.sql | 13 ++++++++-----
3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/app.py b/app.py
index ef9075b..62f79b8 100644
--- a/app.py
+++ b/app.py
@@ -53,7 +53,7 @@ def user():
uid = session["uid"]
return render_template('user.html',
name=db.get_name(uid),
- flavors=db.flavors(),
+ flavors=[_name for (_name, _ord) in db.flavors()],
count=db.coffee_count(uid, 0),
stamp=time.time()
)
@@ -115,7 +115,7 @@ def coffee_graph_history():
fig = plt.figure(figsize=(4, 3))
ax = fig.add_subplot(111)

- list_flavor = sorted(db.flavors())
+ list_flavor = [_name for (_name, _ord) in sorted(db.flavors(), key=lambda x: x[1])]
l = [{} for i in range(len(list_flavor))]
for ll in l:
for d in unix_days:
diff --git a/coffee_db.py b/coffee_db.py
index b7206fe..348113a 100644
--- a/coffee_db.py
+++ b/coffee_db.py
@@ -56,7 +56,7 @@ def add_coffee(uid, flavor, time=None):

def flavors():
conn, c = open_db()
- res = [row for row, in c.execute("select distinct name from flavors")]
+ res = list(c.execute("select distinct name, ord from flavors"))
close_db(conn)
return res

@@ -91,6 +91,7 @@ def coffee_flavors(uid=None, days=0, start=0):
left join (select * from coffees
"""+query+""") c
on f.name=c.flavor group by f.name
+ order by f.ord asc
""", variables))

close_db(conn)
diff --git a/coffee_db.sql b/coffee_db.sql
index 03a7e7c..acb42a2 100644
--- a/coffee_db.sql
+++ b/coffee_db.sql
@@ -6,14 +6,17 @@ create table if not exists users (
);

create table if not exists flavors (
- name varchar(255) primary key not null
+ name varchar(255) primary key not null,
+ ord integer not null default 999
);

insert or ignore into flavors values
- ("espresso"),
- ("espresso lungo"),
- ("cappuccino"),
- ("latte macchiato")
+ ("espresso", 2),
+ ("espresso lungo", 3),
+ ("cappuccino", 1),
+ ("latte macchiato", 4),
+ ("Club-Mate 0,5 l", 5),
+ ("Club-Mate 0,33 l", 6)
;

create table if not exists coffees (

--
Odesláno aplikací K-9 Mail ze systému Android. Omluvte prosím moji stručnost.