##// END OF EJS Templates
helpers: cleanup gravatars code.
marcink -
r4478:748acd24 default
parent child Browse files
Show More
@@ -1357,8 +1357,7 b' class InitialsGravatar(object):'
1357 return "data:image/svg+xml;base64,%s" % base64.b64encode(img_data)
1357 return "data:image/svg+xml;base64,%s" % base64.b64encode(img_data)
1358
1358
1359
1359
1360 def initials_gravatar(email_address, first_name, last_name, size=30, store_on_disk=False):
1360 def initials_gravatar(request, email_address, first_name, last_name, size=30, store_on_disk=False):
1361 request = get_current_request()
1362
1361
1363 svg_type = None
1362 svg_type = None
1364 if email_address == User.DEFAULT_USER_EMAIL:
1363 if email_address == User.DEFAULT_USER_EMAIL:
@@ -1416,12 +1415,18 b' def initials_gravatar(email_address, fir'
1416 return klass.generate_svg(svg_type=svg_type)
1415 return klass.generate_svg(svg_type=svg_type)
1417
1416
1418
1417
1418 def gravatar_external(request, gravatar_url_tmpl, email_address, size=30):
1419 return safe_str(gravatar_url_tmpl)\
1420 .replace('{email}', email_address) \
1421 .replace('{md5email}', md5_safe(email_address.lower())) \
1422 .replace('{netloc}', request.host) \
1423 .replace('{scheme}', request.scheme) \
1424 .replace('{size}', safe_str(size))
1425
1426
1419 def gravatar_url(email_address, size=30, request=None):
1427 def gravatar_url(email_address, size=30, request=None):
1420 request = get_current_request()
1428 request = request or get_current_request()
1421 _use_gravatar = request.call_context.visual.use_gravatar
1429 _use_gravatar = request.call_context.visual.use_gravatar
1422 _gravatar_url = request.call_context.visual.gravatar_url
1423
1424 _gravatar_url = _gravatar_url or User.DEFAULT_GRAVATAR_URL
1425
1430
1426 email_address = email_address or User.DEFAULT_USER_EMAIL
1431 email_address = email_address or User.DEFAULT_USER_EMAIL
1427 if isinstance(email_address, unicode):
1432 if isinstance(email_address, unicode):
@@ -1430,21 +1435,15 b' def gravatar_url(email_address, size=30,'
1430
1435
1431 # empty email or default user
1436 # empty email or default user
1432 if not email_address or email_address == User.DEFAULT_USER_EMAIL:
1437 if not email_address or email_address == User.DEFAULT_USER_EMAIL:
1433 return initials_gravatar(User.DEFAULT_USER_EMAIL, '', '', size=size)
1438 return initials_gravatar(request, User.DEFAULT_USER_EMAIL, '', '', size=size)
1434
1439
1435 if _use_gravatar:
1440 if _use_gravatar:
1436 # TODO: Disuse pyramid thread locals. Think about another solution to
1441 gravatar_url_tmpl = request.call_context.visual.gravatar_url \
1437 # get the host and schema here.
1442 or User.DEFAULT_GRAVATAR_URL
1438 request = get_current_request()
1443 return gravatar_external(request, gravatar_url_tmpl, email_address, size=size)
1439 tmpl = safe_str(_gravatar_url)
1444
1440 tmpl = tmpl.replace('{email}', email_address)\
1441 .replace('{md5email}', md5_safe(email_address.lower())) \
1442 .replace('{netloc}', request.host)\
1443 .replace('{scheme}', request.scheme)\
1444 .replace('{size}', safe_str(size))
1445 return tmpl
1446 else:
1445 else:
1447 return initials_gravatar(email_address, '', '', size=size)
1446 return initials_gravatar(request, email_address, '', '', size=size)
1448
1447
1449
1448
1450 def breadcrumb_repo_link(repo):
1449 def breadcrumb_repo_link(repo):
General Comments 0
You need to be logged in to leave comments. Login now