Skip to content

Commit

Permalink
Merge branch 'flexible-end-llazzaro#541' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
the-moog committed Sep 10, 2022
2 parents ff54977 + 0a17ede commit 4c2913d
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 5 deletions.
13 changes: 9 additions & 4 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
0.10.? - 2022-09-10
===================

- Make event.end optional so that it can later be updated with a known value

0.10.0 - 2022-08-21
==========
===================

- Drop support for Python 3.6.
- Add support for Python 3.10
- Drop support for Django versions before 3.2.
- Allow override of prev_url and next_url links

0.9.6 - 2022-04-18
==========
==================

- Fix bug #522. 'backports.zoneinfo.ZoneInfo' object has no attribute 'localize'


0.9.5 - 2021-05-29
==========
==================

- Use an AutoField until Django 3.2 is the only supported version


0.9.4 - 2021-05-19
==========
==================

- Dropped support for Python 3.5.
- Dropped support for Django 1.11, 2.1 and 3.0.
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ Value is in seconds.
Default (two years):
62208000

### EVENT_END_DEFAULT_DURATION

An event can be created without an end date.
In this case the field default_end is set to True and this setting is used to supply an end date some time way into the future.

The value should be a dictionary of keywords for dateutil.relativedelta

Default (99 years):
```python
{"years": 99}
```

Contributing
============
Expand Down
13 changes: 12 additions & 1 deletion docs/settings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This setting controls the behavior of ``Views.get_next_url``. If set, all calend
SHOW_CANCELLED_OCCURRENCES
--------------------------

This setting controls the behavior of :func:`Period.classify_occurrence`. If True, then occurrences that have been cancelled will be displayed with a css class of canceled, otherwise they won't appear at all.
This setting controls the behavior of ``Period.classify_occurrence``. If True, then occurrences that have been cancelled will be displayed with a css class of canceled, otherwise they won't appear at all.

Defaults to False

Expand Down Expand Up @@ -57,3 +57,14 @@ example::

get_events(request, calendar):
return calendar.event_set.all()

EVENT_END_DEFAULT_DURATION
--------------------------

An event can be created without an end date.
In this case the field default_end is set to True and this setting is used to supply an end date some time way into the future.

The value should be a dictionary of keywords for dateutil.relativedelta

example:
{"years": 99}
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
python-dateutil~=2.7.3
setuptools~=45.2.0
pytz
coverage
1 change: 1 addition & 0 deletions schedule/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class Migration(migrations.Migration):
verbose_name="end",
),
),
("default_end", models.BooleanField(default=False)),
("title", models.CharField(max_length=255, verbose_name="title")),
(
"description",
Expand Down
24 changes: 24 additions & 0 deletions schedule/migrations/0015_alter_event_end.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.0.6 on 2022-09-10 15:18

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("schedule", "0014_use_autofields_for_pk"),
]

operations = [
migrations.AlterField(
model_name="event",
name="end",
field=models.DateTimeField(
blank=True,
db_index=True,
help_text="The end time must be later than the start time.",
null=True,
verbose_name="end",
),
),
]
28 changes: 28 additions & 0 deletions schedule/models/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytz
from dateutil import rrule
from dateutil.relativedelta import relativedelta
from django.conf import settings as django_settings
from django.contrib.contenttypes import fields
from django.contrib.contenttypes.models import ContentType
Expand All @@ -14,6 +15,7 @@

from schedule.models.calendars import Calendar
from schedule.models.rules import Rule
from schedule.settings import EVENT_END_DEFAULT_DURATION
from schedule.utils import OccurrenceReplacer

freq_dict_order = {
Expand Down Expand Up @@ -50,12 +52,38 @@ class Event(models.Model):
other models.
"""

@staticmethod
def end_of_time():
return datetime.datetime.today() + relativedelta(**EVENT_END_DEFAULT_DURATION)

def clean(self):
"""Ensure the end date is not given and optional end_recurring_period (if given) match"""
super().clean()
if self.end is None:
if self.end_recurring_period is not None:
self.end = self.end_recurring_period
else:
self.end = self.end_of_time()
self.default_end = True

if (
self.end_recurring_period is not None
and self.end != self.end_recurring_period
):
end = min(self.end, self.end_recurring_period)
self.end = end
self.end_recurring_period = end
self.default_end = False

start = models.DateTimeField(_("start"), db_index=True)
end = models.DateTimeField(
_("end"),
db_index=True,
null=True,
blank=True,
help_text=_("The end time must be later than the start time."),
)
default_end = models.BooleanField(default=False)
title = models.CharField(_("title"), max_length=255)
description = models.TextField(_("description"), blank=True)
creator = models.ForeignKey(
Expand Down
5 changes: 5 additions & 0 deletions schedule/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,8 @@ def get_events(request, calendar):

# This name is used when a new event is created through selecting in fullcalendar
EVENT_NAME_PLACEHOLDER = getattr(settings, "EVENT_NAME_PLACEHOLDER", "Event Name")

# Default kw args to dateutuil.relativedelta to create a temporary end date if none given
EVENT_END_DEFAULT_DURATION = getattr(
settings, "EVENT_END_DEFAULT_DURATION", {"years": 99}
)

0 comments on commit 4c2913d

Please sign in to comment.