From 82336011d586f2e8e21ffc65670019a0c81d2008 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 3 Jul 2011 20:30:47 +0200 Subject: [PATCH] move files --- pandora/archive/views.py | 28 ++++++++++++++++++---------- static/js/pandora/ui/Ox.FilesView.js | 17 ++++++++++------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/pandora/archive/views.py b/pandora/archive/views.py index 429cd2167..a87b17bf5 100644 --- a/pandora/archive/views.py +++ b/pandora/archive/views.py @@ -185,7 +185,7 @@ def firefogg_upload(request): f.save() #FIXME: this fails badly if rabbitmq goes down try: - t = item.tasks.update_streams.delay((f.item.itemId)) + t = item.tasks.update_streams.delay(f.item.itemId) response['resultUrl'] = t.task_id except: pass @@ -237,20 +237,28 @@ def moveFiles(request): } } ''' - #FIXME: permissions, need to be checked data = json.loads(request.POST['data']) + if models.Item.objects.filter(itemId=data['itemId']).count() == 1: + item = models.Item.objects.get(itemId=data['itemId']) + else: + if len(data['itemId']) != 7: + del data['itemId'] + item = get_item(data) + else: + item = get_item({'imdbId': data['itemId']}) + changed = [] for f in models.File.objects.filter(oshash__in=data['ids']): - if f.item.id != data['itemId']: - if len(data['itemId']) != 7: - folder = f.instances.all()[0].folder - item_info = utils.parse_path(folder) - item = get_item(item_info) - else: - item = get_item({'imdbId': data['itemId']}) + if f.item.id != data['itemId'] and f.editable(request.user): + if f.item.itemId not in changed: + changed.append(f.item.itemId) + if item.itemId not in changed: + changed.append(item.itemId) f.item = item f.save() - #FIXME: other things might need updating here + for itemId in changed: + item.tasks.update_streams.delay(itemId) response = json_response(text='updated') + response['data']['itemId'] = item.itemId return render_to_json_response(response) actions.register(moveFiles, cache=False) diff --git a/static/js/pandora/ui/Ox.FilesView.js b/static/js/pandora/ui/Ox.FilesView.js index bd1571b9c..d1738937f 100644 --- a/static/js/pandora/ui/Ox.FilesView.js +++ b/static/js/pandora/ui/Ox.FilesView.js @@ -287,16 +287,19 @@ Ox.FilesView = function(options, self) { .css({margin: '0 4px 4px 4px'}) .bindEvent({ click: function() { - var itemId = self.$idInput.value(); - Ox.Request.clearCache(); // fixme: remove - pandora.api.moveFiles({ + var data = { ids: self.selected, - itemId: itemId - }, function() { + itemId: self.$idInput.value() + }; + ['title', 'director', 'year'].forEach(function(key) { + data[key] = self['$' + key + 'Input'].value(); + }); + Ox.Request.clearCache(); // fixme: remove + pandora.api.moveFiles(data, function(result) { if(self.$checkbox.value()) { - pandora.URL.set(itemId); + pandora.URL.set(result.data.itemId); } else { - Ox.print('moved', self.selected, itemId); + Ox.print('moved', self.selected, result.data.itemId); self.$filesList.reloadList(); self.$instancesList.reloadList(); }