diff --git a/base/templatetags/seahub_tags.py b/base/templatetags/seahub_tags.py index 922727e43c..d625b0192b 100644 --- a/base/templatetags/seahub_tags.py +++ b/base/templatetags/seahub_tags.py @@ -1,6 +1,8 @@ from datetime import datetime from django import template +from seahub.settings import SUPPORTED_FILE_EXT + register = template.Library() @register.filter(name='tsstr_sec') @@ -11,3 +13,15 @@ def tsstr_sec(value): except: return datetime.fromtimestamp(value/1000000).strftime("%Y-%m-%d %H:%M:%S") +@register.filter(name='file_icon_filter') +def file_icon_filter(value): + """Get file icon according to the file postfix""" + if value.rfind('.') > 0: + file_ext = value.split('.')[-1] + else: + file_ext = None + + if file_ext and SUPPORTED_FILE_EXT.has_key(file_ext): + return SUPPORTED_FILE_EXT.get(file_ext) + else: + return SUPPORTED_FILE_EXT.get('default') diff --git a/settings.py b/settings.py index aade832304..ee596ecff5 100644 --- a/settings.py +++ b/settings.py @@ -129,6 +129,14 @@ CCNET_APPLET_ROOT = "http://localhost:8081" SEAFILE_VERSION = '0.9.2' +# Add supported file extensions and file icon name. +# Icons will show in repo page. +SUPPORTED_FILE_EXT = { + 'txt' : 'foo.jpg', + 'pdf' : '', + 'default' : '', +} + try: import local_settings except ImportError: