1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-04 16:31:13 +00:00

Add file_icon_filter

This commit is contained in:
xiez
2012-05-17 17:45:47 +08:00
parent db2419c598
commit 3ed66222f9
2 changed files with 22 additions and 0 deletions

View File

@@ -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')

View File

@@ -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: