annotate tools/tz.py @ 645:99f7917702ca
Fix 081a88b3bfc8, javascript resize of forum images.
Commit 081a88b3bfc8 broke those pages that loaded forums.js but did not load
the imagesLoaded jQuery extension. Now we have arranged it so that only the
forums topic view loads imagesLoaded and put the resizing javascript inline.
author |
Brian Neal <bgneal@gmail.com> |
date |
Mon, 11 Mar 2013 15:30:25 -0500 |
parents |
ed6202fb08b6 |
children |
|
rev |
line source |
bgneal@245
|
1 """
|
bgneal@245
|
2 This program generates the data used by the timezone.js Javascript.
|
bgneal@245
|
3 This data is used to create the 2 dropdown select boxes for timezones.
|
bgneal@245
|
4 """
|
bgneal@245
|
5 import pytz
|
bgneal@245
|
6 from pprint import pprint
|
bgneal@245
|
7
|
bgneal@245
|
8 def format_locations(locs):
|
bgneal@245
|
9 ss = ["[%s]" % ", ".join(["'%s'" % l for l in loc]) for loc in locs]
|
bgneal@245
|
10 return "%s" % ",\n".join(ss)
|
bgneal@245
|
11
|
bgneal@245
|
12 # get a list of areas
|
bgneal@245
|
13
|
bgneal@245
|
14 zones = [z.split('/') for z in pytz.common_timezones]
|
bgneal@245
|
15 areas = set([zone[0] for zone in zones if len(zone) > 1])
|
bgneal@245
|
16 areas = list(areas)
|
bgneal@245
|
17 areas.sort()
|
bgneal@245
|
18
|
bgneal@245
|
19 locations = dict([(area, []) for area in areas])
|
bgneal@245
|
20
|
bgneal@245
|
21 #pprint(locations)
|
bgneal@245
|
22
|
bgneal@245
|
23 for zone in pytz.common_timezones:
|
bgneal@245
|
24 if zone.count('/') == 0:
|
bgneal@245
|
25 continue
|
bgneal@245
|
26 area, loc = zone.split('/', 1)
|
bgneal@245
|
27 if area in locations:
|
bgneal@245
|
28 locations[area].append(loc.replace('_', ' '))
|
bgneal@245
|
29
|
bgneal@245
|
30 #pprint(locations)
|
bgneal@245
|
31
|
bgneal@245
|
32 for area in locations.iterkeys():
|
bgneal@245
|
33 locations[area].sort()
|
bgneal@245
|
34
|
bgneal@245
|
35 locs = []
|
bgneal@245
|
36 for area in areas:
|
bgneal@245
|
37 locs.append(locations[area])
|
bgneal@245
|
38
|
bgneal@245
|
39 #pprint(locs)
|
bgneal@245
|
40
|
bgneal@245
|
41 default_area = areas.index('US')
|
bgneal@245
|
42 default_location = locs[default_area].index('Pacific')
|
bgneal@245
|
43
|
bgneal@245
|
44 print """\
|
bgneal@245
|
45 var gcalTzInfo = {
|
bgneal@245
|
46 areas: [%s],
|
bgneal@245
|
47 locations: [%s],
|
bgneal@245
|
48 default_area: %s,
|
bgneal@245
|
49 default_location: %s
|
bgneal@245
|
50 };
|
bgneal@245
|
51 """ % (", ".join(["'%s'" % area for area in areas]),
|
bgneal@245
|
52 format_locations(locs),
|
bgneal@245
|
53 default_area,
|
bgneal@245
|
54 default_location,
|
bgneal@245
|
55 )
|