fix by_day value, fix getting next event date with respect to rotation end date
This commit is contained in:
parent
6dc4657371
commit
5ebcb39499
3 changed files with 19 additions and 3 deletions
|
|
@ -90,7 +90,7 @@ class OnCallShiftSerializer(EagerLoadingMixin, serializers.ModelSerializer):
|
|||
def validate_by_day(self, by_day):
|
||||
if by_day:
|
||||
for day in by_day:
|
||||
if day not in CustomOnCallShift.ICAL_WEEKDAY_MAP.keys():
|
||||
if day not in CustomOnCallShift.WEB_WEEKDAY_MAP:
|
||||
raise serializers.ValidationError(["Invalid day value."])
|
||||
return by_day
|
||||
|
||||
|
|
|
|||
|
|
@ -95,8 +95,8 @@ class OnCallShiftView(PublicPrimaryKeyMixin, UpdateSerializerMixin, ModelViewSet
|
|||
[
|
||||
{
|
||||
"display_name": display_name,
|
||||
"value": day_number,
|
||||
"value": value,
|
||||
}
|
||||
for day_number, display_name in CustomOnCallShift.WEEKDAY_CHOICES
|
||||
for value, display_name in CustomOnCallShift.WEB_WEEKDAY_MAP.items()
|
||||
]
|
||||
)
|
||||
|
|
|
|||
|
|
@ -115,6 +115,16 @@ class CustomOnCallShift(models.Model):
|
|||
SATURDAY: "SA",
|
||||
SUNDAY: "SU",
|
||||
}
|
||||
|
||||
WEB_WEEKDAY_MAP = {
|
||||
"MO": "Monday",
|
||||
"TU": "Tuesday",
|
||||
"WE": "Wednesday",
|
||||
"TH": "Thursday",
|
||||
"FR": "Friday",
|
||||
"SA": "Saturday",
|
||||
"SU": "Sunday",
|
||||
}
|
||||
(
|
||||
SOURCE_WEB,
|
||||
SOURCE_API,
|
||||
|
|
@ -240,6 +250,8 @@ class CustomOnCallShift(models.Model):
|
|||
users_queue = self.get_rolling_users()
|
||||
for counter, users in enumerate(users_queue, start=1):
|
||||
start = self.get_next_start_date(event_ical)
|
||||
if not start: # means that rotation ends before next event starts
|
||||
break
|
||||
for user_counter, user in enumerate(users, start=1):
|
||||
event_ical = self.generate_ical(user, start, user_counter, counter, time_zone)
|
||||
result += event_ical
|
||||
|
|
@ -301,6 +313,10 @@ class CustomOnCallShift(models.Model):
|
|||
if days_for_next_event > DAYS_IN_A_MONTH:
|
||||
days_for_next_event = days_for_next_event % DAYS_IN_A_MONTH
|
||||
next_event_start = current_event_start + timezone.timedelta(days=days_for_next_event)
|
||||
|
||||
# check if rotation ends before next event starts
|
||||
if self.until and next_event_start > self.until:
|
||||
return
|
||||
next_event = None
|
||||
# repetitions generate the next event shift according with the recurrence rules
|
||||
repetitions = UnfoldableCalendar(current_event).RepeatedEvent(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue