Commit ffd2f97b by Dányi Bence

store: ajax download

parent 3268f041
...@@ -28,4 +28,5 @@ urlpatterns = patterns('', ...@@ -28,4 +28,5 @@ urlpatterns = patterns('',
url(r'^store/top/$', 'store.views.toplist', name='store_top'), url(r'^store/top/$', 'store.views.toplist', name='store_top'),
url(r'^ajax/templateWizard$', 'one.views.ajax_template_wizard', name='ajax_template_wizard'), url(r'^ajax/templateWizard$', 'one.views.ajax_template_wizard', name='ajax_template_wizard'),
url(r'^ajax/store/list$', 'store.views.ajax_listfolder', name='store_ajax_listfolder'), url(r'^ajax/store/list$', 'store.views.ajax_listfolder', name='store_ajax_listfolder'),
url(r'^ajax/store/download$', 'store.views.ajax_download', name='store_ajax_download'),
) )
...@@ -112,13 +112,22 @@ $(function(){ ...@@ -112,13 +112,22 @@ $(function(){
}; };
} else { } else {
viewData[i]={ viewData[i]={
originalName: d.NAME,
name: d.NAME.length>30?(d.NAME.substr(0,27)+'...'):d.NAME, name: d.NAME.length>30?(d.NAME.substr(0,27)+'...'):d.NAME,
size: data[i].SIZE+'K', size: data[i].SIZE+'K',
type: 'fájl', type: 'fájl',
mTime: d.MTIME, mTime: d.MTIME,
getTypeClass: 'name filetype-text', getTypeClass: 'name filetype-text',
clickHandler: function(){ clickHandler: function(item){
$.ajax({
type: 'POST',
data: 'dl='+self.currentPath()+item.originalName,
url: '/ajax/store/download',
dataType: 'json',
success: function(data){
window.location.href=data.url;
}
})
} }
}; };
} }
......
...@@ -211,7 +211,7 @@ ...@@ -211,7 +211,7 @@
<div class="actions"> <div class="actions">
<a href="#"><img src="/static/icons/pencil.png" alt="rename" /></a> <a href="#"><img src="/static/icons/pencil.png" alt="rename" /></a>
<a href="#"><img src="/static/icons/minus-circle.png" alt="delete" /></a> <a href="#"><img src="/static/icons/minus-circle.png" alt="delete" /></a>
<a href="#"><img src="/static/icons/download-cloud.png" alt="download" /></a> <a href="#" data-bind="click: clickHandler"><img src="/static/icons/download-cloud.png" alt="download" /></a>
</div> </div>
<div class="clear"></div> <div class="clear"></div>
</div> </div>
......
...@@ -68,7 +68,6 @@ def index(request): ...@@ -68,7 +68,6 @@ def index(request):
file_list = StoreApi.listfolder(user,path) file_list = StoreApi.listfolder(user,path)
return render_to_response('store/list.html', RequestContext(request, {'file_list': file_list, 'path' : path, 'backpath' : backpath, 'username' : user})) return render_to_response('store/list.html', RequestContext(request, {'file_list': file_list, 'path' : path, 'backpath' : backpath, 'username' : user}))
@csrf_exempt
@login_required @login_required
def ajax_listfolder(request): def ajax_listfolder(request):
user = request.user.username user = request.user.username
...@@ -95,6 +94,27 @@ def ajax_listfolder(request): ...@@ -95,6 +94,27 @@ def ajax_listfolder(request):
return HttpResponse(json.dumps(file_list)) return HttpResponse(json.dumps(file_list))
@login_required @login_required
def ajax_download(request):
user = request.user.username
try:
details = request.user.userclouddetails_set.all()[0]
password = details.smb_password
key_list = []
for key in request.user.sshkey_set.all():
key_list.append(key.key)
except:
return HttpResponse('Can not acces to django database!', status_code=404)
if StoreApi.userexist(user) != True:
if not StoreApi.createuser(user,password,key_list):
return HttpResponse('User does not exist on store! And could not create!', status_code=404)
try:
dl = request.POST['dl']
return HttpResponse(json.dumps({'url':StoreApi.requestdownload(user,dl)}))
except:
pass
return HttpResponse('File not found!', status_code=404)
@login_required
def toplist(request): def toplist(request):
user = request.user.username user = request.user.username
path = backpath = '/' path = backpath = '/'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment