mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-23 04:18:21 +00:00
[repo] added 'more' for dirents view
This commit is contained in:
@@ -195,7 +195,10 @@ def list_dir(request, repo_id):
|
||||
if path[-1] != '/':
|
||||
path = path + '/'
|
||||
|
||||
file_list, dir_list = get_repo_dirents(request, repo.id, head_commit, path)
|
||||
more_start = None
|
||||
file_list, dir_list, dirent_more = get_repo_dirents(request, repo.id, head_commit, path, offset=0, limit=100)
|
||||
if dirent_more:
|
||||
more_start = 100
|
||||
zipped = get_nav_path(path, repo.name)
|
||||
fileshare = get_fileshare(repo.id, username, path)
|
||||
dir_shared_link = get_dir_share_link(fileshare)
|
||||
@@ -209,6 +212,8 @@ def list_dir(request, repo_id):
|
||||
'dir_shared_link': dir_shared_link,
|
||||
'dir_list': dir_list,
|
||||
'file_list': file_list,
|
||||
'dirent_more': dirent_more,
|
||||
'more_start': more_start,
|
||||
'ENABLE_SUB_LIBRARY': settings.ENABLE_SUB_LIBRARY,
|
||||
}
|
||||
html = render_to_string('snippets/repo_dir_data.html', ctx,
|
||||
@@ -216,6 +221,70 @@ def list_dir(request, repo_id):
|
||||
return HttpResponse(json.dumps({'html': html, 'path': path}),
|
||||
content_type=content_type)
|
||||
|
||||
@login_required
|
||||
def list_dir_more(request, repo_id):
|
||||
"""
|
||||
List 'more' entries in a directory with AJAX.
|
||||
"""
|
||||
if not request.is_ajax():
|
||||
raise Http404
|
||||
|
||||
content_type = 'application/json; charset=utf-8'
|
||||
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
err_msg = _(u'Library does not exist.')
|
||||
return HttpResponse(json.dumps({'error': err_msg}),
|
||||
status=400, content_type=content_type)
|
||||
|
||||
username = request.user.username
|
||||
user_perm = check_repo_access_permission(repo.id, username)
|
||||
if user_perm is None:
|
||||
err_msg = _(u'Permission denied.')
|
||||
return HttpResponse(json.dumps({'error': err_msg}),
|
||||
status=403, content_type=content_type)
|
||||
|
||||
if repo.encrypted and not seafile_api.is_password_set(repo.id, username):
|
||||
err_msg = _(u'Library is encrypted.')
|
||||
return HttpResponse(json.dumps({'error': err_msg}),
|
||||
status=403, content_type=content_type)
|
||||
|
||||
head_commit = get_commit(repo.head_cmmt_id)
|
||||
if not head_commit:
|
||||
err_msg = _(u'Error: no head commit id')
|
||||
return HttpResponse(json.dumps({'error': err_msg}),
|
||||
status=500, content_type=content_type)
|
||||
|
||||
path = request.GET.get('p', '/')
|
||||
if path[-1] != '/':
|
||||
path = path + '/'
|
||||
|
||||
offset = int(request.GET.get('start'))
|
||||
if not offset:
|
||||
err_msg = _(u'Argument missing')
|
||||
return HttpResponse(json.dumps({'error': err_msg}),
|
||||
status=400, content_type=content_type)
|
||||
more_start = None
|
||||
file_list, dir_list, dirent_more = get_repo_dirents(request, repo.id, head_commit, path, offset, limit=100)
|
||||
if dirent_more:
|
||||
more_start = offset + 100
|
||||
|
||||
ctx = {
|
||||
'repo': repo,
|
||||
'user_perm': user_perm,
|
||||
'path': path,
|
||||
'dir_list': dir_list,
|
||||
'file_list': file_list,
|
||||
'dirent_more': dirent_more,
|
||||
'more_start': more_start,
|
||||
'ENABLE_SUB_LIBRARY': settings.ENABLE_SUB_LIBRARY,
|
||||
}
|
||||
html = render_to_string('snippets/repo_dirents.html', ctx,
|
||||
context_instance=RequestContext(request))
|
||||
return HttpResponse(json.dumps({'html': html, 'dirent_more': dirent_more, 'more_start': more_start}),
|
||||
content_type=content_type)
|
||||
|
||||
|
||||
def new_dirent_common(func):
|
||||
"""Decorator for common logic in creating directory and file.
|
||||
"""
|
||||
|
Reference in New Issue
Block a user