Grid: Age -> Created, for dates further than a week ago, display actual date

This commit is contained in:
Kanwei Li
2009-08-03 18:57:13 -04:00
parent 4ce49a8da4
commit fa0a7f1662
2 changed files with 10 additions and 4 deletions
+2 -2
View File
@@ -47,8 +47,8 @@ class HistoryListGrid( grids.Grid ):
attach_popup=True ),
DatasetsByStateColumn( "Datasets (by state)", ncells=4 ),
StatusColumn( "Status", attach_popup=False ),
grids.GridColumn( "Age", key="create_time", format=time_ago ),
grids.GridColumn( "Last update", key="update_time", format=time_ago ),
grids.GridColumn( "Created", key="create_time", format=time_ago ),
grids.GridColumn( "Last Updated", key="update_time", format=time_ago ),
# Valid for filtering but invisible
grids.GridColumn( "Deleted", key="deleted", visible=False )
]
+8 -2
View File
@@ -3,10 +3,16 @@ import pkg_resources
pkg_resources.require( "WebHelpers" )
from webhelpers import *
from datetime import datetime
from datetime import datetime, timedelta
# If the date is more than one week ago, then display the actual date instead of in words
def time_ago( x ):
return date.distance_of_time_in_words( x, datetime.utcnow() )
delta = timedelta(weeks=1)
if (datetime.utcnow() - x) > delta: # Greater than a week difference
return x.strftime("%b %d, %Y")
else:
return date.distance_of_time_in_words( x, datetime.utcnow() ) + " ago"
def iff( a, b, c ):
if a: