agendas: share booking colors between agendas (#50379)

This commit is contained in:
Valentin Deniaud 2021-01-25 18:03:33 +01:00 committed by Frédéric Péters
parent a569b992e0
commit 55841ecfcd
4 changed files with 36 additions and 5 deletions

View File

@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2021-01-25 17:00
from __future__ import unicode_literals
from django.db import migrations
def booking_color_unique_label(apps, schema_editor):
BookingColor = apps.get_model('agendas', 'BookingColor')
for color in BookingColor.objects.order_by('label').distinct('label'):
BookingColor.objects.filter(label=color.label).exclude(pk=color.pk).delete()
class Migration(migrations.Migration):
atomic = False
dependencies = [
('agendas', '0072_booking_absence_reason'),
]
operations = [
migrations.RunPython(booking_color_unique_label, migrations.RunPython.noop),
migrations.AlterUniqueTogether(
name='bookingcolor',
unique_together=set([('label',)]),
),
migrations.RemoveField(
model_name='bookingcolor',
name='agenda',
),
]

View File

@ -1059,17 +1059,16 @@ class Event(models.Model):
class BookingColor(models.Model):
COLOR_COUNT = 8
agenda = models.ForeignKey(Agenda, on_delete=models.CASCADE, related_name='booking_colors')
label = models.CharField(_('Label'), max_length=250)
index = models.PositiveSmallIntegerField()
class Meta:
unique_together = ('agenda', 'label')
unique_together = ('label',)
ordering = ('pk',)
def save(self, *args, **kwargs):
if self.index is None:
last_color = BookingColor.objects.filter(agenda=self.agenda).last() or BookingColor(index=-1)
last_color = BookingColor.objects.last() or BookingColor(index=-1)
self.index = (last_color.index + 1) % self.COLOR_COUNT
super().save(*args, **kwargs)

View File

@ -954,7 +954,7 @@ class Fillslots(APIView):
color_label = payload.get('use_color_for')
if color_label:
color = BookingColor.objects.get_or_create(agenda=agenda, label=color_label)[0]
color = BookingColor.objects.get_or_create(label=color_label)[0]
available_desk = None

View File

@ -886,7 +886,7 @@ class AgendaDateView(DateMixin, ViewableAgendaMixin):
except ValueError: # no meeting types defined
context['hour_span'] = 1
context['booking_colors'] = BookingColor.objects.filter(
agenda=self.agenda, bookings__event__in=self.object_list
bookings__event__in=self.object_list
).distinct()
context['user_can_manage'] = self.agenda.can_be_managed(self.request.user)
return context