From 8535f961ec778d0e609c2cf05009f41530ef3b05 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 17 Sep 2010 23:06:01 +0200 Subject: [PATCH] upload requested files --- pandora/archive/models.py | 3 ++- pandora/archive/views.py | 11 +++++++---- pandora/static/js/pandora.local.js | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/pandora/archive/models.py b/pandora/archive/models.py index 3142f118..21ef4862 100644 --- a/pandora/archive/models.py +++ b/pandora/archive/models.py @@ -144,7 +144,8 @@ class File(models.Model): data = models.FileField(null=True, blank=True, upload_to=lambda f, x: file_path(f, 'data.raw')) def contents(self): - if self.data: + if self.data != None: + self.data.seek(0) return self.data.read() return None diff --git a/pandora/archive/views.py b/pandora/archive/views.py index 87fbed24..62a35ced 100644 --- a/pandora/archive/views.py +++ b/pandora/archive/views.py @@ -67,7 +67,7 @@ def api_update(request): user = request.user response = json_response({'info': [], 'data': [], 'file': []}) - + volume = None if 'files' in data: volume, created = models.Volume.objects.get_or_create(user=user, name=data['volume']) all_files = [] @@ -149,6 +149,8 @@ def api_update(request): instance.file.save() files = models.FileInstance.objects.filter(volume__user=user, file__available=False) + if volume: + files = files.filter(volume=volume) response['data']['info'] = [f.file.oshash for f in files.filter(file__info='{}')] #needs some flag to find those that are actually used main is to generic response['data']['data'] = [f.file.oshash for f in files.filter(file__is_video=True, file__is_main=True)] @@ -169,7 +171,6 @@ def api_upload(request): ''' user = request.user f = get_object_or_404(models.File, oshash=request.POST['oshash']) - print request.FILES if 'frame' in request.FILES: if f.frames.count() == 0: for frame in request.FILES.getlist('frame'): @@ -183,9 +184,11 @@ def api_upload(request): else: response = json_response(status=403, text='permissino denied') if 'file' in request.FILES: - if not f.data: + if not f.available: f.data.save('data.raw', request.FILES['file']) - response = json_response({}) + f.available = True + f.save() + response = json_response(status=200, text='file saved') else: response = json_response(status=403, text='permissino denied') return render_to_json_response(response) diff --git a/pandora/static/js/pandora.local.js b/pandora/static/js/pandora.local.js index af120047..1c2298d6 100644 --- a/pandora/static/js/pandora.local.js +++ b/pandora/static/js/pandora.local.js @@ -191,6 +191,20 @@ app.afterLaunch.push(function() { } ); }, + uploadFile: function(oshash) { + Ox.print('upload file', oshash); + var url = app.local.absolute_url('/api/'); + app.local.upload({ + url: url, + data: {action: 'upload', oshash: oshash}, + oshash: oshash, + action: 'file' + }, + function(result) { + Ox.print(result); + } + ); + }, cancel: function(oshash) { Ox.print('this function needs to be implemented: cancel ', oshash); }, @@ -251,6 +265,7 @@ app.afterLaunch.push(function() { }, function(result) { var videos = {}; function parseResult(result) { + //extract and upload requested videos $.each(result.data.data, function(i, oshash) { $.each(folder_ids, function(i, ids) { if($.inArray(oshash, ids) > -1) { @@ -293,6 +308,10 @@ app.afterLaunch.push(function() { } }); }); + //upload requested files + $.each(result.data.file, function(i, oshash) { + app.local.uploadFile(oshash); + }); }; if (result.data.info.length>0) { var post = {'info': {}};