summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Dony <odo@openerp.com>2017-10-19 18:19:08 +0200
committerOlivier Dony <odo@openerp.com>2017-10-19 18:19:08 +0200
commitf5df4fbca1d6dce4f98cdb6b27bee3fb843febf4 (patch)
treec5c090f0294ca1f1d179703b4155bb7051823f61
parent5d561ec934bb7a7c79885537675ce394d1841ec7 (diff)
[FIX] P3: calendar: correct fwd-port of rev. 83024ca3d64b1a61c4807f184c93d9ca51f396b2
- simplify unicode handling for Py2 and Py3 - fix Py3-related bugs, such as passing bytes for context['tz'], making the conversion silently fail, or attempting to decode() a text
-rw-r--r--addons/calendar/models/calendar.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/addons/calendar/models/calendar.py b/addons/calendar/models/calendar.py
index 3fae81f860f..3c7e24c9187 100644
--- a/addons/calendar/models/calendar.py
+++ b/addons/calendar/models/calendar.py
@@ -670,27 +670,27 @@ class Meeting(models.Model):
1) if user add duration for 2 hours, return : August-23-2013 at (04-30 To 06-30) (Europe/Brussels)
2) if event all day ,return : AllDay, July-31-2013
"""
- timezone = self._context.get('tz')
- if not timezone:
- timezone = self.env.user.partner_id.tz or 'UTC'
- timezone = tools.ustr(timezone).encode('utf-8') # make safe for str{p,f}time()
+ timezone = self._context.get('tz') or self.env.user.partner_id.tz or 'UTC'
+ timezone = pycompat.to_native(timezone) # make safe for str{p,f}time()
# get date/time format according to context
- format_date, format_time = self.with_context(tz=timezone)._get_date_formats()
+ format_date, format_time = self._get_date_formats()
# convert date and time into user timezone
- date = fields.Datetime.context_timestamp(self.with_context(tz=timezone), fields.Datetime.from_string(start))
- date_deadline = fields.Datetime.context_timestamp(self.with_context(tz=timezone), fields.Datetime.from_string(stop))
+ self_tz = self.with_context(tz=timezone)
+ date = fields.Datetime.context_timestamp(self_tz, fields.Datetime.from_string(start))
+ date_deadline = fields.Datetime.context_timestamp(self_tz, fields.Datetime.from_string(stop))
# convert into string the date and time, using user formats
- date_str = date.strftime(format_date).decode('utf-8')
- time_str = date.strftime(format_time).decode('utf-8')
+ to_text = pycompat.to_text
+ date_str = to_text(date.strftime(format_date))
+ time_str = to_text(date.strftime(format_time))
if zallday:
display_time = _("AllDay , %s") % (date_str)
elif zduration < 24:
duration = date + timedelta(hours=zduration)
- duration_time = duration.strftime(format_time).decode('utf-8')
+ duration_time = to_text(duration.strftime(format_time))
display_time = _(u"%s at (%s To %s) (%s)") % (
date_str,
time_str,
@@ -698,8 +698,8 @@ class Meeting(models.Model):
timezone,
)
else:
- dd_date = date_deadline.strftime(format_date).decode('utf-8')
- dd_time = date_deadline.strftime(format_time).decode('utf-8')
+ dd_date = to_text(date_deadline.strftime(format_date))
+ dd_time = to_text(date_deadline.strftime(format_time))
display_time = _(u"%s at %s To\n %s at %s (%s)") % (
date_str,
time_str,