Skip to content

Commit

Permalink
a few speedups
Browse files Browse the repository at this point in the history
  • Loading branch information
niphlod committed Apr 17, 2013
1 parent 787777a commit e50cdec
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions modules/plugin_timezone/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,22 @@
('Pacific/Kiritimati', '(UTC+14:00) Kiritimati')
]

TZDICT = dict((tzn[0], 1) for tzn in TZSETS)

def tz_nice_detector_widget(field, value, **attributes):
nice_TZSETS = []
options = []
for tzn in TZSETS:
#retrieve offset
localized = datetime.datetime.now(pytz.timezone(tzn[0]))
nice_TZSETS.append((tzn[0], tzn[1], localized.strftime('%Y-%m-%d %H:%M')))
options.append(
OPTION(tzn[1], _value=tzn[0],
data=dict(localized=localized.strftime('%Y-%m-%d %H:%M'))
)
)


_id = '%s_%s' % (field._tablename, field.name)
_name = field.name
options = [OPTION(tzn[1], _value=tzn[0], data=dict(localized=tzn[2])) for tzn in nice_TZSETS]
if 'autodetect' in attributes and attributes.pop('autodetect') is True:
current.response.files.append(URL('static', 'plugin_timezone/jstz.min.js'))
script = """
Expand Down Expand Up @@ -143,7 +149,8 @@ def fast_tz_detector():
});
""" % URL()
if current.request.post_vars.timezone:
if current.request.post_vars.timezone in [tz[0] for tz in TZSETS]:
if current.request.post_vars.timezone in TZDICT:
if not current.session.plugin_timezone_tz:
current.session.plugin_timezone_tz = current.request.post_vars.timezone

return SCRIPT(script)

0 comments on commit e50cdec

Please sign in to comment.