diff --git a/smash/web/migrations/0025_configurationitem_calendar_items.py b/smash/web/migrations/0025_configurationitem_calendar_items.py new file mode 100644 index 0000000000000000000000000000000000000000..a5c6a47127bfd6bb95daf65b8e5fb3cd07e92db5 --- /dev/null +++ b/smash/web/migrations/0025_configurationitem_calendar_items.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2017-04-04 09:43 +from __future__ import unicode_literals + +from django.db import migrations + +from web.models.constants import CANCELLED_APPOINTMENT_COLOR_CONFIGURATION_TYPE, \ + NO_SHOW_APPOINTMENT_COLOR_CONFIGURATION_TYPE + + +def configuration_item_color_fields(apps, schema_editor): + # We can't import the ConfigurationItem model directly as it may be a newer + # version than this migration expects. We use the historical version. + ConfigurationItem = apps.get_model("web", "ConfigurationItem") + cancelled_appointment_color = ConfigurationItem.objects.create() + cancelled_appointment_color.type = CANCELLED_APPOINTMENT_COLOR_CONFIGURATION_TYPE + cancelled_appointment_color.value = "#b7babf" + cancelled_appointment_color.name = "Color for cancelled appointments" + cancelled_appointment_color.save() + + cancelled_appointment_color = ConfigurationItem.objects.create() + cancelled_appointment_color.type = NO_SHOW_APPOINTMENT_COLOR_CONFIGURATION_TYPE + cancelled_appointment_color.value = "#ff0000" + cancelled_appointment_color.name = "Color for NO SHOW appointments" + cancelled_appointment_color.save() + + +class Migration(migrations.Migration): + dependencies = [ + ('web', '0024_configurationitem'), + ] + + operations = [ + migrations.RunPython(configuration_item_color_fields), + ] diff --git a/smash/web/migrations/0026_location_color.py b/smash/web/migrations/0026_location_color.py new file mode 100644 index 0000000000000000000000000000000000000000..13ee7979d3cdc27c5ba203ae212ec3ceacbbdc80 --- /dev/null +++ b/smash/web/migrations/0026_location_color.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2017-04-04 13:03 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('web', '0025_configurationitem_calendar_items'), + ] + + operations = [ + migrations.AddField( + model_name='location', + name='color', + field=models.CharField(blank=True, default=b'', max_length=20), + ), + ] diff --git a/smash/web/migrations/0027_auto_20170404_1505.py b/smash/web/migrations/0027_auto_20170404_1505.py new file mode 100644 index 0000000000000000000000000000000000000000..01cd2610e01647f7d4d308f4ea4bd5887e4bf1b1 --- /dev/null +++ b/smash/web/migrations/0027_auto_20170404_1505.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2017-04-04 13:05 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('web', '0026_location_color'), + ] + + operations = [ + migrations.AlterField( + model_name='location', + name='color', + field=models.CharField(blank=True, default=b'', max_length=20, verbose_name=b'Calendar appointment color'), + ), + ] diff --git a/smash/web/migrations/0028_location_color_of_flying_team.py b/smash/web/migrations/0028_location_color_of_flying_team.py new file mode 100644 index 0000000000000000000000000000000000000000..4522720616ab0bf33e492245d9fb9327e5af9bd6 --- /dev/null +++ b/smash/web/migrations/0028_location_color_of_flying_team.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2017-04-04 09:43 +from __future__ import unicode_literals + +from django.db import migrations + + +def configuration_item_color_fields(apps, schema_editor): + # We can't import the Location model directly as it may be a newer + # version than this migration expects. We use the historical version. + Location = apps.get_model("web", "Location") + locations = Location.objects.filter(name="Flying Team") + for location in locations: + location.color = "#FF8000" + + +class Migration(migrations.Migration): + dependencies = [ + ('web', '0027_auto_20170404_1505'), + ] + + operations = [ + migrations.RunPython(configuration_item_color_fields), + ] diff --git a/smash/web/models/__init__.py b/smash/web/models/__init__.py index abc2f3e1918ff632b6b498798ddd362dd3296bd9..a2dc22415ab64d1292bb53ec1fbcdc4262fbbeaf 100644 --- a/smash/web/models/__init__.py +++ b/smash/web/models/__init__.py @@ -5,6 +5,7 @@ import datetime from django.contrib.auth.models import User +from configuration_item import ConfigurationItem from flying_team import FlyingTeam from location import Location from room import Room @@ -18,7 +19,6 @@ from item import Item from language import Language from subject import Subject from contact_attempt import ContactAttempt -from configuration_item import ConfigurationItem def get_current_year(): diff --git a/smash/web/models/appointment.py b/smash/web/models/appointment.py index 59128c6e42d0b4d4e23253729bb31cc13d0da1b0..6f6e545b59d9a502f42cfeac398177f73fefbb48 100644 --- a/smash/web/models/appointment.py +++ b/smash/web/models/appointment.py @@ -3,8 +3,10 @@ import datetime from django.db import models -from constants import APPOINTMENT_TYPE_DEFAULT_COLOR, APPOINTMENT_TYPE_DEFAULT_FONT_COLOR +from constants import APPOINTMENT_TYPE_DEFAULT_COLOR, APPOINTMENT_TYPE_DEFAULT_FONT_COLOR, \ + CANCELLED_APPOINTMENT_COLOR_CONFIGURATION_TYPE, NO_SHOW_APPOINTMENT_COLOR_CONFIGURATION_TYPE from . import FlyingTeam, Location, Room, Visit, Worker +from . import ConfigurationItem class Appointment(models.Model): @@ -86,11 +88,18 @@ class Appointment(models.Model): def color(self): result = APPOINTMENT_TYPE_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 + if self.status == Appointment.APPOINTMENT_STATUS_NO_SHOW: + result = ConfigurationItem.objects.get(type=NO_SHOW_APPOINTMENT_COLOR_CONFIGURATION_TYPE).value + elif self.status == Appointment.APPOINTMENT_STATUS_CANCELLED: + result = ConfigurationItem.objects.get(type=CANCELLED_APPOINTMENT_COLOR_CONFIGURATION_TYPE).value + elif (self.location.color is not None) and (self.location.color != ""): + result = self.location.color + else: + 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 font_color(self): diff --git a/smash/web/models/constants.py b/smash/web/models/constants.py index 333f0baa2a66ea3c4e2e7c1b0437e5ac3f566200..cb52bd3aba0b11d401ed4b118ad0c36db26338fb 100644 --- a/smash/web/models/constants.py +++ b/smash/web/models/constants.py @@ -27,3 +27,6 @@ CONTACT_TYPES_CHOICES = ( (CONTACT_TYPES_PHONE, 'Phone'), (CONTACT_TYPES_SMS, 'SMS'), ) + +CANCELLED_APPOINTMENT_COLOR_CONFIGURATION_TYPE = "CANCELLED_APPOINTMENT_COLOR" +NO_SHOW_APPOINTMENT_COLOR_CONFIGURATION_TYPE = "NO_SHOW_APPOINTMENT_COLOR" diff --git a/smash/web/models/location.py b/smash/web/models/location.py index 2ae251486b48044adaaf668c7417ee1b2373d89d..c185a5f26736228b572b828d1504296edb0e15d4 100644 --- a/smash/web/models/location.py +++ b/smash/web/models/location.py @@ -8,6 +8,11 @@ class Location(models.Model): name = models.CharField(max_length=20) + color = models.CharField(max_length=20, + verbose_name='Calendar appointment color', + blank=True, + default="") + def __str__(self): return "%s" % self.name diff --git a/smash/web/templates/appointments/index.html b/smash/web/templates/appointments/index.html index 66aa979771b9489aa2cf7f065dc700b76a6e7454..b06cb857ded5c05577ba0d3913c3a895fd9c97d6 100644 --- a/smash/web/templates/appointments/index.html +++ b/smash/web/templates/appointments/index.html @@ -105,7 +105,7 @@ weekNumbers: true, startParam: "start_date", endParam: "end_date", - events: get_calendar_events_function("{% url 'web.api.appointments' full_list %}", false), + events: get_calendar_events_function("{% url 'web.api.appointments' full_list %}", true), }); }); </script> diff --git a/smash/web/tests/test_model_configuration_item.py b/smash/web/tests/test_model_configuration_item.py new file mode 100644 index 0000000000000000000000000000000000000000..be211a79adbe5b8312395ecb952458904d325d64 --- /dev/null +++ b/smash/web/tests/test_model_configuration_item.py @@ -0,0 +1,14 @@ +from django.test import TestCase + +from web.models import ConfigurationItem +from web.models.constants import CANCELLED_APPOINTMENT_COLOR_CONFIGURATION_TYPE, \ + NO_SHOW_APPOINTMENT_COLOR_CONFIGURATION_TYPE + + +class ConfigurationItemModelTests(TestCase): + def test_init_data(self): + items = ConfigurationItem.objects.filter(type=CANCELLED_APPOINTMENT_COLOR_CONFIGURATION_TYPE) + self.assertTrue(len(items) > 0) + + items = ConfigurationItem.objects.filter(type=NO_SHOW_APPOINTMENT_COLOR_CONFIGURATION_TYPE) + self.assertTrue(len(items) > 0)