Split up function colorizing non-colored tracks

Make colorize() its own independent function and call it
whenever tracks are added.

Change-Id: Ieb0b9ce162faac42ec4aaeac24976c62d0b6077e
This commit is contained in:
Thierry Carrez 2018-11-26 13:33:55 +01:00
parent 21d77e09f8
commit c12a4956be
1 changed files with 21 additions and 14 deletions

View File

@ -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):