1.1 --- a/imiptools/config.py Sat Oct 24 22:19:17 2015 +0200
1.2 +++ b/imiptools/config.py Sun Oct 25 01:24:56 2015 +0200
1.3 @@ -61,6 +61,10 @@
1.4 # allowing users to choose more appropriate settings themselves.
1.5 # See: docs/preferences.txt
1.6
1.7 +# Default language for messages.
1.8 +
1.9 +LANG = "en"
1.10 +
1.11 # Do users participate in the calendar system by default?
1.12
1.13 PARTICIPATING_DEFAULT = "participate"
2.1 --- a/imiptools/profile.py Sat Oct 24 22:19:17 2015 +0200
2.2 +++ b/imiptools/profile.py Sun Oct 25 01:24:56 2015 +0200
2.3 @@ -19,30 +19,54 @@
2.4 this program. If not, see <http://www.gnu.org/licenses/>.
2.5 """
2.6
2.7 -from imiptools.config import PREFERENCES_DIR
2.8 +from imiptools import config
2.9 +from imiptools.dates import get_default_timezone
2.10 from imiptools.filesys import fix_permissions, FileBase
2.11 from os.path import exists, isdir
2.12 -from os import makedirs
2.13 +from os import listdir, makedirs
2.14
2.15 class Preferences(FileBase):
2.16
2.17 "A simple preferences file manager."
2.18
2.19 + # See: docs/preferences.txt
2.20 +
2.21 + known_keys = {
2.22 + "CN" : "",
2.23 + "LANG" : config.LANG,
2.24 + "TZID" : get_default_timezone(),
2.25 + "add_method_response" : config.ADD_RESPONSE_DEFAULT,
2.26 + "event_refreshing" : config.REFRESHING_DEFAULT,
2.27 + "freebusy_bundling" : config.BUNDLING_DEFAULT,
2.28 + "freebusy_messages" : config.NOTIFYING_DEFAULT,
2.29 + "freebusy_offers" : config.FREEBUSY_OFFER_DEFAULT,
2.30 + "freebusy_publishing" : config.PUBLISHING_DEFAULT,
2.31 + "freebusy_sharing" : config.SHARING_DEFAULT,
2.32 + "incoming" : config.INCOMING_DEFAULT,
2.33 + "organiser_replacement" : config.ORGANISER_REPLACEMENT_DEFAULT,
2.34 + "participating" : config.PARTICIPATING_DEFAULT,
2.35 + "permitted_times" : None,
2.36 + }
2.37 +
2.38 def __init__(self, user, store_dir=None):
2.39 - FileBase.__init__(self, store_dir or PREFERENCES_DIR)
2.40 + FileBase.__init__(self, store_dir or config.PREFERENCES_DIR)
2.41 self.user = user
2.42
2.43 - def get(self, name, default=None):
2.44 + def get(self, name, default=None, config_default=False):
2.45
2.46 """
2.47 Return the value for 'name', with absent entries providing a default of
2.48 - None or any indicated 'default'.
2.49 + None or any indicated 'default' or, if 'config_default' is set to a true
2.50 + value, the default value from the config module.
2.51 """
2.52
2.53 try:
2.54 return self[name]
2.55 except KeyError:
2.56 - return default
2.57 + if config_default:
2.58 + return self.known_keys.get(name, default)
2.59 + else:
2.60 + return default
2.61
2.62 def get_all(self, names):
2.63
2.64 @@ -68,6 +92,30 @@
2.65 except KeyError:
2.66 return False
2.67
2.68 + def keys(self):
2.69 +
2.70 + "Return all entry names in the preferences."
2.71 +
2.72 + filename = self.get_object_in_store(self.user)
2.73 + if not filename or not isdir(filename):
2.74 + return []
2.75 +
2.76 + return listdir(filename)
2.77 +
2.78 + def items(self, all_known=False, default=None, config_default=False):
2.79 +
2.80 + """
2.81 + Return all entries in the preferences or all known entries if
2.82 + 'all_known' is set to a true value, with absent entries providing a
2.83 + default of None or any indicated 'default' or, if 'config_default' is
2.84 + set to a true value, the default value from the config module.
2.85 + """
2.86 +
2.87 + l = []
2.88 + for key in (all_known and self.known_keys or self).keys():
2.89 + l.append((key, self.get(key, default, config_default)))
2.90 + return l
2.91 +
2.92 def __getitem__(self, name):
2.93
2.94 "Return the value for 'name', raising a KeyError if absent."
3.1 --- a/imipweb/resource.py Sat Oct 24 22:19:17 2015 +0200
3.2 +++ b/imipweb/resource.py Sun Oct 25 01:24:56 2015 +0200
3.3 @@ -184,7 +184,7 @@
3.4
3.5 def get_user_locale(self):
3.6 if not self.locale:
3.7 - self.locale = self.get_preferences().get("LANG", "en")
3.8 + self.locale = self.get_preferences().get("LANG", "en", True)
3.9 return self.locale
3.10
3.11 # Prettyprinting of dates and times.