diff 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
line wrap: on
line diff
--- a/MoinMoin/themes/__init__.py	Sat Aug 24 01:28:27 2013 +0530
+++ b/MoinMoin/themes/__init__.py	Sat Aug 24 15:23:05 2013 +0530
@@ -473,6 +473,26 @@
             name = u'{0}...{1}'.format(name[:half + left], name[-half:])
     return name
 
+CONTENTTYPE_SHORTEN = {
+    'text/x.moin.wiki': 'MoinWiki',
+}
+
+def shorten_content_type(contenttype):
+    """
+    Shorten content-types
+
+    Shortens the content-type to terms that normal users understand.
+
+    :param name: contenttype, unicode
+    :rtype: unicode
+    :returns: shortened version of contenttype
+    """
+    print type(contenttype)
+    ctype = contenttype.split(';')[0]
+    if ctype in CONTENTTYPE_SHORTEN:
+        return CONTENTTYPE_SHORTEN[ctype]
+    else:
+        return "Unknown"
 
 def shorten_id(name, length=7):
     """
@@ -527,6 +547,7 @@
     app.jinja_env.filters['shorten_id'] = shorten_id
     app.jinja_env.filters['contenttype_to_class'] = contenttype_to_class
     app.jinja_env.filters['json_dumps'] = dumps
+    app.jinja_env.filters['shorten_ctype'] = shorten_content_type
     # please note that these filters are installed by flask-babel:
     # datetimeformat, dateformat, timeformat, timedeltaformat