Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.1.13 #112

Merged
merged 6 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ambition_utils/docs/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
Release Notes
=============

3.1.13
------
* Fix possible null date comparison in rrule form update logic

3.1.12
------
* RRule clones will now retain the next_occurrence of the source.
* RRule clones will now retain the next_occurrence of the source.

3.1.11
------
Expand Down
9 changes: 6 additions & 3 deletions ambition_utils/rrule/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def __init__(self, *args, **kwargs):
# cause the base form init to fail
kwargs.pop('instance', None)

super(RecurrenceForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def clean_rrule_exclusion(self):
# Get the value from data
Expand Down Expand Up @@ -255,12 +255,15 @@ def save(self, **kwargs):
# Get the rrule model from the cleaned data
rrule_model = self.cleaned_data.get('rrule')
if rrule_model:
# Refresh if the next occurrence is not expired.
need_to_refresh_next_occurrence = rrule_model.next_occurrence > datetime.utcnow()
need_to_refresh_next_occurrence = True
else:
# Use the recurrence passed into save kwargs
rrule_model = kwargs.get('recurrence') or RRule()

# Do not refresh if the next occurrence has not been handled yet
if rrule_model.next_occurrence and rrule_model.next_occurrence <= datetime.utcnow():
need_to_refresh_next_occurrence = False

# Create or update the rule
rrule_model.rrule_params = self.get_rrule_params_from_cleaned_data()
rrule_model.rrule_exclusion_params = self.cleaned_data.get('rrule_exclusion')
Expand Down
47 changes: 47 additions & 0 deletions ambition_utils/rrule/tests/form_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,53 @@ def test_update(self):
RRule.objects.update_next_occurrences([rrule_model])
self.assertEqual(rrule_model.next_occurrence, datetime.datetime(2017, 6, 7))

def test_update_finished_rrule(self):
"""
Handles the case of trying to update an rrule that has completed so it no longer has a next
occurrence. It should be able to update without any errors.
"""
# Create an object, update its next occurrence, and assert it changes.
with freeze_time(datetime.datetime(2017, 6, 6)):
data = {
'freq': rrule.DAILY,
'interval': 1,
'dtstart': '6/4/2017',
'byhour': '0',
'time_zone': 'UTC',
'ends': RecurrenceEnds.ON,
'until': '6/5/2017',
}
form = RecurrenceForm(data=data)
self.assertTrue(form.is_valid())
rrule_model = form.save(
occurrence_handler_path='ambition_utils.rrule.handler.OccurrenceHandler',
)

# Refresh next occurrence so it completes
rrule_model.refresh_next_occurrence()
rrule_model.save()
self.assertEqual(RRule.objects.count(), 1)
self.assertEqual(rrule_model.next_occurrence, None)

# In the future from the original completion date, try to update the rrule
with freeze_time(datetime.datetime(2017, 6, 9)):
data = {
'rrule': str(rrule_model.id),
'freq': rrule.DAILY,
'interval': 1,
'dtstart': '6/4/2017',
'byhour': '0',
'time_zone': 'UTC',
'ends': RecurrenceEnds.ON,
'until': '6/10/2017',
}
form = RecurrenceForm(data=data)
self.assertTrue(form.is_valid())
rrule_model = form.save(
occurrence_handler_path='ambition_utils.rrule.handler.OccurrenceHandler',
)
self.assertEqual(rrule_model.next_occurrence, datetime.datetime(2017, 6, 10))

def test_exclusion_rule(self):
exclusion_data = {
'freq': rrule.MONTHLY,
Expand Down
2 changes: 1 addition & 1 deletion ambition_utils/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '3.1.12'
__version__ = '3.1.13'
Loading