Skip to content
Snippets Groups Projects
Commit 7cf554af authored by Vipul Bhatt's avatar Vipul Bhatt Committed by Denis Vermylen (dve)
Browse files

[IMP] website_event_track: display event time in website language format

parent 4d9f5bbf
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import babel
import collections
import datetime
import pytz
......@@ -18,8 +19,18 @@ class WebsiteEventTrackController(http.Controller):
values = {'track': track, 'event': track.event_id, 'main_object': track}
return request.render("website_event_track.track_view", values)
def _get_locale_time(self, dt_time, lang_code):
""" Get locale time from datetime object
:param dt_time: datetime object
:param lang_code: language code (eg. en_US)
"""
locale = babel.Locale.parse(lang_code)
return babel.dates.format_time(dt_time, format='short', locale=locale)
def _prepare_calendar(self, event, event_track_ids):
local_tz = pytz.timezone(event.date_tz or 'UTC')
lang_code = request.env.context.get('lang')
locations = {} # { location: [track, start_date, end_date, rowspan]}
dates = [] # [ (date, {}) ]
for track in event_track_ids:
......@@ -34,7 +45,8 @@ class WebsiteEventTrackController(http.Controller):
# New TR, align all events
if forcetr or (start_date>dates[-1][0]) or not location:
dates.append((start_date, {}, bool(location)))
formatted_time = self._get_locale_time(start_date, lang_code)
dates.append((start_date, {}, bool(location), formatted_time))
for loc in locations.keys():
if locations[loc] and (locations[loc][-1][2] > start_date):
locations[loc][-1][3] += 1
......@@ -62,9 +74,9 @@ class WebsiteEventTrackController(http.Controller):
days_tracks[track.date[:10]].append(track)
days = {}
days_tracks_count = {}
tracks_by_days = {}
for day, tracks in days_tracks.iteritems():
days_tracks_count[day] = len(tracks)
tracks_by_days[day] = tracks
days[day] = self._prepare_calendar(event, tracks)
speakers = {}
......@@ -75,7 +87,7 @@ class WebsiteEventTrackController(http.Controller):
return request.render("website_event_track.agenda", {
'event': event,
'days': days,
'days_nbr': days_tracks_count,
'tracks_by_days': tracks_by_days,
'speakers': speakers,
'tag': tag
})
......
......@@ -55,8 +55,8 @@
<t t-set="locations" t-value="days[day]['locations']"/>
<t t-set="dates" t-value="days[day]['dates']"/>
<h3 class="page-header mt0">
<t t-esc="day"/>
<small><t t-esc="days_nbr[day]"/> talks</small>
<span t-field="tracks_by_days[day][0].date" t-field-options="{'widget': 'date'}"/>
<small><t t-esc="len(tracks_by_days[day])"/> talks</small>
</h3>
<table id="table_search" class="table table-bordered table-condensed">
<tr>
......@@ -69,7 +69,7 @@
</tr>
<tr t-foreach="dates" t-as="dt">
<td class="active">
<b t-esc="dt[0].strftime('%H:%M')"/>
<b t-esc="dt[-1]"/>
</td>
<t t-if="dt[2]"> <!-- Not a multi location -->
<t t-foreach="locations" t-as="location">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment