From 4c0c460e36a0536bc958739f2e438404ddb560de Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Thu, 20 Jan 2022 16:34:08 +0100 Subject: [PATCH 2/5] agendas: add weekday indexes to time period (#45159) --- .../0110_timeperiod_weekday_indexes.py | 33 +++++++++++++++++++ chrono/agendas/models.py | 15 +++++++++ 2 files changed, 48 insertions(+) create mode 100644 chrono/agendas/migrations/0110_timeperiod_weekday_indexes.py diff --git a/chrono/agendas/migrations/0110_timeperiod_weekday_indexes.py b/chrono/agendas/migrations/0110_timeperiod_weekday_indexes.py new file mode 100644 index 00000000..366ec7a8 --- /dev/null +++ b/chrono/agendas/migrations/0110_timeperiod_weekday_indexes.py @@ -0,0 +1,33 @@ +# Generated by Django 2.2.19 on 2022-03-10 11:03 + +import django.contrib.postgres.fields +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('agendas', '0109_auto_20220203_1051'), + ] + + operations = [ + migrations.AddField( + model_name='timeperiod', + name='weekday_indexes', + field=django.contrib.postgres.fields.ArrayField( + base_field=models.IntegerField( + choices=[ + (1, 'First of the month'), + (2, 'Second of the month'), + (3, 'Third of the month'), + (4, 'Fourth of the month'), + (5, 'Fifth of the month'), + ] + ), + blank=True, + null=True, + size=None, + verbose_name='Repeat', + ), + ), + ] diff --git a/chrono/agendas/models.py b/chrono/agendas/models.py index 2b4e98aa..9536179c 100644 --- a/chrono/agendas/models.py +++ b/chrono/agendas/models.py @@ -1157,8 +1157,23 @@ class WeekTime(collections.namedtuple('WeekTime', ['weekday', 'time'])): ) +WEEK_CHOICES = [ + (1, _('First of the month')), + (2, _('Second of the month')), + (3, _('Third of the month')), + (4, _('Fourth of the month')), + (5, _('Fifth of the month')), +] + + class TimePeriod(models.Model): weekday = models.IntegerField(_('Week day'), choices=WEEKDAYS_LIST) + weekday_indexes = ArrayField( + models.IntegerField(choices=WEEK_CHOICES), + verbose_name=_('Repeat'), + blank=True, + null=True, + ) start_time = models.TimeField(_('Start')) end_time = models.TimeField(_('End')) desk = models.ForeignKey('Desk', on_delete=models.CASCADE, null=True) -- 2.30.2