Skip to content
Snippets Groups Projects
Commit 959b81e4 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '89-calendar-colors' into 'master'

Custom calendar colors for appointment location and appointment status

Closes #89

See merge request !37
parents 5d8d9542 3b440733
No related branches found
No related tags found
1 merge request!37Custom calendar colors for appointment location and appointment status
Pipeline #
# -*- 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),
]
# -*- 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),
),
]
# -*- 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'),
),
]
# -*- 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),
]
......@@ -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():
......
......@@ -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):
......
......@@ -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"
......@@ -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
......
......@@ -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>
......
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment