comparison rhodecode/lib/helpers.py @ 635:fd63782c4426 beta

Fixed age, for new vcs implementation. Removed all obsolete date formatters Added simplegit middleware. fixed deps added scm type icon to main page
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 25 Oct 2010 03:19:01 +0200
parents 05528ad948c4
children ffd07396d315
comparison
equal deleted inserted replaced
634:0d18cf02278a 635:fd63782c4426
21 from webhelpers.pylonslib import Flash as _Flash 21 from webhelpers.pylonslib import Flash as _Flash
22 from webhelpers.pylonslib.secure_form import secure_form 22 from webhelpers.pylonslib.secure_form import secure_form
23 from webhelpers.text import chop_at, collapse, convert_accented_entities, \ 23 from webhelpers.text import chop_at, collapse, convert_accented_entities, \
24 convert_misc_entities, lchop, plural, rchop, remove_formatting, \ 24 convert_misc_entities, lchop, plural, rchop, remove_formatting, \
25 replace_whitespace, urlify, truncate, wrap_paragraphs 25 replace_whitespace, urlify, truncate, wrap_paragraphs
26 from webhelpers.date import time_ago_in_words
26 27
27 #Custom helpers here :) 28 #Custom helpers here :)
28 class _Link(object): 29 class _Link(object):
29 ''' 30 '''
30 Make a url based on label and url with help of url_for 31 Make a url based on label and url with help of url_for
315 316
316 317
317 flash = _Flash() 318 flash = _Flash()
318 319
319 320
320 #=============================================================================== 321 #==============================================================================
321 # MERCURIAL FILTERS available via h. 322 # MERCURIAL FILTERS available via h.
322 #=============================================================================== 323 #==============================================================================
323 from mercurial import util 324 from mercurial import util
324 from mercurial.templatefilters import age as _age, person as _person 325 from mercurial.templatefilters import person as _person
325 326
326 age = lambda x:x 327
328
329 def _age(curdate):
330 """turns a datetime into an age string."""
331
332 from datetime import timedelta, datetime
333 agescales = [("year", 3600 * 24 * 365),
334 ("month", 3600 * 24 * 30),
335 #("week", 3600 * 24 * 7),
336 ("day", 3600 * 24),
337 ("hour", 3600),
338 ("minute", 60),
339 ("second", 1)]
340
341 age = datetime.now() - curdate
342 age_seconds = (age.days * agescales[2][1]) + age.seconds
343
344 pos = 1
345 for scale in agescales:
346 if scale[1] <= age_seconds:
347 return time_ago_in_words(curdate, agescales[pos][0])
348 pos += 1
349
350 age = lambda x:_age(x)
327 capitalize = lambda x: x.capitalize() 351 capitalize = lambda x: x.capitalize()
328 date = lambda x: util.datestr(x)
329 email = util.email 352 email = util.email
330 email_or_none = lambda x: util.email(x) if util.email(x) != x else None 353 email_or_none = lambda x: util.email(x) if util.email(x) != x else None
331 person = lambda x: _person(x) 354 person = lambda x: _person(x)
332 hgdate = lambda x: "%d %d" % x 355
333 isodate = lambda x: util.datestr(x, '%Y-%m-%d %H:%M %1%2') 356 #==============================================================================
334 isodatesec = lambda x: util.datestr(x, '%Y-%m-%d %H:%M:%S %1%2')
335 localdate = lambda x: (x[0], util.makedate()[1])
336 rfc822date = lambda x: x#util.datestr(x, "%a, %d %b %Y %H:%M:%S %1%2")
337 rfc822date_notz = lambda x: x#util.datestr(x, "%a, %d %b %Y %H:%M:%S")
338 rfc3339date = lambda x: util.datestr(x, "%Y-%m-%dT%H:%M:%S%1:%2")
339 time_ago = lambda x: util.datestr(_age(x), "%a, %d %b %Y %H:%M:%S %1%2")
340
341
342 #===============================================================================
343 # PERMS 357 # PERMS
344 #=============================================================================== 358 #==============================================================================
345 from rhodecode.lib.auth import HasPermissionAny, HasPermissionAll, \ 359 from rhodecode.lib.auth import HasPermissionAny, HasPermissionAll, \
346 HasRepoPermissionAny, HasRepoPermissionAll 360 HasRepoPermissionAny, HasRepoPermissionAll
347 361
348 #=============================================================================== 362 #==============================================================================
349 # GRAVATAR URL 363 # GRAVATAR URL
350 #=============================================================================== 364 #==============================================================================
351 import hashlib 365 import hashlib
352 import urllib 366 import urllib
353 from pylons import request 367 from pylons import request
354 368
355 def gravatar_url(email_address, size=30): 369 def gravatar_url(email_address, size=30):