upload requested files

This commit is contained in:
j 2010-09-17 23:06:01 +02:00
parent 37ed99d029
commit 8535f961ec
3 changed files with 28 additions and 5 deletions

View file

@ -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')) data = models.FileField(null=True, blank=True, upload_to=lambda f, x: file_path(f, 'data.raw'))
def contents(self): def contents(self):
if self.data: if self.data != None:
self.data.seek(0)
return self.data.read() return self.data.read()
return None return None

View file

@ -67,7 +67,7 @@ def api_update(request):
user = request.user user = request.user
response = json_response({'info': [], 'data': [], 'file': []}) response = json_response({'info': [], 'data': [], 'file': []})
volume = None
if 'files' in data: if 'files' in data:
volume, created = models.Volume.objects.get_or_create(user=user, name=data['volume']) volume, created = models.Volume.objects.get_or_create(user=user, name=data['volume'])
all_files = [] all_files = []
@ -149,6 +149,8 @@ def api_update(request):
instance.file.save() instance.file.save()
files = models.FileInstance.objects.filter(volume__user=user, file__available=False) 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='{}')] 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 #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)] 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 user = request.user
f = get_object_or_404(models.File, oshash=request.POST['oshash']) f = get_object_or_404(models.File, oshash=request.POST['oshash'])
print request.FILES
if 'frame' in request.FILES: if 'frame' in request.FILES:
if f.frames.count() == 0: if f.frames.count() == 0:
for frame in request.FILES.getlist('frame'): for frame in request.FILES.getlist('frame'):
@ -183,9 +184,11 @@ def api_upload(request):
else: else:
response = json_response(status=403, text='permissino denied') response = json_response(status=403, text='permissino denied')
if 'file' in request.FILES: if 'file' in request.FILES:
if not f.data: if not f.available:
f.data.save('data.raw', request.FILES['file']) 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: else:
response = json_response(status=403, text='permissino denied') response = json_response(status=403, text='permissino denied')
return render_to_json_response(response) return render_to_json_response(response)

View file

@ -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) { cancel: function(oshash) {
Ox.print('this function needs to be implemented: cancel ', oshash); Ox.print('this function needs to be implemented: cancel ', oshash);
}, },
@ -251,6 +265,7 @@ app.afterLaunch.push(function() {
}, function(result) { }, function(result) {
var videos = {}; var videos = {};
function parseResult(result) { function parseResult(result) {
//extract and upload requested videos
$.each(result.data.data, function(i, oshash) { $.each(result.data.data, function(i, oshash) {
$.each(folder_ids, function(i, ids) { $.each(folder_ids, function(i, ids) {
if($.inArray(oshash, ids) > -1) { 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) { if (result.data.info.length>0) {
var post = {'info': {}}; var post = {'info': {}};