diff -r ce028d356e1f -r 8ec729c5d998 preferences.py --- a/preferences.py Mon Feb 09 06:19:12 2009 +0200 +++ b/preferences.py Mon Feb 09 06:56:04 2009 +0200 @@ -67,14 +67,17 @@ self.values = dict( (name, self.preferences.pref_map[name].process(self, value)) for name, value in self.values.iteritems() ) - + def get (self, pref) : """ Return the value for the given Preference """ return self.values[pref.name] - + + # support dict-access + __getitem__ = get + def set (self, name, value_obj) : """ Set a new value for the given preference @@ -154,6 +157,10 @@ # load preferences cookies, prefs = self.load(request) + # bind to request.prefs + # XXX: better way to do this? :/ + request.prefs = prefs + # update args with new ones args.update(((pref.name, prefs.get(pref)) for pref in pref_list)) @@ -162,6 +169,9 @@ # set cookies? if prefs.set_cookies : + if not cookies : + cookies = Cookie.SimpleCookie('') + # update cookies for key, value in prefs.set_cookies.iteritems() : cookies[key] = value @@ -201,7 +211,7 @@ name = 'date_format' # default value - default = "%Y-%m%d" + default = "%Y-%m-%d" class Timezone (Preference) : """ @@ -256,22 +266,27 @@ class LogFormatter -> fmt_name """ - return fmt.name + return fmt_cls.name def process (self, prefs, fmt_cls) : """ class LogFormatter -> LogFormatter(tz, time_fmt) """ - return fmt_cls(prefs.get(Timezone), prefs.get(TimeFormat)) + return fmt_cls(prefs[timezone], prefs[time_format]) # and then build the Preferences object import log_formatter +time_format = TimeFormat() +date_format = DateFormat() +timezone = Timezone() +formatter = Formatter(log_formatter.FORMATTERS, log_formatter.IrssiFormatter) + preferences = Preferences([ - TimeFormat(), - DateFormat(), - Timezone(), - Formatter(log_formatter.FORMATTERS, log_formatter.IrssiFormatter), + time_format, + date_format, + timezone, + formatter, ])