move files

This commit is contained in:
j 2011-07-03 20:30:47 +02:00
parent 523835dd6a
commit 87f64b1d0b
2 changed files with 28 additions and 17 deletions

View file

@ -185,7 +185,7 @@ def firefogg_upload(request):
f.save() f.save()
#FIXME: this fails badly if rabbitmq goes down #FIXME: this fails badly if rabbitmq goes down
try: try:
t = item.tasks.update_streams.delay((f.item.itemId)) t = item.tasks.update_streams.delay(f.item.itemId)
response['resultUrl'] = t.task_id response['resultUrl'] = t.task_id
except: except:
pass pass
@ -237,20 +237,28 @@ def moveFiles(request):
} }
} }
''' '''
#FIXME: permissions, need to be checked
data = json.loads(request.POST['data']) data = json.loads(request.POST['data'])
for f in models.File.objects.filter(oshash__in=data['ids']): if models.Item.objects.filter(itemId=data['itemId']).count() == 1:
if f.item.id != data['itemId']: item = models.Item.objects.get(itemId=data['itemId'])
else:
if len(data['itemId']) != 7: if len(data['itemId']) != 7:
folder = f.instances.all()[0].folder del data['itemId']
item_info = utils.parse_path(folder) item = get_item(data)
item = get_item(item_info)
else: else:
item = get_item({'imdbId': data['itemId']}) item = get_item({'imdbId': data['itemId']})
changed = []
for f in models.File.objects.filter(oshash__in=data['ids']):
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.item = item
f.save() 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 = json_response(text='updated')
response['data']['itemId'] = item.itemId
return render_to_json_response(response) return render_to_json_response(response)
actions.register(moveFiles, cache=False) actions.register(moveFiles, cache=False)

View file

@ -287,16 +287,19 @@ Ox.FilesView = function(options, self) {
.css({margin: '0 4px 4px 4px'}) .css({margin: '0 4px 4px 4px'})
.bindEvent({ .bindEvent({
click: function() { click: function() {
var itemId = self.$idInput.value(); var data = {
Ox.Request.clearCache(); // fixme: remove
pandora.api.moveFiles({
ids: self.selected, ids: self.selected,
itemId: itemId itemId: self.$idInput.value()
}, function() { };
['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()) { if(self.$checkbox.value()) {
pandora.URL.set(itemId); pandora.URL.set(result.data.itemId);
} else { } else {
Ox.print('moved', self.selected, itemId); Ox.print('moved', self.selected, result.data.itemId);
self.$filesList.reloadList(); self.$filesList.reloadList();
self.$instancesList.reloadList(); self.$instancesList.reloadList();
} }