本文整理汇总了Python中seahub.utils.get_file_type_and_ext函数的典型用法代码示例。如果您正苦于以下问题:Python get_file_type_and_ext函数的具体用法?Python get_file_type_and_ext怎么用?Python get_file_type_and_ext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_file_type_and_ext函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_file_revisions
def render_file_revisions (request, repo_id):
"""List all history versions of a file."""
days_str = request.GET.get('days', '')
try:
days = int(days_str)
except ValueError:
days = 7
path = request.GET.get('p', '/')
if path[-1] == '/':
path = path[:-1]
u_filename = os.path.basename(path)
if not path:
return render_error(request)
repo = get_repo(repo_id)
if not repo:
error_msg = _(u"Library does not exist")
return render_error(request, error_msg)
filetype = get_file_type_and_ext(u_filename)[0].lower()
if filetype == 'text' or filetype == 'markdown':
can_compare = True
else:
can_compare = False
try:
commits = seafile_api.get_file_revisions(repo_id, path, -1, -1, days)
except SearpcError, e:
logger.error(e.msg)
return render_error(request, e.msg)
示例2: post
def post(self, request):
license_file = request.FILES.get('license', None)
if not license_file:
error_msg = 'license can not be found.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
file_type, ext = get_file_type_and_ext(license_file.name)
if ext != 'txt':
error_msg = file_type_error_msg(ext, 'txt')
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
if license_file.size > 1024 * 1024 * 5: # 5mb
error_msg = file_size_error_msg(license_file.size, 5*1024*1024)
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
license_dir = os.path.dirname(LICENSE_PATH)
try:
if not os.path.exists(license_dir):
error_msg = 'path %s invalid.' % LICENSE_PATH
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
with open(LICENSE_PATH, 'w') as fd:
fd.write(license_file.read())
ccnet_api.reload_license()
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
return Response({'success': True}, status=status.HTTP_200_OK)
示例3: view_shared_file
def view_shared_file(request, token):
"""
Preview file via shared link.
"""
assert token is not None # Checked by URLconf
try:
fileshare = FileShare.objects.get(token=token)
except FileShare.DoesNotExist:
raise Http404
shared_by = fileshare.username
repo_id = fileshare.repo_id
repo = get_repo(repo_id)
if not repo:
raise Http404
path = fileshare.path.rstrip('/') # Normalize file path
obj_id = seafile_api.get_file_id_by_path(repo_id, path)
if not obj_id:
return render_error(request, _(u'File does not exist'))
file_size = seafile_api.get_file_size(obj_id)
filename = os.path.basename(path)
filetype, fileext = get_file_type_and_ext(filename)
access_token = seafserv_rpc.web_get_access_token(repo.id, obj_id,
'view', '')
raw_path = gen_file_get_url(access_token, filename)
inner_path = gen_inner_file_get_url(access_token, filename)
# get file content
ret_dict = {'err': '', 'file_content': '', 'encoding': '', 'file_enc': '',
'file_encoding_list': [], 'html_exists': False,
'filetype': filetype}
fsize = get_file_size(obj_id)
exceeds_limit, err_msg = file_size_exceeds_preview_limit(fsize, filetype)
if exceeds_limit:
err = err_msg
else:
"""Choose different approach when dealing with different type of file."""
if is_textual_file(file_type=filetype):
handle_textual_file(request, filetype, inner_path, ret_dict)
elif filetype == DOCUMENT:
handle_document(inner_path, obj_id, fileext, ret_dict)
elif filetype == PDF:
handle_pdf(inner_path, obj_id, fileext, ret_dict)
# Increase file shared link view_cnt, this operation should be atomic
fileshare.view_cnt = F('view_cnt') + 1
fileshare.save()
# send statistic messages
if ret_dict['filetype'] != 'Unknown':
try:
obj_size = seafserv_threaded_rpc.get_file_size(obj_id)
send_message('seahub.stats', 'file-view\t%s\t%s\t%s\t%s' % \
(repo.id, shared_by, obj_id, obj_size))
except SearpcError, e:
logger.error('Error when sending file-view message: %s' % str(e))
示例4: get_onlyoffice_dict
def get_onlyoffice_dict(username, repo_id, file_path,
file_id='', can_edit=False, can_download=True):
repo = seafile_api.get_repo(repo_id)
if repo.is_virtual:
origin_repo_id = repo.origin_repo_id
origin_file_path = posixpath.join(repo.origin_path, file_path.strip('/'))
# for view history/trash/snapshot file
if not file_id:
file_id = seafile_api.get_file_id_by_path(origin_repo_id,
origin_file_path)
else:
origin_repo_id = repo_id
origin_file_path = file_path
if not file_id:
file_id = seafile_api.get_file_id_by_path(repo_id,
file_path)
dl_token = seafile_api.get_fileserver_access_token(repo_id,
file_id, 'download', username, use_onetime=True)
if not dl_token:
return None
filetype, fileext = get_file_type_and_ext(file_path)
if fileext in ('xls', 'xlsx', 'ods', 'fods', 'csv'):
document_type = 'spreadsheet'
elif fileext in ('pptx', 'ppt', 'odp', 'fodp', 'ppsx', 'pps'):
document_type = 'presentation'
else:
document_type = 'text'
doc_info = json.dumps({'repo_id': repo_id, 'file_path': file_path, 'username': username})
doc_key = hashlib.md5(force_bytes(origin_repo_id + origin_file_path + file_id)).hexdigest()[:20]
cache.set("ONLYOFFICE_%s" % doc_key, doc_info, None)
file_name = os.path.basename(file_path.rstrip('/'))
doc_url = gen_file_get_url(dl_token, file_name)
base_url = get_site_scheme_and_netloc()
onlyoffice_editor_callback_url = reverse('onlyoffice_editor_callback')
calllback_url = urlparse.urljoin(base_url, onlyoffice_editor_callback_url)
return_dict = {
'repo_id': repo_id,
'path': file_path,
'ONLYOFFICE_APIJS_URL': ONLYOFFICE_APIJS_URL,
'file_type': fileext,
'doc_key': doc_key,
'doc_title': file_name,
'doc_url': doc_url,
'document_type': document_type,
'callback_url': calllback_url,
'can_edit': can_edit,
'can_download': can_download,
'username': username,
'enable_watermark': ENABLE_WATERMARK and not can_edit,
}
return return_dict
示例5: get_group_msgs
def get_group_msgs(groupid, page, username):
# Show 15 group messages per page.
paginator = Paginator(GroupMessage.objects.filter(group_id=groupid).order_by("-timestamp"), 15)
# If page request (9999) is out of range, return None
try:
group_msgs = paginator.page(page)
except (EmptyPage, InvalidPage):
return None
# Force evaluate queryset to fix some database error for mysql.
group_msgs.object_list = list(group_msgs.object_list)
attachments = MessageAttachment.objects.filter(group_message__in=group_msgs.object_list)
msg_replies = MessageReply.objects.filter(reply_to__in=group_msgs.object_list)
reply_to_list = [r.reply_to_id for r in msg_replies]
for msg in group_msgs.object_list:
msg.reply_cnt = reply_to_list.count(msg.id)
msg.replies = []
for r in msg_replies:
if msg.id == r.reply_to_id:
msg.replies.append(r)
msg.replies = msg.replies[-3:]
for att in attachments:
if att.group_message_id != msg.id:
continue
# Attachment name is file name or directory name.
# If is top directory, use repo name instead.
path = att.path
if path == "/":
repo = seafile_api.get_repo(att.repo_id)
if not repo:
# TODO: what should we do here, tell user the repo
# is no longer exists?
continue
att.name = repo.name
else:
path = path.rstrip("/") # cut out last '/' if possible
att.name = os.path.basename(path)
# Load to discuss page if attachment is a image and from recommend.
if att.attach_type == "file" and att.src == "recommend":
att.filetype, att.fileext = get_file_type_and_ext(att.name)
if att.filetype == IMAGE:
att.obj_id = seafile_api.get_file_id_by_path(att.repo_id, path)
if not att.obj_id:
att.err = "File does not exist"
else:
att.token = seafile_api.get_fileserver_access_token(att.repo_id, att.obj_id, "view", username)
att.img_url = gen_file_get_url(att.token, att.name)
msg.attachment = att
return group_msgs
示例6: view_file_via_shared_dir
def view_file_via_shared_dir(request, token):
assert token is not None # Checked by URLconf
try:
fileshare = FileShare.objects.get(token=token)
except FileShare.DoesNotExist:
raise Http404
shared_by = fileshare.username
repo_id = fileshare.repo_id
repo = get_repo(repo_id)
if not repo:
raise Http404
path = request.GET.get('p', '').rstrip('/')
if not path:
raise Http404
if not path.startswith(fileshare.path): # Can not view upper dir of shared dir
raise Http404
zipped = gen_path_link(path, '')
obj_id = seafile_api.get_file_id_by_path(repo_id, path)
if not obj_id:
return render_error(request, _(u'File does not exist'))
file_size = seafile_api.get_file_size(obj_id)
filename = os.path.basename(path)
filetype, fileext = get_file_type_and_ext(filename)
access_token = seafserv_rpc.web_get_access_token(repo.id, obj_id,
'view', '')
raw_path = gen_file_get_url(access_token, filename)
inner_path = gen_inner_file_get_url(access_token, filename)
# get file content
ret_dict = {'err': '', 'file_content': '', 'encoding': '', 'file_enc': '',
'file_encoding_list': [], 'html_exists': False,
'filetype': filetype}
fsize = get_file_size(obj_id)
exceeds_limit, err_msg = file_size_exceeds_preview_limit(fsize, filetype)
if exceeds_limit:
err = err_msg
else:
"""Choose different approach when dealing with different type of file."""
if is_textual_file(file_type=filetype):
handle_textual_file(request, filetype, inner_path, ret_dict)
elif filetype == DOCUMENT:
handle_document(inner_path, obj_id, fileext, ret_dict)
elif filetype == PDF:
handle_pdf(inner_path, obj_id, fileext, ret_dict)
# send statistic messages
try:
obj_size = seafserv_threaded_rpc.get_file_size(obj_id)
send_message('seahub.stats', 'file-view\t%s\t%s\t%s\t%s' % \
(repo.id, shared_by, obj_id, obj_size))
except SearpcError, e:
logger.error('Error when sending file-view message: %s' % str(e))
示例7: allow_generate_thumbnail
def allow_generate_thumbnail(username, repo, f):
# check if thumbnail is allowed
if seafile_api.check_repo_access_permission(repo.id, username) is None:
# user can not access repo
return False
file_type, file_ext = get_file_type_and_ext(f.obj_name)
if not repo.encrypted and file_type == IMAGE and ENABLE_THUMBNAIL \
and f.file_size < THUMBNAIL_IMAGE_SIZE_LIMIT * 1024**2:
return True
else:
return False
示例8: repl
def repl(matchobj):
if matchobj.group(2): # return origin string in backquotes
return matchobj.group(2)
page_alias = page_name = matchobj.group(1).strip()
if len(page_name.split("|")) > 1:
page_alias = page_name.split("|")[0]
page_name = page_name.split("|")[1]
filetype, fileext = get_file_type_and_ext(page_name)
if fileext == "":
# convert page_name that extension is missing to a markdown page
try:
dirent = get_wiki_dirent(repo_id, page_name)
a_tag = "<a href='%s'>%s</a>"
return a_tag % (smart_str(url_prefix + normalize_page_name(page_name) + "/"), page_alias)
except (WikiDoesNotExist, WikiPageMissing):
a_tag = """<a class="wiki-page-missing" href='%s'>%s</a>"""
return a_tag % (smart_str(url_prefix + page_name.replace("/", "-") + "/"), page_alias)
elif filetype == IMAGE:
# load image to wiki page
path = "/" + page_name
filename = os.path.basename(path)
obj_id = seaserv.get_file_id_by_path(repo_id, path)
if not obj_id:
# Replace '/' in page_name to '-', since wiki name can not
# contain '/'.
return """<a class="wiki-page-missing" href='%s'>%s</a>""" % (
url_prefix + "/" + page_name.replace("/", "-"),
page_name,
)
token = seaserv.web_get_access_token(repo_id, obj_id, "view", username)
ret = '<img class="wiki-image" src="%s" alt="%s" />' % (gen_file_get_url(token, filename), filename)
return smart_str(ret)
else:
from seahub.base.templatetags.seahub_tags import file_icon_filter
from django.conf import settings
# convert other types of filelinks to clickable links
path = "/" + page_name
icon = file_icon_filter(page_name)
s = reverse("repo_view_file", args=[repo_id]) + "?p=" + urlquote(path)
a_tag = (
"""<img src="%simg/file/%s" alt="%s" class="vam" /> <a href='%s' target='_blank' class="vam">%s</a>"""
)
ret = a_tag % (settings.MEDIA_URL, icon, icon, smart_str(s), page_name)
return smart_str(ret)
示例9: post
def post(self, request):
favicon_file = request.FILES.get('favicon', None)
if not favicon_file:
error_msg = 'Favicon can not be found.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
file_type, ext = get_file_type_and_ext(favicon_file.name)
if file_type != IMAGE:
error_msg = file_type_error_msg(ext, PREVIEW_FILEEXT.get(IMAGE))
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
if favicon_file.size > 1024 * 1024 * 20: # 20mb
error_msg = file_size_error_msg(favicon_file.size, 20*1024*1024)
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
if not os.path.exists(SEAHUB_DATA_ROOT):
os.makedirs(SEAHUB_DATA_ROOT)
custom_dir = os.path.join(SEAHUB_DATA_ROOT,
os.path.dirname(CUSTOM_FAVICON_PATH))
if not os.path.exists(custom_dir):
os.makedirs(custom_dir)
try:
custom_favicon_file = os.path.join(SEAHUB_DATA_ROOT,
CUSTOM_FAVICON_PATH)
# save favicon file to custom dir
with open(custom_favicon_file, 'w') as fd:
fd.write(favicon_file.read())
custom_symlink = os.path.join(MEDIA_ROOT,
os.path.dirname(CUSTOM_FAVICON_PATH))
# create symlink for custom dir
if not os.path.exists(custom_symlink):
os.symlink(custom_dir, custom_symlink)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
return Response({'success': True})
示例10: repl
def repl(matchobj):
if matchobj.group(2): # return origin string in backquotes
return matchobj.group(2)
page_alias = page_name = matchobj.group(1).strip()
if len(page_name.split('|')) > 1:
page_alias = page_name.split('|')[0]
page_name = page_name.split('|')[1]
filetype, fileext = get_file_type_and_ext(page_name)
if fileext == '':
# convert page_name that extension is missing to a markdown page
try:
dirent = get_wiki_dirent(repo_id, page_name)
a_tag = '''<a href="%s">%s</a>'''
return a_tag % (smart_str(url_prefix + normalize_page_name(page_name) + '/'), page_alias)
except (WikiDoesNotExist, WikiPageMissing):
a_tag = '''<a href="%s" class="wiki-page-missing">%s</a>'''
return a_tag % (smart_str(url_prefix + normalize_page_name(page_name) + '/'), page_alias)
elif filetype == IMAGE:
# load image to wiki page
path = "/" + page_name
filename = os.path.basename(path)
obj_id = seaserv.get_file_id_by_path(repo_id, path)
if not obj_id:
# Replace '/' in page_name to '-', since wiki name can not
# contain '/'.
return '''<a href="%s" class="wiki-page-missing">%s</a>''' % \
(url_prefix + '/' + page_name.replace('/', '-'), page_name)
token = seafile_api.get_fileserver_access_token(repo_id, obj_id,
'view', username)
ret = '<img src="%s" alt="%s" class="wiki-image" />' % (gen_file_get_url(token, filename), filename)
return smart_str(ret)
else:
from seahub.base.templatetags.seahub_tags import file_icon_filter
from django.conf import settings
# convert other types of filelinks to clickable links
path = "/" + page_name
icon = file_icon_filter(page_name)
s = reverse('view_lib_file', args=[repo_id, urlquote(path)])
a_tag = '''<img src="%simg/file/%s" alt="%s" class="file-icon vam" /> <a href="%s" class="vam" target="_blank">%s</a>'''
ret = a_tag % (settings.MEDIA_URL, icon, icon, smart_str(s), page_name)
return smart_str(ret)
示例11: allow_generate_thumbnail
def allow_generate_thumbnail(request, repo_id, path):
"""check if thumbnail is allowed
"""
# get file type
obj_name = os.path.basename(path)
file_type, file_ext = get_file_type_and_ext(obj_name)
# get file size
file_id = get_file_id_by_path(repo_id, path)
if not file_id:
return False
repo = get_repo(repo_id)
file_size = get_file_size(repo.store_id, repo.version, file_id)
if repo.encrypted or file_type != IMAGE or not ENABLE_THUMBNAIL:
return False
# check image compressed size limit
if file_size < THUMBNAIL_IMAGE_COMPRESSED_SIZE_LIMIT * 1024**2:
return True
# get image memory cost
token = seafile_api.get_fileserver_access_token(repo_id, file_id, 'view',
'', use_onetime = True)
inner_path = gen_inner_file_get_url(token, obj_name)
try:
image_file = urllib2.urlopen(inner_path)
f = StringIO(image_file.read())
image = Image.open(f)
width, height = image.size
# check image memory cost size limit
# use RGBA as default mode(4x8-bit pixels, true colour with transparency mask)
# every pixel will cost 4 byte in RGBA mode
image_memory_cost = width * height * 4 / 1024 / 1024
if image_memory_cost < THUMBNAIL_IMAGE_ORIGINAL_SIZE_LIMIT:
return True
except Exception as e:
logger.error(e)
return False
示例12: post
def post(self, request):
image_file = request.FILES.get('login_bg_image', None)
if not image_file:
error_msg = 'Image can not be found.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
if not os.path.exists(SEAHUB_DATA_ROOT):
os.makedirs(SEAHUB_DATA_ROOT)
file_type, ext = get_file_type_and_ext(image_file.name)
if file_type != IMAGE:
error_msg = file_type_error_msg(ext, PREVIEW_FILEEXT.get('Image'))
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
if image_file.size > 1024 * 1024 * 20: # 20mb
error_msg = file_size_error_msg(image_file.size, 20*1024*1024)
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
custom_login_bg_image_path = get_custom_login_bg_image_path()
custom_dir = os.path.join(SEAHUB_DATA_ROOT,
os.path.dirname(custom_login_bg_image_path))
if not os.path.exists(custom_dir):
os.makedirs(custom_dir)
try:
custom_login_bg_image_file = os.path.join(SEAHUB_DATA_ROOT,
custom_login_bg_image_path)
# save login background image file to custom dir
with open(custom_login_bg_image_file, 'w') as fd:
fd.write(image_file.read())
custom_symlink = os.path.join(MEDIA_ROOT,
os.path.dirname(custom_login_bg_image_path))
# create symlink for custom dir
if not os.path.exists(custom_symlink):
os.symlink(custom_dir, custom_symlink)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
return Response({'success': True})
示例13: repl
def repl(matchobj):
if matchobj.group(2): # return origin string in backquotes
return matchobj.group(2)
link_alias = link_name = matchobj.group(1).strip()
if len(link_name.split("|")) > 1:
link_alias = link_name.split("|")[0]
link_name = link_name.split("|")[1]
filetype, fileext = get_file_type_and_ext(link_name)
if fileext == "":
# convert link_name that extension is missing to a markdown page
try:
dirent = get_wiki_dirent(repo_id, link_name)
path = "/" + dirent.obj_name
href = reverse("repo_view_file", args=[repo_id]) + "?p=" + urlquote(path)
a_tag = """<a href="%s">%s</a>"""
return a_tag % (href, link_alias)
except (WikiDoesNotExist, WikiPageMissing):
a_tag = """<p class="wiki-page-missing">%s</p>"""
return a_tag % (link_alias)
elif filetype == IMAGE:
# load image to current page
path = "/" + link_name
filename = os.path.basename(path)
obj_id = get_file_id_by_path(repo_id, path)
if not obj_id:
return """<p class="wiki-page-missing">%s</p>""" % link_name
token = web_get_access_token(repo_id, obj_id, "view", username)
return '<img class="wiki-image" src="%s" alt="%s" />' % (gen_file_get_url(token, filename), filename)
else:
from seahub.base.templatetags.seahub_tags import file_icon_filter
# convert other types of filelinks to clickable links
path = "/" + link_name
icon = file_icon_filter(link_name)
s = reverse("repo_view_file", args=[repo_id]) + "?p=" + urlquote(path)
a_tag = (
"""<img src="%simg/file/%s" alt="%s" class="vam" /> <a href="%s" target="_blank" class="vam">%s</a>"""
)
return a_tag % (MEDIA_URL, icon, icon, s, link_name)
示例14: post
def post(self, request):
logo_file = request.FILES.get('logo', None)
if not logo_file:
error_msg = 'Logo can not be found.'
logger.error(error_msg)
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
file_type, ext = get_file_type_and_ext(logo_file.name)
if file_type != IMAGE:
error_msg = file_type_error_msg(ext, PREVIEW_FILEEXT.get(IMAGE))
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
if logo_file.size > 1024 * 1024 * 20: # 20mb
error_msg = file_size_error_msg(logo_file.size, 20*1024*1024)
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
if not os.path.exists(SEAHUB_DATA_ROOT):
os.makedirs(SEAHUB_DATA_ROOT)
custom_dir = os.path.join(SEAHUB_DATA_ROOT, os.path.dirname(CUSTOM_LOGO_PATH))
if not os.path.exists(custom_dir):
os.makedirs(custom_dir)
try:
# save logo file to custom dir
custom_logo_file = os.path.join(SEAHUB_DATA_ROOT, CUSTOM_LOGO_PATH)
image = Image.open(logo_file)
image.save(custom_logo_file)
# create symlink for custom dir
custom_symlink = os.path.join(MEDIA_ROOT, os.path.dirname(CUSTOM_LOGO_PATH))
if not os.path.exists(custom_symlink):
os.symlink(custom_dir, custom_symlink)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
return Response({'success': True})
示例15: repl
def repl(matchobj):
if matchobj.group(2): # return origin string in backquotes
return matchobj.group(2)
linkname = matchobj.group(1).strip()
filetype, fileext = get_file_type_and_ext(linkname)
filetype = filetype.lower()
if fileext == '':
# convert linkname that extension is missing to a markdown page
filename = linkname + ".md"
path = "/" + filename
if get_file_id_by_path(repo_id, path):
a_tag = "<a href='%s'>%s</a>"
return a_tag % (reverse('group_wiki', args=[group.id, linkname]), linkname)
else:
a_tag = '''<a class="wiki-page-missing" href='%s'>%s</a>'''
return a_tag % (reverse('group_wiki', args=[group.id, linkname.replace('/', '-')]), linkname)
elif filetype == 'image':
# load image to wiki page
path = "/" + linkname
filename = os.path.basename(path)
obj_id = get_file_id_by_path(repo_id, path)
if not obj_id:
# Replace '/' in linkname to '-', since wiki name can not
# contain '/'.
return '''<a class="wiki-page-missing" href='%s'>%s</a>''' % \
(reverse('group_wiki', args=[group.id, linkname.replace('/', '-')]), linkname)
token = web_get_access_token(repo_id, obj_id, 'view', username)
return '<img src="%s" alt="%s" />' % (gen_file_get_url(token, filename), filename)
else:
from base.templatetags.seahub_tags import file_icon_filter
# convert other types of filelinks to clickable links
path = "/" + linkname
icon = file_icon_filter(linkname)
s = reverse('repo_view_file', args=[repo_id]) + '?p=' + path
a_tag = '''<img src="%simg/file/%s" alt="%s" class="vam" /> <a href='%s' target='_blank' class="vam">%s</a>'''
return a_tag % (MEDIA_URL, icon, icon, s, linkname)