From 6da2ade5e30011b139756d8f4504e9a582c81bf1 Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Thu, 20 May 2010 17:47:31 +0000 Subject: [PATCH] Format date in Last Changed column in views according to preference setting svn: r15426 --- src/Utils.py | 16 ++++++++++++++++ src/gui/views/treemodels/eventmodel.py | 6 +----- src/gui/views/treemodels/familymodel.py | 6 ++---- src/gui/views/treemodels/mediamodel.py | 6 ++---- src/gui/views/treemodels/notemodel.py | 6 ++---- src/gui/views/treemodels/peoplemodel.py | 8 ++------ src/gui/views/treemodels/placemodel.py | 6 ++---- src/gui/views/treemodels/repomodel.py | 6 ++---- src/gui/views/treemodels/sourcemodel.py | 6 ++---- 9 files changed, 31 insertions(+), 35 deletions(-) diff --git a/src/Utils.py b/src/Utils.py index 7c52d7d6b..84966c2ac 100644 --- a/src/Utils.py +++ b/src/Utils.py @@ -47,6 +47,8 @@ from gen.display.name import displayer as name_displayer import gen.lib import Errors from GrampsLocale import codeset +from Date import Date +import DateHandler from const import TEMP_DIR, USER_HOME, GRAMPS_UUID import constfunc @@ -1376,3 +1378,17 @@ def navigation_label(db, nav_type, handle): label = '[%s] %s' % (obj.get_gramps_id(), label) return (label, obj) + +#------------------------------------------------------------------------- +# +# Format the date and time displayed in the Last Changed column in views. +# +#------------------------------------------------------------------------- +def format_time(secs): + """ + Format a time in seconds as a date in the preferred date format and a + 24 hour time as hh:mm:ss. + """ + t = time.localtime(secs) + d = Date(t.tm_year, t.tm_mon, t.tm_mday) + return DateHandler.displayer.display(d) + time.strftime(' %X', t) diff --git a/src/gui/views/treemodels/eventmodel.py b/src/gui/views/treemodels/eventmodel.py index e98e6d52a..acebba9ec 100644 --- a/src/gui/views/treemodels/eventmodel.py +++ b/src/gui/views/treemodels/eventmodel.py @@ -24,7 +24,6 @@ # python modules # #------------------------------------------------------------------------- -import time import cgi import logging log = logging.getLogger(".") @@ -42,7 +41,6 @@ import gtk # #------------------------------------------------------------------------- import ToolTips -import GrampsLocale import DateHandler import gen.lib import Utils @@ -154,9 +152,7 @@ class EventModel(FlatBaseModel): return "%012x" % data[COLUMN_CHANGE] def column_change(self,data): - return unicode(time.strftime('%x %X', - time.localtime(data[COLUMN_CHANGE])), - GrampsLocale.codeset) + return Utils.format_time(data[COLUMN_CHANGE]) def column_tooltip(self,data): try: diff --git a/src/gui/views/treemodels/familymodel.py b/src/gui/views/treemodels/familymodel.py index 3c5f1f310..3d7f22e74 100644 --- a/src/gui/views/treemodels/familymodel.py +++ b/src/gui/views/treemodels/familymodel.py @@ -24,7 +24,6 @@ # python modules # #------------------------------------------------------------------------- -import time import logging log = logging.getLogger(".") @@ -42,7 +41,7 @@ import gtk #------------------------------------------------------------------------- import const import ToolTips -import GrampsLocale +import Utils import DateHandler from gen.display.name import displayer as name_displayer import gen.lib @@ -153,8 +152,7 @@ class FamilyModel(FlatBaseModel): return "%012x" % data[12] def column_change(self, data): - return unicode(time.strftime('%x %X', time.localtime(data[12])), - GrampsLocale.codeset) + return Utils.format_time(data[12]) def column_marker_text(self, data): try: diff --git a/src/gui/views/treemodels/mediamodel.py b/src/gui/views/treemodels/mediamodel.py index 2f58ed56b..e8af129ce 100644 --- a/src/gui/views/treemodels/mediamodel.py +++ b/src/gui/views/treemodels/mediamodel.py @@ -24,7 +24,6 @@ # python modules # #------------------------------------------------------------------------- -import time from gen.ggettext import gettext as _ import logging log = logging.getLogger(".") @@ -43,7 +42,7 @@ import gtk #------------------------------------------------------------------------- import const import ToolTips -import GrampsLocale +import Utils import DateHandler import gen.lib from gui.views.treemodels.flatbasemodel import FlatBaseModel @@ -130,8 +129,7 @@ class MediaModel(FlatBaseModel): return "%012x" % data[8] def column_change(self,data): - return unicode(time.strftime('%x %X',time.localtime(data[8])), - GrampsLocale.codeset) + return Utils.format_time(data[8]) def column_tooltip(self,data): if const.USE_TIPS: diff --git a/src/gui/views/treemodels/notemodel.py b/src/gui/views/treemodels/notemodel.py index 648158157..61f4f76a0 100644 --- a/src/gui/views/treemodels/notemodel.py +++ b/src/gui/views/treemodels/notemodel.py @@ -24,7 +24,6 @@ # python modules # #------------------------------------------------------------------------- -import time import logging _LOG = logging.getLogger(".gui.notemodel") @@ -40,7 +39,7 @@ import gtk # GRAMPS modules # #------------------------------------------------------------------------- -import GrampsLocale +import Utils from gui.views.treemodels.flatbasemodel import FlatBaseModel from gen.lib import (Note, NoteType, MarkerType, StyledText) @@ -133,5 +132,4 @@ class NoteModel(FlatBaseModel): return "%012x" % data[Note.POS_CHANGE] def column_change(self,data): - return unicode(time.strftime('%x %X',time.localtime( - data[Note.POS_CHANGE])), GrampsLocale.codeset) + return Utils.format_time(data[Note.POS_CHANGE]) diff --git a/src/gui/views/treemodels/peoplemodel.py b/src/gui/views/treemodels/peoplemodel.py index 65a907a52..26afb5413 100644 --- a/src/gui/views/treemodels/peoplemodel.py +++ b/src/gui/views/treemodels/peoplemodel.py @@ -33,7 +33,6 @@ TreeModel for the GRAMPS Person tree. # #------------------------------------------------------------------------- from gen.ggettext import gettext as _ -import time import cgi #------------------------------------------------------------------------- @@ -61,7 +60,7 @@ from gen.lib import Name, EventRef, EventType, EventRoleType, MarkerType from gen.display.name import displayer as name_displayer import DateHandler import ToolTips -import GrampsLocale +import Utils from Lru import LRU from gui.views.treemodels.flatbasemodel import FlatBaseModel from gui.views.treemodels.treebasemodel import TreeBaseModel @@ -223,10 +222,7 @@ class PeopleBaseModel(object): return "%012x" % data[COLUMN_CHANGE] def column_change(self, data): - return unicode( - time.strftime('%x %X', - time.localtime(data[COLUMN_CHANGE])), - GrampsLocale.codeset) + return Utils.format_time(data[COLUMN_CHANGE]) def column_gender(self, data): return PeopleBaseModel._GENDER[data[COLUMN_GENDER]] diff --git a/src/gui/views/treemodels/placemodel.py b/src/gui/views/treemodels/placemodel.py index 91cd16818..9b3be44a5 100644 --- a/src/gui/views/treemodels/placemodel.py +++ b/src/gui/views/treemodels/placemodel.py @@ -30,7 +30,6 @@ Place Model. # python modules # #------------------------------------------------------------------------- -import time import cgi import logging _LOG = logging.getLogger(".gui.views.treemodels.placemodel") @@ -49,7 +48,7 @@ import gtk #------------------------------------------------------------------------- import const import ToolTips -import GrampsLocale +import Utils from gui.views.treemodels.flatbasemodel import FlatBaseModel from gui.views.treemodels.treebasemodel import TreeBaseModel @@ -212,8 +211,7 @@ class PlaceBaseModel(object): return "%012x" % data[11] def column_change(self, data): - return unicode(time.strftime('%x %X',time.localtime(data[11])), - GrampsLocale.codeset) + return Utils.format_time(data[11]) def column_tooltip(self, data): if const.USE_TIPS: diff --git a/src/gui/views/treemodels/repomodel.py b/src/gui/views/treemodels/repomodel.py index 2d5ac4738..b9f5fefaa 100644 --- a/src/gui/views/treemodels/repomodel.py +++ b/src/gui/views/treemodels/repomodel.py @@ -24,7 +24,6 @@ # python modules # #------------------------------------------------------------------------- -import time import logging log = logging.getLogger(".") @@ -41,7 +40,7 @@ import gtk # #------------------------------------------------------------------------- import gen.lib -import GrampsLocale +import Utils from gui.views.treemodels.flatbasemodel import FlatBaseModel #------------------------------------------------------------------------- @@ -220,5 +219,4 @@ class RepositoryModel(FlatBaseModel): return "%012x" % data[7] def column_change(self,data): - return unicode(time.strftime('%x %X',time.localtime(data[7])), - GrampsLocale.codeset) + return Utils.format_time(data[7]) diff --git a/src/gui/views/treemodels/sourcemodel.py b/src/gui/views/treemodels/sourcemodel.py index c985acf55..d62926663 100644 --- a/src/gui/views/treemodels/sourcemodel.py +++ b/src/gui/views/treemodels/sourcemodel.py @@ -24,7 +24,6 @@ # python modules # #------------------------------------------------------------------------- -import time import logging log = logging.getLogger(".") @@ -42,7 +41,7 @@ import gtk #------------------------------------------------------------------------- import const import ToolTips -import GrampsLocale +import Utils from gui.views.treemodels.flatbasemodel import FlatBaseModel #------------------------------------------------------------------------- @@ -99,8 +98,7 @@ class SourceModel(FlatBaseModel): return unicode(data[4]) def column_change(self,data): - return unicode(time.strftime('%x %X',time.localtime(data[8])), - GrampsLocale.codeset) + return Utils.format_time(data[8]) def sort_change(self,data): return "%012x" % data[8]