38
33
log = logging.getLogger("loggerhead.controllers")
39
return '%d years' % (int(delta.days // 365.25),)
41
return '%d days' % delta.days
47
seg.append('%d days' % delta.days)
48
hrs = delta.seconds // 3600
49
mins = (delta.seconds % 3600) // 60
54
seg.append('%d hours' % hrs)
58
seg.append('1 minute')
60
seg.append('%d minutes' % mins)
62
seg.append('less than a minute')
67
now = datetime.datetime.now()
68
return timespan(now - timestamp) + ' ago'
40
71
def fix_year(year):
49
# date_day -- just the day
50
# date_time -- full date with time
52
# displaydate -- for use in sentences
53
# approximatedate -- for use in tables
55
# displaydate and approximatedate return an elementtree <span> Element
56
# with the full date in a tooltip.
59
return value.strftime('%Y-%m-%d')
63
return value.strftime('%Y-%m-%d %T')
66
def _displaydate(date):
67
delta = abs(datetime.datetime.now() - date)
68
if delta > datetime.timedelta(1, 0, 0):
69
# far in the past or future, display the date
70
return 'on ' + date_day(date)
71
return _approximatedate(date)
74
def _approximatedate(date):
79
_g_format = '%Y-%m-%d @ %H:%M'
81
def format_date(date):
82
if _g_format == 'fancy':
83
return fancy_format_date(date)
84
return date.strftime(_g_format)
86
def fancy_format_date(date):
75
87
delta = datetime.datetime.now() - date
76
if abs(delta) > datetime.timedelta(1, 0, 0):
77
# far in the past or future, display the date
79
future = delta < datetime.timedelta(0, 0, 0)
82
hours = delta.seconds / 3600
83
minutes = (delta.seconds - (3600*hours)) / 60
84
seconds = delta.seconds % 60
89
return date.strftime('%d %b %Y')
102
result += '%s %s' % (amount, unit)
108
def _wrap_with_date_time_title(date, formatted_date):
109
elem = ET.Element("span")
110
elem.text = formatted_date
111
elem.set("title", date_time(date))
115
def approximatedate(date):
116
#FIXME: Returns an object instead of a string
117
return _wrap_with_date_time_title(date, _approximatedate(date))
120
def displaydate(date):
121
return _wrap_with_date_time_title(date, _displaydate(date))
91
return date.strftime('%d %b %H:%M')
93
def set_date_format(format):
124
98
class Container (object):
357
331
navigation.prev_page_revid = get_offset(-1 * navigation.pagesize)
358
332
navigation.next_page_revid = get_offset(1 * navigation.pagesize)
359
prev_page_revno = navigation.branch.history.get_revno(
360
navigation.prev_page_revid)
361
next_page_revno = navigation.branch.history.get_revno(
362
navigation.next_page_revid)
363
start_revno = navigation.branch._history.get_revno(navigation.start_revid)
365
params = { 'filter_file_id': navigation.filter_file_id }
334
params = { 'file_id': navigation.file_id }
366
335
if getattr(navigation, 'query', None) is not None:
367
336
params['q'] = navigation.query
369
if getattr(navigation, 'start_revid', None) is not None:
370
params['start_revid'] = start_revno
338
params['start_revid'] = navigation.start_revid
372
340
if navigation.prev_page_revid:
373
navigation.prev_page_url = navigation.branch.context_url(
374
[navigation.scan_url, prev_page_revno], **params)
341
navigation.prev_page_url = navigation.branch.url([ navigation.scan_url, navigation.prev_page_revid ], **get_context(**params))
375
342
if navigation.next_page_revid:
376
navigation.next_page_url = navigation.branch.context_url(
377
[navigation.scan_url, next_page_revno], **params)
343
navigation.next_page_url = navigation.branch.url([ navigation.scan_url, navigation.next_page_revid ], **get_context(**params))
380
346
def log_exception(log):
453
419
# current location along the navigation path (while browsing)
454
420
# - starting revid (start_revid)
455
421
# the current beginning of navigation (navigation continues back to
456
# the original revision) -- this defines an 'alternate mainline'
457
# when the user navigates into a branch.
422
# the original revision) -- this may not be along the primary revision
423
# path since the user may have navigated into a branch
459
# the file being looked at
461
425
# if navigating the revisions that touched a file
463
427
# if navigating the revisions that matched a search query
474
438
# for re-ordering an existing page by different sort
476
440
t_context = threading.local()
477
_valid = ('start_revid', 'file_id', 'filter_file_id', 'q', 'remember',
478
'compare_revid', 'sort')
441
_valid = ('start_revid', 'file_id', 'q', 'remember', 'compare_revid', 'sort')
481
444
def set_context(map):