handlers.py
changeset 59 8ec729c5d998
parent 56 69494e4a5ecc
child 62 e7ca94b94a4e
--- a/handlers.py	Mon Feb 09 06:19:12 2009 +0200
+++ b/handlers.py	Mon Feb 09 06:56:04 2009 +0200
@@ -26,6 +26,34 @@
         req             = request,
     )
 
+# XXX: fix this namespace crap
+@preferences.handler()
+def preferences_ (request) :
+    """
+        Preferences editor
+    """
+
+    # POST?
+    if request.is_post() :
+        # update any modified preferences
+        for pref in preferences.pref_list :
+            # get+parse new POST'd value
+            # XXX: this doesn't postprocess
+            new_value = pref.parse(request.get_post(pref.name))
+
+            # update if changed
+            if new_value != request.prefs[pref] :
+                request.prefs.set(pref.name, new_value)
+
+    # render
+    return templates.render_to_response("preferences",
+        req             = request,
+        prefs           = request.prefs,
+        preferences     = prefs,
+        timezone        = request.prefs[prefs.timezone],
+        timezones       = pytz.common_timezones,
+    )
+
 def channel_select (request, channel) :
     """
         Redirect to the appropriate channel_view
@@ -33,8 +61,8 @@
    
     return http.Redirect(urls.channel_view.build(request, channel=channel))
 
-@preferences.handler(prefs.Formatter, prefs.Timezone)
-def channel_view (request, channel, count, formatter, timezone) :
+@preferences.handler(prefs.formatter)
+def channel_view (request, channel, count, formatter) :
     """
         The main channel view page, display the most important info, and all requisite links
     """
@@ -47,7 +75,7 @@
 
     return templates.render_to_response("channel_view",
         req             = request,
-        timezone        = timezone,
+        timezone        = request.prefs[prefs.timezone],
         channel         = channel,
         count           = count,
         formatter       = formatter,
@@ -70,7 +98,7 @@
     else :
         raise http.ResponseError("Unknown filetype %r" % format)
 
-@preferences.handler(prefs.Timezone)
+@preferences.handler(prefs.timezone)
 def channel_calendar (request, channel, year, month, timezone) :
     """
         Display a list of avilable logs for some month
@@ -99,7 +127,7 @@
         days            = days,
     )
 
-@preferences.handler(prefs.Formatter, prefs.Timezone)
+@preferences.handler(prefs.formatter, prefs.timezone)
 def channel_date (request, channel, date, formatter, timezone) :
     """
         Display all log data for the given date