summaryrefslogtreecommitdiff
path: root/alot/settings
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2012-03-31 16:24:09 +0100
committerPatrick Totzke <patricktotzke@gmail.com>2012-03-31 16:24:09 +0100
commit32e2d2eb9289f14907d1a4e9b239f52a9e2bbf36 (patch)
treea3e061dad45c9d12eb4d510715f8fada45b33f5a /alot/settings
parentd503b1c2cb81b92e8ddf3fd2f431c0cb3e82ab08 (diff)
introduce represent_datetime
settings helper that turns a given datetime obj into a unicode string representation according to locale and user settings: 1) look if a fixed 'timestamp_format' is given in the config 2) check if a 'timestamp_format' hook is defined 3) use :function:`pretty_datetime` as fallback This introduces a new hook 'timestamp_format' that accepts a datetime as only argument and returns a string cf issue #415
Diffstat (limited to 'alot/settings')
-rw-r--r--alot/settings/__init__.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/alot/settings/__init__.py b/alot/settings/__init__.py
index f62dfa0d..b405dfc5 100644
--- a/alot/settings/__init__.py
+++ b/alot/settings/__init__.py
@@ -11,12 +11,14 @@ from configobj import ConfigObj, Section
from alot.account import SendmailAccount
from alot.addressbooks import MatchSdtoutAddressbook, AbookAddressBook
+from alot.helper import pretty_datetime, string_decode
from errors import ConfigError
from utils import read_config
from checks import mail_container
from theme import Theme
+
DEFAULTSPATH = os.path.join(os.path.dirname(__file__), '..', 'defaults')
@@ -337,5 +339,24 @@ class SettingsManager(object):
"""
return mailcap.findmatch(self._mailcaps, *args, **kwargs)
+ def represent_datetime(self, d):
+ """
+ turns a given datetime obj into a unicode string representation.
+ This will:
+ 1) look if a fixed 'timestamp_format' is given in the config
+ 2) check if a 'timestamp_format' hook is defined
+ 3) use :function:`pretty_datetime` as fallback
+ """
+
+ fixed_format = self.get('timestamp_format')
+ if fixed_format:
+ rep = string_decode(d.strftime(fixed_format), 'UTF-8')
+ else:
+ format_hook = self.get_hook('timestamp_format')
+ if format_hook:
+ rep = string_decode(format_hook(d), 'UTF-8')
+ else:
+ rep = pretty_datetime(d)
+ return rep
settings = SettingsManager()