[FIX] P3: calendar: correct fwd-port of rev. 83024ca3d6
- 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
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user