本文整理汇总了Python中seahub.views.get_repo_dirents函数的典型用法代码示例。如果您正苦于以下问题:Python get_repo_dirents函数的具体用法?Python get_repo_dirents怎么用?Python get_repo_dirents使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_repo_dirents函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: repo_history_view
def repo_history_view(request, repo_id):
"""View repo in history.
"""
repo = get_repo(repo_id)
if not repo:
raise Http404
username = request.user.username
path = get_path_from_request(request)
user_perm = check_folder_permission(request, repo.id, '/')
if user_perm is None:
return render_error(request, _(u'Permission denied'))
try:
server_crypto = UserOptions.objects.is_server_crypto(username)
except CryptoOptionNotSetError:
# Assume server_crypto is ``False`` if this option is not set.
server_crypto = False
if repo.encrypted and \
(repo.enc_version == 1 or (repo.enc_version == 2 and server_crypto)) \
and not is_password_set(repo.id, username):
return render_to_response(
'decrypt_repo_form.html', {
'repo':
repo,
'next':
get_next_url_from_request(request)
or reverse('repo', args=[repo.id]),
'force_server_crypto':
FORCE_SERVER_CRYPTO,
},
context_instance=RequestContext(request))
commit_id = request.GET.get('commit_id', None)
if commit_id is None:
return HttpResponseRedirect(reverse('repo', args=[repo.id]))
current_commit = get_commit(repo.id, repo.version, commit_id)
if not current_commit:
current_commit = get_commit(repo.id, repo.version, repo.head_cmmt_id)
file_list, dir_list, dirent_more = get_repo_dirents(
request, repo, current_commit, path)
zipped = get_nav_path(path, repo.name)
repo_owner = seafile_api.get_repo_owner(repo.id)
is_repo_owner = True if username == repo_owner else False
return render_to_response(
'repo_history_view.html', {
'repo': repo,
"is_repo_owner": is_repo_owner,
'user_perm': user_perm,
'current_commit': current_commit,
'dir_list': dir_list,
'file_list': file_list,
'path': path,
'zipped': zipped,
},
context_instance=RequestContext(request))
开发者ID:soloice,项目名称:seahub,代码行数:60,代码来源:repo.py
示例2: list_dir_more
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,
'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)
开发者ID:Greyhatno,项目名称:seahub,代码行数:59,代码来源:ajax.py
示例3: repo_history_view
def repo_history_view(request, repo_id):
"""View repo in history.
"""
repo = get_repo(repo_id)
if not repo:
raise Http404
username = request.user.username
path = get_path_from_request(request)
user_perm = check_repo_access_permission(repo.id, request.user)
if user_perm is None:
return render_to_response("repo_access_deny.html", {"repo": repo}, context_instance=RequestContext(request))
try:
server_crypto = UserOptions.objects.is_server_crypto(username)
except CryptoOptionNotSetError:
# Assume server_crypto is ``False`` if this option is not set.
server_crypto = False
if (
repo.encrypted
and (repo.enc_version == 1 or (repo.enc_version == 2 and server_crypto))
and not is_password_set(repo.id, username)
):
return render_to_response(
"decrypt_repo_form.html",
{
"repo": repo,
"next": get_next_url_from_request(request) or reverse("repo", args=[repo.id]),
"force_server_crypto": FORCE_SERVER_CRYPTO,
},
context_instance=RequestContext(request),
)
commit_id = request.GET.get("commit_id", None)
if commit_id is None:
return HttpResponseRedirect(reverse("repo", args=[repo.id]))
current_commit = get_commit(repo.id, repo.version, commit_id)
if not current_commit:
current_commit = get_commit(repo.id, repo.version, repo.head_cmmt_id)
file_list, dir_list = get_repo_dirents(request, repo, current_commit, path)
zipped = get_nav_path(path, repo.name)
return render_to_response(
"repo_history_view.html",
{
"repo": repo,
"user_perm": user_perm,
"current_commit": current_commit,
"dir_list": dir_list,
"file_list": file_list,
"path": path,
"zipped": zipped,
},
context_instance=RequestContext(request),
)
开发者ID:vikingliu,项目名称:seahub,代码行数:57,代码来源:repo.py
示例4: repo_history_view
def repo_history_view(request, repo_id):
"""View repo in history.
"""
repo = get_repo(repo_id)
if not repo:
raise Http404
username = request.user.username
path = get_path_from_request(request)
user_perm = check_repo_access_permission(repo.id, username)
if user_perm is None:
return render_to_response('repo_access_deny.html', {
'repo': repo,
}, context_instance=RequestContext(request))
try:
server_crypto = UserOptions.objects.is_server_crypto(username)
except CryptoOptionNotSetError:
# Assume server_crypto is ``False`` if this option is not set.
server_crypto = False
if repo.encrypted and \
(repo.enc_version == 1 or (repo.enc_version == 2 and server_crypto)) \
and not is_password_set(repo.id, username):
return render_to_response('decrypt_repo_form.html', {
'repo': repo,
'next': get_next_url_from_request(request) or \
reverse('repo', args=[repo.id])
}, context_instance=RequestContext(request))
commit_id = request.GET.get('commit_id', None)
if commit_id is None:
return HttpResponseRedirect(reverse('repo', args=[repo.id]))
current_commit = get_commit(commit_id)
if not current_commit:
current_commit = get_commit(repo.head_cmmt_id)
file_list, dir_list = get_repo_dirents(request, repo.id, current_commit, path)
zipped = get_nav_path(path, repo.name)
search_repo_id = None if repo.encrypted else repo.id
return render_to_response('repo_history_view.html', {
'repo': repo,
'user_perm': user_perm,
'current_commit': current_commit,
'dir_list': dir_list,
'file_list': file_list,
'path': path,
'zipped': zipped,
'search_repo_id': search_repo_id,
}, context_instance=RequestContext(request))
开发者ID:unixcrh,项目名称:seahub,代码行数:51,代码来源:repo.py
示例5: repo_history_view
def repo_history_view(request, repo_id):
"""View repo in history.
"""
repo = get_repo(repo_id)
if not repo:
raise Http404
username = request.user.username
path = get_path_from_request(request)
user_perm = check_repo_access_permission(repo.id, username)
if user_perm is None:
return render_to_response("repo_access_deny.html", {"repo": repo}, context_instance=RequestContext(request))
if (
repo.encrypted
and (repo.enc_version == 1 or (repo.enc_version == 2 and SERVER_CRYPTO))
and not is_password_set(repo.id, username)
):
return render_to_response(
"decrypt_repo_form.html",
{"repo": repo, "next": get_next_url_from_request(request) or reverse("repo", args=[repo.id])},
context_instance=RequestContext(request),
)
commit_id = request.GET.get("commit_id", None)
if commit_id is None:
return HttpResponseRedirect(reverse("repo", args=[repo.id]))
current_commit = get_commit(commit_id)
if not current_commit:
current_commit = get_commit(repo.head_cmmt_id)
file_list, dir_list = get_repo_dirents(request, repo.id, current_commit, path)
zipped = get_nav_path(path, repo.name)
search_repo_id = None if repo.encrypted else repo.id
return render_to_response(
"repo_history_view.html",
{
"repo": repo,
"user_perm": user_perm,
"current_commit": current_commit,
"dir_list": dir_list,
"file_list": file_list,
"path": path,
"zipped": zipped,
"search_repo_id": search_repo_id,
},
context_instance=RequestContext(request),
)
开发者ID:vIiRuS,项目名称:seahub,代码行数:49,代码来源:repo.py
示例6: repo_history_view
def repo_history_view(request, repo_id):
"""View repo in history.
"""
repo = get_repo(repo_id)
if not repo:
raise Http404
username = request.user.username
user_perm = check_repo_access_permission(repo.id, username)
if user_perm is None:
return render_to_response('repo_access_deny.html', {
'repo': repo,
}, context_instance=RequestContext(request))
if repo.encrypted and not is_password_set(repo.id, username):
return render_to_response('decrypt_repo_form.html', {
'repo': repo,
'next': get_next_url_from_request(request) or \
reverse('repo', args=[repo.id])
}, context_instance=RequestContext(request))
commit_id = request.GET.get('commit_id', None)
if commit_id is None:
return HttpResponseRedirect(reverse('repo', args=[repo.id]))
current_commit = get_commit(commit_id)
if not current_commit:
current_commit = get_commit(repo.head_cmmt_id)
path = get_path_from_request(request)
file_list, dir_list = get_repo_dirents(request, repo.id, current_commit, path)
zipped = get_nav_path(path, repo.name)
search_repo_id = None if repo.encrypted else repo.id
return render_to_response('repo_history_view.html', {
'repo': repo,
'user_perm': user_perm,
'current_commit': current_commit,
'dir_list': dir_list,
'file_list': file_list,
'path': path,
'zipped': zipped,
'search_repo_id': search_repo_id,
}, context_instance=RequestContext(request))
开发者ID:jjjasont,项目名称:seahub,代码行数:43,代码来源:repo.py
示例7: prepare_property
def prepare_property(self):
# NOTE: order is important.
self.repo_id = self.get_repo_id()
self.user = self.get_user()
self.path = self.get_path()
self.parent_dir = self.get_parent_dir()
self.repo = self.get_repo(self.repo_id)
self.repo_size = self.get_repo_size()
self.user_perm = get_user_permission(self.request, self.repo_id)
self.current_commit = self.get_current_commit()
self.password_set = self.is_password_set()
if self.repo.encrypt and not self.password_set:
# Repo is encrypt and password is not set, then no need to
# query following informations.
self.file_list, self.dir_list = [], []
self.zipped = None
self.applet_root = None
else:
self.file_list, self.dir_list = get_repo_dirents(self.request, self.repo_id, self.current_commit, self.path)
self.zipped = self.get_nav_path()
self.applet_root = self.get_applet_root()
self.protocol = self.request.is_secure() and 'https' or 'http'
self.domain = RequestSite(self.request).domain
self.contacts = Contact.objects.filter(user_email=self.request.user.username)
开发者ID:orymate,项目名称:seahub,代码行数:24,代码来源:repo.py
示例8: render_repo
def render_repo(request, repo):
"""Steps to show repo page:
If user has permission to view repo
If repo is encrypt and password is not set on server
return decrypt repo page
If repo is not encrypt or password is set on server
Show repo direntries based on requested path
If user does not have permission to view repo
return permission deny page
"""
username = request.user.username
path = get_path_from_request(request)
user_perm = check_repo_access_permission(repo.id, request.user)
if user_perm is None:
return render_to_response('repo_access_deny.html', {
'repo': repo,
}, context_instance=RequestContext(request))
sub_lib_enabled = UserOptions.objects.is_sub_lib_enabled(username)
server_crypto = False
if repo.encrypted:
try:
server_crypto = UserOptions.objects.is_server_crypto(username)
except CryptoOptionNotSetError:
return render_to_response('options/set_user_options.html', {
}, context_instance=RequestContext(request))
if (repo.enc_version == 1 or (repo.enc_version == 2 and server_crypto)) \
and not is_password_set(repo.id, username):
return render_to_response('decrypt_repo_form.html', {
'repo': repo,
'next': get_next_url_from_request(request) or \
reverse('repo', args=[repo.id]),
'force_server_crypto': FORCE_SERVER_CRYPTO,
}, context_instance=RequestContext(request))
# query context args
fileserver_root = get_fileserver_root()
max_upload_file_size = get_max_upload_file_size()
protocol = request.is_secure() and 'https' or 'http'
domain = RequestSite(request).domain
for g in request.user.joined_groups:
g.avatar = grp_avatar(g.id, 20)
head_commit = get_commit(repo.id, repo.version, repo.head_cmmt_id)
if not head_commit:
raise Http404
if new_merge_with_no_conflict(head_commit):
info_commit = get_commit_before_new_merge(head_commit)
else:
info_commit = head_commit
repo_size = get_repo_size(repo.id)
no_quota = is_no_quota(repo.id)
if is_org_context(request):
repo_owner = seafile_api.get_org_repo_owner(repo.id)
else:
repo_owner = seafile_api.get_repo_owner(repo.id)
is_repo_owner = True if repo_owner == username else False
if is_repo_owner and not repo.is_virtual:
show_repo_settings = True
else:
show_repo_settings = False
more_start = None
file_list, dir_list, dirent_more = get_repo_dirents(request, repo,
head_commit, path,
offset=0, limit=100)
if dirent_more:
more_start = 100
zipped = get_nav_path(path, repo.name)
repo_groups = get_shared_groups_by_repo_and_user(repo.id, username)
if len(repo_groups) > 1:
repo_group_str = render_to_string("snippets/repo_group_list.html",
{'groups': repo_groups})
else:
repo_group_str = ''
upload_url = get_upload_url(request, repo.id)
fileshare = get_fileshare(repo.id, username, path)
dir_shared_link = get_dir_share_link(fileshare)
uploadlink = get_uploadlink(repo.id, username, path)
dir_shared_upload_link = get_dir_shared_upload_link(uploadlink)
return render_to_response('repo.html', {
'repo': repo,
'user_perm': user_perm,
'repo_owner': repo_owner,
'is_repo_owner': is_repo_owner,
'show_repo_settings': show_repo_settings,
'current_commit': head_commit,
'info_commit': info_commit,
'password_set': True,
'repo_size': repo_size,
'dir_list': dir_list,
'file_list': file_list,
#.........这里部分代码省略.........
开发者ID:bits4beats,项目名称:seahub,代码行数:101,代码来源:repo.py
示例9: view_shared_dir
def view_shared_dir(request, token):
assert token is not None # Checked by URLconf
fileshare = FileShare.objects.get_valid_dir_link_by_token(token)
if fileshare is None:
raise Http404
if fileshare.is_encrypted():
if not check_share_link_access(request.user.username, token):
d = {'token': token, 'view_name': 'view_shared_dir', }
if request.method == 'POST':
post_values = request.POST.copy()
post_values['enc_password'] = fileshare.password
form = SharedLinkPasswordForm(post_values)
d['form'] = form
if form.is_valid():
# set cache for non-anonymous user
if request.user.is_authenticated():
set_share_link_access(request.user.username, token)
else:
return render_to_response('share_access_validation.html', d,
context_instance=RequestContext(request))
else:
return render_to_response('share_access_validation.html', d,
context_instance=RequestContext(request))
username = fileshare.username
repo_id = fileshare.repo_id
path = request.GET.get('p', '')
path = fileshare.path if not path else path
if path[-1] != '/': # Normalize dir path
path += '/'
if not path.startswith(fileshare.path):
path = fileshare.path # Can not view upper dir of shared dir
repo = get_repo(repo_id)
if not repo:
raise Http404
# Check path still exist, otherwise show error
if not seafile_api.get_dir_id_by_path(repo.id, fileshare.path):
return render_error(request, _('"%s" does not exist.') % fileshare.path)
dir_name = os.path.basename(path[:-1])
current_commit = seaserv.get_commits(repo_id, 0, 1)[0]
file_list, dir_list, dirent_more = get_repo_dirents(request, repo,
current_commit, path)
zipped = gen_path_link(path, '')
if path == fileshare.path: # When user view the shared dir..
# increase shared link view_cnt,
fileshare = FileShare.objects.get(token=token)
fileshare.view_cnt = F('view_cnt') + 1
fileshare.save()
traffic_over_limit = user_traffic_over_limit(fileshare.username)
for f in file_list:
if allow_generate_thumbnail(username, repo, f):
f.allow_generate_thumbnail = True
if os.path.exists(os.path.join(THUMBNAIL_ROOT, THUMBNAIL_DEFAULT_SIZE, f.obj_id)):
f.thumbnail_src = get_thumbnail_src(repo.id, f.obj_id, THUMBNAIL_DEFAULT_SIZE)
return render_to_response('view_shared_dir.html', {
'repo': repo,
'token': token,
'path': path,
'username': username,
'dir_name': dir_name,
'file_list': file_list,
'dir_list': dir_list,
'zipped': zipped,
'traffic_over_limit': traffic_over_limit,
'ENABLE_THUMBNAIL': ENABLE_THUMBNAIL,
'PREVIEW_DEFAULT_SIZE': PREVIEW_DEFAULT_SIZE,
}, context_instance=RequestContext(request))
开发者ID:biddyweb,项目名称:seahub,代码行数:77,代码来源:repo.py
示例10: render_repo
def render_repo(request, repo):
"""Steps to show repo page:
If user has permission to view repo
If repo is encrypt and password is not set on server
return decrypt repo page
If repo is not encrypt or password is set on server
Show repo direntries based on requested path
If user does not have permission to view repo
return permission deny page
"""
username = request.user.username
path = get_path_from_request(request)
user_perm = check_repo_access_permission(repo.id, username)
if user_perm is None:
return render_to_response("repo_access_deny.html", {"repo": repo}, context_instance=RequestContext(request))
if (
repo.encrypted
and (repo.enc_version == 1 or (repo.enc_version == 2 and SERVER_CRYPTO))
and not is_password_set(repo.id, username)
):
return render_to_response(
"decrypt_repo_form.html",
{"repo": repo, "next": get_next_url_from_request(request) or reverse("repo", args=[repo.id])},
context_instance=RequestContext(request),
)
# query context args
applet_root = get_ccnetapplet_root()
httpserver_root = get_httpserver_root()
max_upload_file_size = MAX_UPLOAD_FILE_SIZE
protocol = request.is_secure() and "https" or "http"
domain = RequestSite(request).domain
contacts = Contact.objects.get_contacts_by_user(username)
accessible_repos = [repo] if repo.encrypted else get_unencry_rw_repos_by_user(username)
head_commit = get_commit(repo.head_cmmt_id)
if not head_commit:
raise Http404
repo_size = get_repo_size(repo.id)
no_quota = is_no_quota(repo.id)
search_repo_id = None if repo.encrypted else repo.id
repo_owner = seafile_api.get_repo_owner(repo.id)
is_repo_owner = True if repo_owner == username else False
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)
repo_groups = get_shared_groups_by_repo_and_user(repo.id, username)
if len(repo_groups) > 1:
repo_group_str = render_to_string("snippets/repo_group_list.html", {"groups": repo_groups})
else:
repo_group_str = ""
upload_url = get_upload_url(request, repo.id)
if repo.encrypted and repo.enc_version == 2 and not SERVER_CRYPTO:
ajax_upload_url = get_blks_upload_url(request, repo.id)
ajax_update_url = get_blks_update_url(request, repo.id)
else:
ajax_upload_url = get_ajax_upload_url(request, repo.id)
ajax_update_url = get_ajax_update_url(request, repo.id)
fileshare = get_fileshare(repo.id, username, path)
dir_shared_link = get_dir_share_link(fileshare)
joined_groups = get_personal_groups_by_user(request.user.username)
return render_to_response(
"repo.html",
{
"repo": repo,
"user_perm": user_perm,
"repo_owner": repo_owner,
"is_repo_owner": is_repo_owner,
"current_commit": head_commit,
"password_set": True,
"repo_size": repo_size,
"dir_list": dir_list,
"file_list": file_list,
"dirent_more": dirent_more,
"more_start": more_start,
"path": path,
"zipped": zipped,
"accessible_repos": accessible_repos,
"applet_root": applet_root,
"groups": repo_groups,
"joined_groups": joined_groups,
"repo_group_str": repo_group_str,
"no_quota": no_quota,
"max_upload_file_size": max_upload_file_size,
"upload_url": upload_url,
"ajax_upload_url": ajax_upload_url,
"ajax_update_url": ajax_update_url,
"httpserver_root": httpserver_root,
"protocol": protocol,
"domain": domain,
"contacts": contacts,
#.........这里部分代码省略.........
开发者ID:vIiRuS,项目名称:seahub,代码行数:101,代码来源:repo.py
示例11: list_dir
def list_dir(request, repo_id):
"""
List directory entries in 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)
sub_lib_enabled = UserOptions.objects.is_sub_lib_enabled(username)
try:
server_crypto = UserOptions.objects.is_server_crypto(username)
except CryptoOptionNotSetError:
# Assume server_crypto is ``False`` if this option is not set.
server_crypto = False
if repo.encrypted and \
(repo.enc_version == 1 or (repo.enc_version == 2 and server_crypto)) \
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 + '/'
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)
uploadlink = get_uploadlink(repo.id, username, path)
dir_shared_upload_link = get_dir_shared_upload_link(uploadlink)
ctx = {
'repo': repo,
'zipped': zipped,
'user_perm': user_perm,
'path': path,
'server_crypto': server_crypto,
'fileshare': fileshare,
'dir_shared_link': dir_shared_link,
'uploadlink': uploadlink,
'dir_shared_upload_link': dir_shared_upload_link,
'dir_list': dir_list,
'file_list': file_list,
'dirent_more': dirent_more,
'more_start': more_start,
'ENABLE_SUB_LIBRARY': settings.ENABLE_SUB_LIBRARY,
"sub_lib_enabled": sub_lib_enabled,
}
html = render_to_string('snippets/repo_dir_data.html', ctx,
context_instance=RequestContext(request))
return HttpResponse(json.dumps({'html': html, 'path': path}),
content_type=content_type)
开发者ID:mhltlyc,项目名称:seahub,代码行数:78,代码来源:ajax.py
示例12: view_shared_dir
def view_shared_dir(request, token):
assert token is not None # Checked by URLconf
fileshare = FileShare.objects.get_valid_dir_link_by_token(token)
if fileshare is None:
raise Http404
if fileshare.is_encrypted():
if not check_share_link_access(request, token):
d = {'token': token, 'view_name': 'view_shared_dir', }
if request.method == 'POST':
post_values = request.POST.copy()
post_values['enc_password'] = fileshare.password
form = SharedLinkPasswordForm(post_values)
d['form'] = form
if form.is_valid():
set_share_link_access(request, token)
else:
return render_to_response('share_access_validation.html', d,
context_instance=RequestContext(request))
else:
return render_to_response('share_access_validation.html', d,
context_instance=RequestContext(request))
username = fileshare.username
repo_id = fileshare.repo_id
# Get path from frontend, use '/' if missing, and construct request path
# with fileshare.path to real path, used to fetch dirents by RPC.
req_path = request.GET.get('p', '/')
if req_path[-1] != '/':
req_path += '/'
if req_path == '/':
real_path = fileshare.path
else:
real_path = posixpath.join(fileshare.path, req_path.lstrip('/'))
if real_path[-1] != '/': # Normalize dir path
real_path += '/'
repo = get_repo(repo_id)
if not repo:
raise Http404
# Check path still exist, otherwise show error
if not seafile_api.get_dir_id_by_path(repo.id, fileshare.path):
return render_error(request, _('"%s" does not exist.') % fileshare.path)
# download shared dir
if request.GET.get('dl', '') == '1':
return _download_dir_from_share_link(request, fileshare, repo,
real_path)
if fileshare.path == '/':
# use repo name as dir name if share whole library
dir_name = repo.name
else:
dir_name = os.path.basename(real_path[:-1])
current_commit = seaserv.get_commits(repo_id, 0, 1)[0]
file_list, dir_list, dirent_more = get_repo_dirents(request, repo,
current_commit, real_path)
# generate dir navigator
if fileshare.path == '/':
zipped = gen_path_link(req_path, repo.name)
else:
zipped = gen_path_link(req_path, os.path.basename(fileshare.path[:-1]))
if req_path == '/': # When user view the root of shared dir..
# increase shared link view_cnt,
fileshare = FileShare.objects.get(token=token)
fileshare.view_cnt = F('view_cnt') + 1
fileshare.save()
traffic_over_limit = user_traffic_over_limit(fileshare.username)
for f in file_list:
file_type, file_ext = get_file_type_and_ext(f.obj_name)
if file_type == IMAGE:
f.is_img = True
if allow_generate_thumbnail(username, repo, f):
f.allow_generate_thumbnail = True
if os.path.exists(os.path.join(THUMBNAIL_ROOT, THUMBNAIL_DEFAULT_SIZE, f.obj_id)):
f.thumbnail_src = get_thumbnail_src(repo.id, f.obj_id, THUMBNAIL_DEFAULT_SIZE)
return render_to_response('view_shared_dir.html', {
'repo': repo,
'token': token,
'path': req_path,
'username': username,
'dir_name': dir_name,
'file_list': file_list,
'dir_list': dir_list,
'zipped': zipped,
'traffic_over_limit': traffic_over_limit,
'ENABLE_THUMBNAIL': ENABLE_THUMBNAIL,
'PREVIEW_DEFAULT_SIZE': PREVIEW_DEFAULT_SIZE,
}, context_instance=RequestContext(request))
开发者ID:InfoTestStg,项目名称:seahub,代码行数:99,代码来源:repo.py
示例13: view_shared_dir
def view_shared_dir(request, token):
assert token is not None # Checked by URLconf
fileshare = FileShare.objects.get_valid_dir_link_by_token(token)
if fileshare is None:
raise Http404
if fileshare.is_encrypted():
if not check_share_link_access(request.user.username, token):
d = {"token": token, "view_name": "view_shared_dir"}
if request.method == "POST":
post_values = request.POST.copy()
post_values["enc_password"] = fileshare.password
form = SharedLinkPasswordForm(post_values)
d["form"] = form
if form.is_valid():
# set cache for non-anonymous user
if request.user.is_authenticated():
set_share_link_access(request.user.username, token)
else:
return render_to_response(
"share_access_validation.html", d, context_instance=RequestContext(request)
)
else:
return render_to_response("share_access_validation.html", d, context_instance=RequestContext(request))
username = fileshare.username
repo_id = fileshare.repo_id
path = request.GET.get("p", "")
path = fileshare.path if not path else path
if path[-1] != "/": # Normalize dir path
path += "/"
if not path.startswith(fileshare.path):
path = fileshare.path # Can not view upper dir of shared dir
repo = get_repo(repo_id)
if not repo:
raise Http404
dir_name = os.path.basename(path[:-1])
current_commit = seaserv.get_commits(repo_id, 0, 1)[0]
file_list, dir_list = get_repo_dirents(request, repo, current_commit, path)
zipped = gen_path_link(path, "")
if path == fileshare.path: # When user view the shared dir..
# increase shared link view_cnt,
fileshare = FileShare.objects.get(token=token)
fileshare.view_cnt = F("view_cnt") + 1
fileshare.save()
traffic_over_limit = user_traffic_over_limit(fileshare.username)
return render_to_response(
"view_shared_dir.html",
{
"repo": repo,
"token": token,
"path": path,
"username": username,
"dir_name": dir_name,
"file_list": file_list,
"dir_list": dir_list,
"zipped": zipped,
"traffic_over_limit": traffic_over_limit,
},
context_instance=RequestContext(request),
)
开发者ID:vikingliu,项目名称:seahub,代码行数:68,代码来源:repo.py
示例14: render_repo
def render_repo(request, repo):
"""Steps to show repo page:
If user has permission to view repo
If repo is encrypt and password is not set on server
return decrypt repo page
If repo is not encrypt or password is set on server
Show repo direntries based on requested path
If user does not have permission to view repo
return permission deny page
"""
username = request.user.username
path = get_path_from_request(request)
user_perm = check_repo_access_permission(repo.id, username)
if user_perm is None:
return render_to_response('repo_access_deny.html', {
'repo': repo,
}, context_instance=RequestContext(request))
server_crypto = False
if repo.encrypted:
try:
server_crypto = UserOptions.objects.is_server_crypto(username)
except CryptoOptionNotSetError:
return render_to_response('options/set_user_options.html', {
}, context_instance=RequestContext(request))
if (repo.enc_version == 1 or (repo.enc_version == 2 and server_crypto)) \
and not is_password_set(repo.id, username):
return render_to_response('decrypt_repo_form.html', {
'repo': repo,
'next': get_next_url_from_request(request) or \
reverse('repo', args=[repo.id])
}, context_instance=RequestContext(request))
# query context args
applet_root = get_ccnetapplet_root()
httpserver_root = get_httpserver_root()
max_upload_file_size = MAX_UPLOAD_FILE_SIZE
protocol = request.is_secure() and 'https' or 'http'
domain = RequestSite(request).domain
contacts = Contact.objects.get_contacts_by_user(username)
accessible_repos = [repo] if repo.encrypted else get_unencry_rw_repos_by_user(username)
joined_groups = get_personal_groups_by_user(request.user.username)
head_commit = get_commit(repo.head_cmmt_id)
if not head_commit:
raise Http404
repo_size = get_repo_size(repo.id)
no_quota = is_no_quota(repo.id)
search_repo_id = None if repo.encrypted else repo.id
repo_owner = seafile_api.get_repo_owner(repo.id)
is_repo_owner = True if repo_owner == username else False
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)
repo_groups = get_shared_groups_by_repo_and_user(repo.id, username)
if len(repo_groups) > 1:
repo_group_str = render_to_string("snippets/repo_group_list.html",
{'groups': repo_groups})
else:
repo_group_str = ''
upload_url = get_upload_url(request, repo.id)
if repo.encrypted and repo.enc_version == 2 and not server_crypto:
ajax_upload_url = get_blks_upload_url(request, repo.id)
ajax_update_url = get_blks_update_url(request, repo.id)
else:
ajax_upload_url = get_ajax_upload_url(request, repo.id)
ajax_update_url = get_ajax_update_url(request, repo.id)
fileshare = get_fileshare(repo.id, username, path)
dir_shared_link = get_dir_share_link(fileshare)
uploadlink = get_uploadlink(repo.id, username, path)
dir_shared_upload_link = get_dir_shared_upload_link(uploadlink)
return render_to_response('repo.html', {
'repo': repo,
'user_perm': user_perm,
'repo_owner': repo_owner,
'is_repo_owner': is_repo_owner,
'current_commit': head_commit,
'password_set': True,
'repo_size': repo_size,
'dir_list': dir_list,
'file_list': file_list,
'dirent_more': dirent_more,
'more_start': more_start,
'path': path,
'zipped': zipped,
'accessible_repos': accessible_repos,
'applet_root': applet_root,
'groups': repo_groups,
'joined_groups': joined_groups,
'repo_group_str': repo_group_str,
'no_quota': no_quota,
'max_upload_file_size': max_upload_file_size,
#.........这里部分代码省略.........
开发者ID:unixcrh,项目名称:seahub,代码行数:101,代码来源:repo.py
示例15: render_repo
def render_repo(request, repo):
"""Steps to show repo page:
If user has permission to view repo
If repo is encrypt and password is not set on server
return decrypt repo page
If repo is not encrypt or password is set on server
Show repo direntries based on requested path
If user does not have permission to view repo
return permission deny page
"""
username = request.user.username
path = get_path_from_request(request)
user_perm = check_repo_access_permission(repo.id, request.user)
if user_perm is None:
return render_to_response("repo_access_deny.html", {"repo": repo}, context_instance=RequestContext(request))
sub_lib_enabled = UserOptions.objects.is_sub_lib_enabled(username)
server_crypto = False
if repo.encrypted:
try:
server_crypto = UserOptions.objects.is_server_crypto(username)
except CryptoOptionNotSetError:
return render_to_response("options/set_user_options.html", {}, context_instance=RequestContext(request))
if (repo.enc_version == 1 or (repo.enc_version == 2 and server_crypto)) and not is_password_set(
repo.id, username
):
return render_to_response(
"decrypt_repo_form.html",
{
"repo": repo,
"next": get_next_url_from_request(request) or reverse("repo", args=[repo.id]),
"force_server_crypto": FORCE_SERVER_CRYPTO,
},
context_instance=RequestContext(request),
)
# query context args
fileserver_root = get_fileserver_root()
max_upload_file_size = get_max_upload_file_size()
protocol = request.is_secure() and "https" or "http"
domain = RequestSite(request).domain
for g in request.user.joined_groups:
g.avatar = grp_avatar(g.id, 20)
head_commit = get_commit(repo.id, repo.version, repo.head_cmmt_id)
if not head_commit:
raise Http404
if new_merge_with_no_conflict(head_commit):
info_commit = get_commit_before_new_merge(head_commit)
else:
info_commit = head_commit
repo_size = get_repo_size(repo.id)
no_quota = is_no_quota(repo.id)
if is_org_context(request):
repo_owner = seafile_api.get_org_repo_owner(repo.id)
else:
repo_owner = seafile_api.get_repo_owner(repo.id)
is_repo_owner = True if repo_owner == username else False
if is_repo_owner and not repo.is_virtual:
show_repo_settings = True
else:
show_repo_settings = False
more_start = None
file_list, dir_list, dirent_more = get_repo_dirents(request, repo, head_commit, path, offset=0, limit=100)
if dirent_more:
more_start = 100
zipped = get_nav_path(path, repo.name)
repo_groups = get_shared_groups_by_repo_and_user(repo.id, username)
if len(repo_groups) > 1:
repo_group_str = render_to_string("snippets/repo_group_list.html", {"groups": repo_groups})
else:
repo_group_str = ""
upload_url = get_upload_url(request, repo.id)
fileshare = get_fileshare(repo.id, username, path)
dir_shared_link = get_dir_share_link(fileshare)
uploadlink = get_uploadlink(repo.id, username, path)
dir_shared_upload_link = get_dir_shared_upload_link(uploadlink)
return render_to_response(
"repo.html",
{
"repo": repo,
"user_perm": user_perm,
"repo_owner": repo_owner,
"is_repo_owner": is_repo_owner,
"show_repo_settings": show_repo_settings,
"current_commit": head_commit,
"info_commit": info_commit,
"password_set": True,
"repo_size": repo_size,
"dir_list": dir_list,
"file_list": file_list,
#.........这里部分代码
|
请发表评论