Skip to content

Commit 60c601b

Browse files
committed
updating Recurrence class to be py3 compatible
in python 3 the __str__ method is called when converting a class to a string (opposed to the __unicode__ method in py2). This change renames the __unicode__ method to __str__, so we can easily get the serialized version of a Recurrence object and while doing so maintain py2 compatibility be wrapping the class with Djangos python_2_unicode_compatible decorator for more info see https://docs.djangoproject.com/en/1.11/topics/python3/#str-and-unicode-methods
1 parent efb0b97 commit 60c601b

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

recurrence/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import pytz
1717
import dateutil.rrule
1818
from django.utils import dateformat, timezone
19+
from django.utils.encoding import python_2_unicode_compatible
1920
from django.utils.translation import ugettext as _, pgettext as _p
2021
from django.utils.six import string_types
2122

@@ -243,6 +244,7 @@ def to_dateutil_rrule(self, dtstart=None, dtend=None, cache=False):
243244
cache=cache, **kwargs)
244245

245246

247+
@python_2_unicode_compatible
246248
class Recurrence(object):
247249
"""
248250
A combination of `Rule` and `datetime.datetime` instances.
@@ -319,7 +321,7 @@ def __init__(
319321
def __iter__(self):
320322
return self.occurrences()
321323

322-
def __unicode__(self):
324+
def __str__(self):
323325
return serialize(self)
324326

325327
def __hash__(self):

0 commit comments

Comments
 (0)