comparison MoinMoin/themes/__init__.py @ 2409:51b90beddc7c

Shortens contenttype display in the history view
author sharky93 <rishabhr123@gmail.com>
date Sat, 24 Aug 2013 15:23:05 +0530
parents 35b64d97bd9c
children 89ce7644a01d
comparison
equal deleted inserted replaced
2408:e0736d533b8f 2409:51b90beddc7c
471 if len(name) > length: 471 if len(name) > length:
472 half, left = divmod(length - 3, 2) 472 half, left = divmod(length - 3, 2)
473 name = u'{0}...{1}'.format(name[:half + left], name[-half:]) 473 name = u'{0}...{1}'.format(name[:half + left], name[-half:])
474 return name 474 return name
475 475
476 CONTENTTYPE_SHORTEN = {
477 'text/x.moin.wiki': 'MoinWiki',
478 }
479
480 def shorten_content_type(contenttype):
481 """
482 Shorten content-types
483
484 Shortens the content-type to terms that normal users understand.
485
486 :param name: contenttype, unicode
487 :rtype: unicode
488 :returns: shortened version of contenttype
489 """
490 print type(contenttype)
491 ctype = contenttype.split(';')[0]
492 if ctype in CONTENTTYPE_SHORTEN:
493 return CONTENTTYPE_SHORTEN[ctype]
494 else:
495 return "Unknown"
476 496
477 def shorten_id(name, length=7): 497 def shorten_id(name, length=7):
478 """ 498 """
479 Shorten IDs to specified length 499 Shorten IDs to specified length
480 500
525 def setup_jinja_env(): 545 def setup_jinja_env():
526 app.jinja_env.filters['shorten_item_name'] = shorten_item_name 546 app.jinja_env.filters['shorten_item_name'] = shorten_item_name
527 app.jinja_env.filters['shorten_id'] = shorten_id 547 app.jinja_env.filters['shorten_id'] = shorten_id
528 app.jinja_env.filters['contenttype_to_class'] = contenttype_to_class 548 app.jinja_env.filters['contenttype_to_class'] = contenttype_to_class
529 app.jinja_env.filters['json_dumps'] = dumps 549 app.jinja_env.filters['json_dumps'] = dumps
550 app.jinja_env.filters['shorten_ctype'] = shorten_content_type
530 # please note that these filters are installed by flask-babel: 551 # please note that these filters are installed by flask-babel:
531 # datetimeformat, dateformat, timeformat, timedeltaformat 552 # datetimeformat, dateformat, timeformat, timedeltaformat
532 553
533 app.jinja_env.globals.update({ 554 app.jinja_env.globals.update({
534 # please note that flask-babel/jinja2.ext installs: 555 # please note that flask-babel/jinja2.ext installs: