From 9f5bdce8402be5636fa58941b3c9944dee7829cb Mon Sep 17 00:00:00 2001 From: bkfox Date: Wed, 23 Aug 2017 17:01:25 +0200 Subject: [PATCH] update tz and get default tz --- aircox/models.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/aircox/models.py b/aircox/models.py index 028e5bd..7eb5e38 100755 --- a/aircox/models.py +++ b/aircox/models.py @@ -520,6 +520,21 @@ class Schedule(models.Model): help_text = 'this schedule is a rerun of this one', ) + @property + def tz(self): + """ + Pytz timezone of the schedule. + """ + if not hasattr(self, '_tz') or self._tz.zone != self.timezone: + import pytz + if not self.timezone: + self.timezone = \ + self.date.tzinfo.zone \ + if self.date and hasattr(self.date, 'tzinfo') else \ + tz.get_current_timezone_name() + self._tz = pytz.timezone(self.timezone or self.date.tzinfo.zone) + return self._tz + # initial cached data __initial = None @@ -578,16 +593,6 @@ class Schedule(models.Model): return self.frequency == 0b1111 return (self.frequency & (0b0001 << week) > 0) - @property - def tz(self): - """ - Return pytz timezone for this schedule. - """ - if not hasattr(self, '_tz') or self._tz.zone != self.timezone: - import pytz - self._tz = pytz.timezone('Europe/Brussels') - return self._tz - def normalize(self, date): """ Set the time of a datetime to the schedule's one