From bc4d3af9b9158fa4eec908e84ae2c3559106a19e Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Wed, 1 Mar 2017 12:40:58 +0100 Subject: [PATCH] color codes are visible in the calendar --- smash/web/models.py | 21 +++++++++++++++++++++ smash/web/templates/appointments/index.html | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/smash/web/models.py b/smash/web/models.py index dac9e217..fef1d4a2 100644 --- a/smash/web/models.py +++ b/smash/web/models.py @@ -253,6 +253,10 @@ class Room (models.Model): class AppointmentType (models.Model): + + + DEFAULT_COLOR = '#cfc600' + required_equipment = models.ManyToManyField(Item, verbose_name='Required equipment', blank = True @@ -266,6 +270,14 @@ class AppointmentType (models.Model): default_duration = models.IntegerField( verbose_name='Default duration (in minutes)' ) + calendar_color_priority = models.IntegerField( + verbose_name='Calendar color priority', + default=1 + ) + calendar_color = models.CharField(max_length=2000, + verbose_name='Calendar color', + default=DEFAULT_COLOR + ) rest_time = models.IntegerField( verbose_name='Suggested rest time' ) @@ -464,6 +476,15 @@ class Appointment(models.Model): else: return self.datetime_when + timedelta(minutes=max(self.length, 15)) + def color(self): + result = AppointmentType.DEFAULT_COLOR + priority = 1000000 + for type in self.appointment_types.all(): + if type.calendar_color_priority<priority: + priority=type.calendar_color_priority + result = type.calendar_color + return result + def title(self): if self.visit.subject.screening_number=="---": return self.comment diff --git a/smash/web/templates/appointments/index.html b/smash/web/templates/appointments/index.html index bd829b46..23c2de5c 100644 --- a/smash/web/templates/appointments/index.html +++ b/smash/web/templates/appointments/index.html @@ -140,7 +140,7 @@ title: '{{ approach.title }}', start: '{{ approach.datetime_when | date:"c" }}', end: '{{ approach.datetime_until | date:"c" }}', - color: '#cfc600', + color: '{{ approach.color }}', subject_id: '{{ approach.visit.subject.id }}', id: '{{ approach.id }}' }, -- GitLab