38
35
log = logging.getLogger("loggerhead.controllers")
41
return '%d years' % (int(delta.days // 365.25),)
43
return '%d days' % delta.days
49
seg.append('%d days' % delta.days)
50
hrs = delta.seconds // 3600
51
mins = (delta.seconds % 3600) // 60
56
seg.append('%d hours' % hrs)
60
seg.append('1 minute')
62
seg.append('%d minutes' % mins)
64
seg.append('less than a minute')
69
now = datetime.datetime.now()
70
return timespan(now - timestamp) + ' ago'
40
73
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):
81
_g_format = '%Y-%m-%d @ %H:%M'
83
def format_date(date):
84
if _g_format == 'fancy':
85
return fancy_format_date(date)
86
return date.strftime(_g_format)
88
def fancy_format_date(date):
75
89
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
91
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))
93
return date.strftime('%d %b %H:%M')
95
def set_date_format(format):
124
100
class Container (object):
131
107
setattr(self, key, value)
132
108
for key, value in kw.iteritems():
133
109
setattr(self, key, value)
135
111
def __repr__(self):
137
113
for key, value in self.__dict__.iteritems():
205
181
given a position in a maximum range, return a list of negative and positive
206
182
jump factors for an hgweb-style triple-factor geometric scan.
208
184
for example, with pos=20 and max=500, the range would be:
209
185
[ -10, -3, -1, 1, 3, 10, 30, 100, 300 ]
211
187
i admit this is a very strange way of jumping through revisions. i didn't
348
324
navigation.count = len(navigation.revid_list)
349
325
navigation.page_position = navigation.position // navigation.pagesize + 1
350
326
navigation.page_count = (len(navigation.revid_list) + (navigation.pagesize - 1)) // navigation.pagesize
352
328
def get_offset(offset):
353
329
if (navigation.position + offset < 0) or (navigation.position + offset > navigation.count - 1):
355
331
return navigation.revid_list[navigation.position + offset]
357
333
navigation.prev_page_revid = get_offset(-1 * navigation.pagesize)
358
334
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 }
336
params = { 'file_id': navigation.file_id }
366
337
if getattr(navigation, 'query', None) is not None:
367
338
params['q'] = navigation.query
369
if getattr(navigation, 'start_revid', None) is not None:
370
params['start_revid'] = start_revno
340
params['start_revid'] = navigation.start_revid
372
342
if navigation.prev_page_revid:
373
navigation.prev_page_url = navigation.branch.context_url(
374
[navigation.scan_url, prev_page_revno], **params)
343
navigation.prev_page_url = navigation.branch.url([ navigation.scan_url, navigation.prev_page_revid ], **get_context(**params))
375
344
if navigation.next_page_revid:
376
navigation.next_page_url = navigation.branch.context_url(
377
[navigation.scan_url, next_page_revno], **params)
345
navigation.next_page_url = navigation.branch.url([ navigation.scan_url, navigation.next_page_revid ], **get_context(**params))
380
348
def log_exception(log):
453
421
# current location along the navigation path (while browsing)
454
422
# - starting revid (start_revid)
455
423
# 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.
424
# the original revision) -- this may not be along the primary revision
425
# path since the user may have navigated into a branch
459
# the file being looked at
461
427
# if navigating the revisions that touched a file
463
429
# if navigating the revisions that matched a search query
474
440
# for re-ordering an existing page by different sort
476
442
t_context = threading.local()
477
_valid = ('start_revid', 'file_id', 'filter_file_id', 'q', 'remember',
478
'compare_revid', 'sort')
443
_valid = ('start_revid', 'file_id', 'q', 'remember', 'compare_revid', 'sort')
481
446
def set_context(map):
485
450
def get_context(**overrides):
487
Soon to be deprecated.
490
452
return a context map that may be overriden by specific values passed in,
491
453
but only contains keys from the list of valid context keys.
493
455
if 'clear' is set, only the 'remember' context value will be added, and
494
456
all other context will be omitted.