[FIX] website_event: event dates within event timezone
The dates of an event on the website was always within the user timezone. If not signed in, it was within the public user timezone (which is quite not user-friendly to change) For this purpose, we weed get the context from the record (the context used when using `record.with_context`), and therefore the QWeb field `ir.qweb.field.datetime` is slightly altered, to use the context from the record. opw-675427
This commit is contained in:
parent
7f05692cb9
commit
8395f0d217
|
@ -66,7 +66,7 @@
|
||||||
</t>
|
</t>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<i class="fa fa-clock-o"></i> <span itemprop="startDate" t-field="event.date_begin" t-field-options='{"hide_seconds":"True"}'> </span> <i>to</i> <span itemprop="endDate" t-field="event.date_end" t-field-options='{"hide_seconds":"True"}'> </span>
|
<i class="fa fa-clock-o"></i> <span itemprop="startDate" t-field="event.with_context(tz=event.date_tz).date_begin" t-field-options='{"hide_seconds":"True"}'> </span> <i>to</i> <span itemprop="endDate" t-field="event.with_context(tz=event.date_tz).date_end" t-field-options='{"hide_seconds":"True"}'> </span>
|
||||||
</div>
|
</div>
|
||||||
<div itemprop="location" t-field="event.address_id" t-field-options='{
|
<div itemprop="location" t-field="event.address_id" t-field-options='{
|
||||||
"widget": "contact",
|
"widget": "contact",
|
||||||
|
@ -257,8 +257,8 @@
|
||||||
<div itemscope="itemscope" itemtype="http://schema.org/Event" class="container">
|
<div itemscope="itemscope" itemtype="http://schema.org/Event" class="container">
|
||||||
<h1 itemprop="name" class="text-center" t-field="event.name"></h1>
|
<h1 itemprop="name" class="text-center" t-field="event.name"></h1>
|
||||||
<h4 class="text-center text-muted">
|
<h4 class="text-center text-muted">
|
||||||
<i class="fa fa-clock-o"></i> <span itemprop="startDate" t-field="event.date_begin" t-field-options='{"hide_seconds":"True"}'/> to
|
<i class="fa fa-clock-o"></i> <span itemprop="startDate" t-field="event.with_context(tz=event.date_tz).date_begin" t-field-options='{"hide_seconds":"True"}'/> to
|
||||||
<span itemprop="endDate" t-field="event.date_end" t-field-options='{"hide_seconds":"True"}'/>
|
<span itemprop="endDate" t-field="event.with_context(tz=event.date_tz).date_end" t-field-options='{"hide_seconds":"True"}'/>
|
||||||
</h4>
|
</h4>
|
||||||
<h4 class="text-center text-muted"
|
<h4 class="text-center text-muted"
|
||||||
t-field="event.address_id" t-field-options='{
|
t-field="event.address_id" t-field-options='{
|
||||||
|
@ -330,8 +330,8 @@
|
||||||
<h4>When</h4>
|
<h4>When</h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<i class="fa fa-clock-o"></i> From <span t-field="event.date_begin" t-field-options='{"hide_seconds":"True"}'> </span><br/>
|
<i class="fa fa-clock-o"></i> From <span t-field="event.with_context(tz=event.date_tz).date_begin" t-field-options='{"hide_seconds":"True"}'> </span><br/>
|
||||||
<i class="fa fa-clock-o"></i> To <span t-field="event.date_end" t-field-options='{"hide_seconds":"True"}'> </span>
|
<i class="fa fa-clock-o"></i> To <span t-field="event.with_context(tz=event.date_tz).date_end" t-field-options='{"hide_seconds":"True"}'> </span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -712,12 +712,6 @@ class DateTimeConverter(osv.AbstractModel):
|
||||||
lang = self.user_lang(cr, uid, context=context)
|
lang = self.user_lang(cr, uid, context=context)
|
||||||
locale = babel.Locale.parse(lang.code)
|
locale = babel.Locale.parse(lang.code)
|
||||||
|
|
||||||
if isinstance(value, basestring):
|
|
||||||
value = datetime.datetime.strptime(
|
|
||||||
value, openerp.tools.DEFAULT_SERVER_DATETIME_FORMAT)
|
|
||||||
value = fields.datetime.context_timestamp(
|
|
||||||
cr, uid, timestamp=value, context=context)
|
|
||||||
|
|
||||||
if options and 'format' in options:
|
if options and 'format' in options:
|
||||||
pattern = options['format']
|
pattern = options['format']
|
||||||
else:
|
else:
|
||||||
|
@ -729,6 +723,17 @@ class DateTimeConverter(osv.AbstractModel):
|
||||||
|
|
||||||
return babel.dates.format_datetime(value, format=pattern, locale=locale)
|
return babel.dates.format_datetime(value, format=pattern, locale=locale)
|
||||||
|
|
||||||
|
def record_to_html(self, cr, uid, field_name, record, options, context=None):
|
||||||
|
value = record[field_name]
|
||||||
|
if isinstance(value, basestring):
|
||||||
|
value = datetime.datetime.strptime(
|
||||||
|
value, openerp.tools.DEFAULT_SERVER_DATETIME_FORMAT)
|
||||||
|
value = fields.datetime.context_timestamp(
|
||||||
|
cr, uid, timestamp=value, context=record.env.context)
|
||||||
|
field = field = record._fields[field_name]
|
||||||
|
return self.value_to_html(
|
||||||
|
cr, uid, value, field, options=options, context=context)
|
||||||
|
|
||||||
class TextConverter(osv.AbstractModel):
|
class TextConverter(osv.AbstractModel):
|
||||||
_name = 'ir.qweb.field.text'
|
_name = 'ir.qweb.field.text'
|
||||||
_inherit = 'ir.qweb.field'
|
_inherit = 'ir.qweb.field'
|
||||||
|
|
Loading…
Reference in New Issue