0001-agendas-share-booking-colors-between-agendas-50379.patch
chrono/agendas/migrations/0073_auto_20210125_1800.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Generated by Django 1.11.18 on 2021-01-25 17:00 |
|
3 |
from __future__ import unicode_literals |
|
4 | ||
5 |
from django.db import migrations |
|
6 | ||
7 | ||
8 |
def booking_color_unique_label(apps, schema_editor): |
|
9 |
BookingColor = apps.get_model('agendas', 'BookingColor') |
|
10 | ||
11 |
for color in BookingColor.objects.order_by('label').distinct('label'): |
|
12 |
BookingColor.objects.filter(label=color.label).exclude(pk=color.pk).delete() |
|
13 | ||
14 | ||
15 |
class Migration(migrations.Migration): |
|
16 |
atomic = False |
|
17 | ||
18 |
dependencies = [ |
|
19 |
('agendas', '0072_booking_absence_reason'), |
|
20 |
] |
|
21 | ||
22 |
operations = [ |
|
23 |
migrations.RunPython(booking_color_unique_label, migrations.RunPython.noop), |
|
24 |
migrations.AlterUniqueTogether( |
|
25 |
name='bookingcolor', |
|
26 |
unique_together=set([('label',)]), |
|
27 |
), |
|
28 |
migrations.RemoveField( |
|
29 |
model_name='bookingcolor', |
|
30 |
name='agenda', |
|
31 |
), |
|
32 |
] |
chrono/agendas/models.py | ||
---|---|---|
1059 | 1059 |
class BookingColor(models.Model): |
1060 | 1060 |
COLOR_COUNT = 8 |
1061 | 1061 | |
1062 |
agenda = models.ForeignKey(Agenda, on_delete=models.CASCADE, related_name='booking_colors') |
|
1063 | 1062 |
label = models.CharField(_('Label'), max_length=250) |
1064 | 1063 |
index = models.PositiveSmallIntegerField() |
1065 | 1064 | |
1066 | 1065 |
class Meta: |
1067 |
unique_together = ('agenda', 'label')
|
|
1066 |
unique_together = ('label',)
|
|
1068 | 1067 |
ordering = ('pk',) |
1069 | 1068 | |
1070 | 1069 |
def save(self, *args, **kwargs): |
1071 | 1070 |
if self.index is None: |
1072 |
last_color = BookingColor.objects.filter(agenda=self.agenda).last() or BookingColor(index=-1)
|
|
1071 |
last_color = BookingColor.objects.last() or BookingColor(index=-1) |
|
1073 | 1072 |
self.index = (last_color.index + 1) % self.COLOR_COUNT |
1074 | 1073 |
super().save(*args, **kwargs) |
1075 | 1074 |
chrono/api/views.py | ||
---|---|---|
954 | 954 | |
955 | 955 |
color_label = payload.get('use_color_for') |
956 | 956 |
if color_label: |
957 |
color = BookingColor.objects.get_or_create(agenda=agenda, label=color_label)[0]
|
|
957 |
color = BookingColor.objects.get_or_create(label=color_label)[0] |
|
958 | 958 | |
959 | 959 |
available_desk = None |
960 | 960 |
chrono/manager/views.py | ||
---|---|---|
886 | 886 |
except ValueError: # no meeting types defined |
887 | 887 |
context['hour_span'] = 1 |
888 | 888 |
context['booking_colors'] = BookingColor.objects.filter( |
889 |
agenda=self.agenda, bookings__event__in=self.object_list
|
|
889 |
bookings__event__in=self.object_list |
|
890 | 890 |
).distinct() |
891 | 891 |
context['user_can_manage'] = self.agenda.can_be_managed(self.request.user) |
892 | 892 |
return context |
893 |
- |