From c12a4956be11e09806abcf02ca7bc6ccfcf7d674 Mon Sep 17 00:00:00 2001 From: Thierry Carrez Date: Mon, 26 Nov 2018 13:33:55 +0100 Subject: [PATCH] Split up function colorizing non-colored tracks Make colorize() its own independent function and call it whenever tracks are added. Change-Id: Ieb0b9ce162faac42ec4aaeac24976c62d0b6077e --- ptgbot/db.py | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/ptgbot/db.py b/ptgbot/db.py index 924336d..aa2fb09 100644 --- a/ptgbot/db.py +++ b/ptgbot/db.py @@ -49,20 +49,8 @@ class PTGDataBase(): for time, track in bookings.items(): if track not in self.data['tracks']: self.data['tracks'].append(track) - self.data['colors'][track] = random.choice([ - '#596468', - '#9ea8ad', - '#b57506', - '#f8ac29', - '#5b731a', - '#9dc62d', - '#156489', - '#27a3dd', - '#2a6d3c', - '#3fa45b', - '#930a0a', - '#dc0d0e', - ]) + + self.colorize() def add_now(self, track, session): self.data['now'][track] = session @@ -78,6 +66,24 @@ class PTGDataBase(): self.data['colors'][track] = color self.save() + def colorize(self): + for track in self.data['tracks']: + if track not in self.data['colors']: + self.add_color(track, random.choice([ + '#596468', + '#9ea8ad', + '#b57506', + '#f8ac29', + '#5b731a', + '#9dc62d', + '#156489', + '#27a3dd', + '#2a6d3c', + '#3fa45b', + '#930a0a', + '#dc0d0e', + ])) + def get_track_room(self, track): # This simplified version returns the first room the track is # scheduled in for the day. If the event does not run on this @@ -112,6 +118,7 @@ class PTGDataBase(): for track in tracks: if track not in self.data['tracks']: self.data['tracks'].append(track) + self.colorize() self.save() def del_tracks(self, tracks):