1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-02 07:27:04 +00:00

Add basic download feature

This commit is contained in:
xiez
2012-04-24 22:31:24 +08:00
parent f4002df715
commit e4fad50b43
4 changed files with 27 additions and 15 deletions

View File

@@ -13,18 +13,17 @@
{% if owned_repos %} {% if owned_repos %}
<table class="repo-list"> <table class="repo-list">
<tr> <tr>
<th width="12%">名字</th> <th width="30%">名字</th>
<th width="33%">ID</th> <th width="50%">描述</th>
<th width="40%">描述</th> <th width="20%">操作</th>
<th width="15%">操作</th>
</tr> </tr>
{% for repo in owned_repos %} {% for repo in owned_repos %}
<tr> <tr>
<td><a href="{{ SITE_ROOT }}repo/{{ repo.props.id }}">{{ repo.props.name }}</a></td> <td><a href="{{ SITE_ROOT }}repo/{{ repo.props.id }}">{{ repo.props.name }}</a></td>
<td>{{ repo.props.id }}</td>
<td>{{ repo.props.desc }}</td> <td>{{ repo.props.desc }}</td>
<td> <td>
<button data="{{ SITE_ROOT }}repo/download/{{ repo.props.id }}/" class="repo-download-btn">下载</button>
<button data="{{ repo.props.id }}" class="repo-share-btn">共享</button> <button data="{{ repo.props.id }}" class="repo-share-btn">共享</button>
<button data="{{ SITE_ROOT }}repo/remove/{{ repo.props.id }}/" class="repo-delete-btn">删除</button> <button data="{{ SITE_ROOT }}repo/remove/{{ repo.props.id }}/" class="repo-delete-btn">删除</button>
</td> </td>
@@ -39,18 +38,17 @@
{% if fetched_repos %} {% if fetched_repos %}
<table class="repo-list"> <table class="repo-list">
<tr> <tr>
<th width="12%">名字</th> <th width="30%">名字</th>
<th width="33%">ID</th> <th width="50%">描述</th>
<th width="40%">描述</th> <th width="20%">操作</th>
<th width="15%">操作</th>
</tr> </tr>
{% for repo in fetched_repos %} {% for repo in fetched_repos %}
<tr> <tr>
<td><a href="{{ SITE_ROOT }}repo/{{ repo.props.id }}">{{ repo.props.name }}</a></td> <td><a href="{{ SITE_ROOT }}repo/{{ repo.props.id }}">{{ repo.props.name }}</a></td>
<td>{{ repo.props.id }}</td>
<td>{{ repo.props.desc }}</td> <td>{{ repo.props.desc }}</td>
<td> <td>
<button data="{{ SITE_ROOT }}repo/download/{{ repo.props.id }}/" class="repo-download-btn">下载</button>
<button data="{{ SITE_ROOT }}repo/removefetched/{{ repo.userid }}/{{ repo.props.id }}/" class="repo-delete-btn">删除</button> <button data="{{ SITE_ROOT }}repo/removefetched/{{ repo.userid }}/{{ repo.props.id }}/" class="repo-delete-btn">删除</button>
</td> </td>
</tr> </tr>
@@ -60,7 +58,7 @@
<p>暂无</p> <p>暂无</p>
{% endif %} {% endif %}
<form id="repo-share-form" action="/repo/addshare/" method="post" name="repo-share-form" class="hide"> <form id="repo-share-form" action="{{ SITE_ROOT }}shareadmin/addshare/" method="post" name="repo-share-form" class="hide">
<label>邮箱</label><br /> <label>邮箱</label><br />
<input id="to_email" type="text" name="to_email" value="" maxlength="40" /><br/> <input id="to_email" type="text" name="to_email" value="" maxlength="40" /><br/>
<input id="share_repo_id" type="hidden" name="share_repo_id" value="" /> <input id="share_repo_id" type="hidden" name="share_repo_id" value="" />
@@ -77,6 +75,10 @@ $(".repo-share-btn").click(function() {
$("#repo-share-form").modal({appendTo: "#main", containerCss:{padding:18}}); $("#repo-share-form").modal({appendTo: "#main", containerCss:{padding:18}});
}); });
$(".repo-download-btn").click(function() {
location.href = $(this).attr("data");
});
addConfirmTo($('.repo-delete-btn')); addConfirmTo($('.repo-delete-btn'));
</script> </script>
{% endblock %} {% endblock %}

View File

@@ -45,7 +45,7 @@
<td>{{ repo.props.shared_email }}</td> <td>{{ repo.props.shared_email }}</td>
<td>{{ repo.props.desc }}</td> <td>{{ repo.props.desc }}</td>
<td> <td>
<a href="#">下载</a> <a href="{{ SITE_ROOT }}repo/download/{{ repo.props.id }}/" target="_blank">下载</a>
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}

View File

@@ -7,7 +7,7 @@ from seahub.views import root, peers, groups, myhome, \
role_add, role_remove, activate_user, user_add, user_remove, \ role_add, role_remove, activate_user, user_add, user_remove, \
ownerhome, remove_fetched_repo, repo_set_public, repo_unset_public, \ ownerhome, remove_fetched_repo, repo_set_public, repo_unset_public, \
repo_list_dir, user_info, repo_set_access_property, repo_operation_file, \ repo_list_dir, user_info, repo_set_access_property, repo_operation_file, \
repo_add_share, repo_list_share, repo_remove_share repo_add_share, repo_list_share, repo_remove_share, repo_download
# Uncomment the next two lines to enable the admin: # Uncomment the next two lines to enable the admin:
#from django.contrib import admin #from django.contrib import admin
@@ -29,9 +29,9 @@ urlpatterns = patterns('',
(r'^$', root), (r'^$', root),
url(r'^home/my/$', myhome, name='myhome'), url(r'^home/my/$', myhome, name='myhome'),
url(r'^home/owner/(?P<owner_name>[^/]+)/$', ownerhome, name='ownerhome'), url(r'^home/owner/(?P<owner_name>[^/]+)/$', ownerhome, name='ownerhome'),
url(r'^repo/addshare/$', repo_add_share, name='repo_add_share'),
url(r'^shareadmin/$', repo_list_share, name='repo_list_share'), url(r'^shareadmin/$', repo_list_share, name='repo_list_share'),
(r'^shareadmin/remove/(?P<repo_id>[^/]+)/(?P<to_email>[^/]+)/$', repo_remove_share), url(r'^shareadmin/addshare/$', repo_add_share, name='repo_add_share'), (r'^shareadmin/remove/(?P<repo_id>[^/]+)/(?P<to_email>[^/]+)/$', repo_remove_share),
(r'^download/$', direct_to_template, { 'template': 'download.html' } ), (r'^download/$', direct_to_template, { 'template': 'download.html' } ),
(r'^repo/(?P<repo_id>[^/]+)/$', repo), (r'^repo/(?P<repo_id>[^/]+)/$', repo),
@@ -43,6 +43,7 @@ urlpatterns = patterns('',
(r'^repo/setap/(?P<repo_id>[^/]+)/(?P<ap>[^/]+)/$', repo_set_access_property), (r'^repo/setap/(?P<repo_id>[^/]+)/(?P<ap>[^/]+)/$', repo_set_access_property),
(r'^repo/dir/(?P<repo_id>[^/]+)/$', repo_list_dir), (r'^repo/dir/(?P<repo_id>[^/]+)/$', repo_list_dir),
(r'^repo/(?P<op>[^/]+)/(?P<repo_id>[^/]+)/(?P<obj_id>[^/]+)/(?P<file_name>[^/]+)/$', repo_operation_file), (r'^repo/(?P<op>[^/]+)/(?P<repo_id>[^/]+)/(?P<obj_id>[^/]+)/(?P<file_name>[^/]+)/$', repo_operation_file),
(r'^repo/download/(?P<repo_id>[^/]+)/$', repo_download),
(r'^seafadmin/$', seafadmin), (r'^seafadmin/$', seafadmin),
url(r'^useradmin/$', useradmin, name='useradmin'), url(r'^useradmin/$', useradmin, name='useradmin'),

View File

@@ -355,6 +355,15 @@ def repo_list_share(request):
"in_repos": in_repos, "in_repos": in_repos,
}, context_instance=RequestContext(request)) }, context_instance=RequestContext(request))
@login_required
def repo_download(request, repo_id):
relay_id = cclient.props.id
token = 'default'
redirect_url = "http://localhost:8083/repo/download/?repo_id=%s&token=%s&relay_id=%s" % (repo_id, token, relay_id)
return HttpResponseRedirect(redirect_url)
@login_required @login_required
def repo_remove_share(request, repo_id, to_email): def repo_remove_share(request, repo_id, to_email):
if not validate_owner(request, repo_id): if not validate_owner(request, repo_id):