add prefs to render context, and remove old timezone/formatter from it
authorTero Marttila <terom@fixme.fi>
Mon, 09 Feb 2009 07:15:19 +0200
changeset 62 e7ca94b94a4e
parent 61 d4b2b2fa9fc5
child 63 416560b82116
add prefs to render context, and remove old timezone/formatter from it
handlers.py
helpers.py
preferences.py
templates/channel.tmpl
templates/preferences.tmpl
--- a/handlers.py	Mon Feb 09 07:09:00 2009 +0200
+++ b/handlers.py	Mon Feb 09 07:15:19 2009 +0200
@@ -50,7 +50,6 @@
         req             = request,
         prefs           = request.prefs,
         preferences     = prefs,
-        timezone        = request.prefs[prefs.timezone],
         timezones       = pytz.common_timezones,
     )
 
@@ -75,10 +74,9 @@
 
     return templates.render_to_response("channel_view",
         req             = request,
-        timezone        = request.prefs[prefs.timezone],
+        prefs           = request.prefs,
         channel         = channel,
         count           = count,
-        formatter       = formatter,
         lines           = lines,
     )
 
@@ -120,7 +118,7 @@
     # display calendar
     return templates.render_to_response("channel_calendar",
         req             = request,
-        timezone        = timezone,
+        prefs           = request.prefs,
         channel         = channel,
         calendar        = calendar.Calendar(),
         month           = target.date(),
@@ -144,9 +142,8 @@
 
     return templates.render_to_response("channel_date",
         req             = request,
-        timezone        = timezone,
+        prefs           = request.prefs,
         channel         = channel,
-        formatter       = formatter,
         date            = date,
         lines           = lines,
     )
--- a/helpers.py	Mon Feb 09 07:09:00 2009 +0200
+++ b/helpers.py	Mon Feb 09 07:15:19 2009 +0200
@@ -46,7 +46,7 @@
             Build current time
         """
 
-        return self.ctx['timezone'].localize(datetime.datetime.now())
+        return self.ctx['prefs'][preferences.timezone].localize(datetime.datetime.now())
 
     def today (self) :
         """
--- a/preferences.py	Mon Feb 09 07:09:00 2009 +0200
+++ b/preferences.py	Mon Feb 09 07:15:19 2009 +0200
@@ -70,10 +70,15 @@
     
     def get (self, pref) :
         """
-            Return the value for the given Preference
+            Return the value for the given Preference, or preference name
         """
         
-        return self.values[pref.name]
+        # Preference -> name
+        if isinstance(pref, Preference) :
+            pref = pref.name
+        
+        # look up
+        return self.values[pref]
 
     # support dict-access
     __getitem__ = get
--- a/templates/channel.tmpl	Mon Feb 09 07:09:00 2009 +0200
+++ b/templates/channel.tmpl	Mon Feb 09 07:15:19 2009 +0200
@@ -49,5 +49,5 @@
 ${next.body()}
 
 <%def name="footer_right()">
-    All times are in <strong>${h.tz_name(timezone)}</strong>
+    All times are in <strong>${h.tz_name(prefs['timezone'])}</strong>
 </%def>
--- a/templates/preferences.tmpl	Mon Feb 09 07:09:00 2009 +0200
+++ b/templates/preferences.tmpl	Mon Feb 09 07:15:19 2009 +0200
@@ -10,20 +10,20 @@
             <label for="timezone">Timezone:</label>
             <select name="timezone">
             % for tz_name in timezones :
-                <option${' selected="selected"' if tz_name == prefs[preferences.timezone].zone else ''}>${tz_name}</option>
+                <option${' selected="selected"' if tz_name == prefs['timezone'].zone else ''}>${tz_name}</option>
             % endfor
             </select>
         </p>
 
         <p>
             <label for="date_format">Date format:</label>
-            <input type="text" name="date_format" value="${prefs[preferences.date_format]}" />
+            <input type="text" name="date_format" value="${prefs['date_format']}" />
             <span class="example">(${h.fmt_date()})</span>
         </p>
         
         <p>
             <label for="time_format">Time format:</label>
-            <input type="text" name="time_format" value="${prefs[preferences.time_format]}" />
+            <input type="text" name="time_format" value="${prefs['time_format']}" />
             <span class="example">(${h.fmt_time()})</span>
         </p>