From 80f90420db11477cd527eeb2c4f626915ffe6cb1 Mon Sep 17 00:00:00 2001 From: rolux Date: Mon, 19 Dec 2011 17:20:06 +0000 Subject: [PATCH] fix select all --- pandora/itemlist/models.py | 7 +++++-- pandora/itemlist/views.py | 9 +++++---- static/js/pandora/list.js | 24 ++++++++++++++++++++---- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/pandora/itemlist/models.py b/pandora/itemlist/models.py index 1a5986d82..4764a45c8 100644 --- a/pandora/itemlist/models.py +++ b/pandora/itemlist/models.py @@ -75,8 +75,11 @@ class List(models.Model): l.item = item l.save() - def remove(self, item): - ListItem.objects.all().filter(item=item, list=self).delete() + def remove(self, item=None, items=None): + if item: + ListItem.objects.all().filter(item=item, list=self).delete() + if items: + ListItem.objects.all().filter(item__itemId__in=items, list=self).delete() def __unicode__(self): return self.get_id() diff --git a/pandora/itemlist/views.py b/pandora/itemlist/views.py index 8ebad27fe..4b065a910 100644 --- a/pandora/itemlist/views.py +++ b/pandora/itemlist/views.py @@ -4,6 +4,7 @@ from __future__ import division import os from django.db.models import Max, Sum +from django.db import transaction from django.http import HttpResponseForbidden, Http404 from django.conf import settings from ox.utils import json @@ -139,8 +140,9 @@ def addListItems(request): list = get_list_or_404_json(data['list']) if 'items' in data: if list.editable(request.user): - for item in Item.objects.filter(itemId__in=data['items']): - list.add(item) + with transaction.commit_on_success(): + for item in Item.objects.filter(itemId__in=data['items']): + list.add(item) response = json_response(status=200, text='items added') else: response = json_response(status=403, text='not allowed') @@ -170,8 +172,7 @@ def removeListItems(request): list = get_list_or_404_json(data['list']) if 'items' in data: if list.editable(request.user): - for item in list.items.filter(itemId__in=data['items']): - list.remove(item) + list.remove(items=data['items']) response = json_response(status=200, text='items removed') else: response = json_response(status=403, text='not allowed') diff --git a/static/js/pandora/list.js b/static/js/pandora/list.js index 1e3d3eac3..663732823 100644 --- a/static/js/pandora/list.js +++ b/static/js/pandora/list.js @@ -497,7 +497,7 @@ pandora.ui.list = function() { }, pandora.reloadList); }, select: function(data) { - var $still, $timeline; + var query; pandora.UI.set('listSelection', data.ids); if (data.ids.length) { pandora.$ui.mainMenu.enableItem('copy'); @@ -507,8 +507,8 @@ pandora.ui.list = function() { pandora.$ui.mainMenu.disableItem('openmovie'); } pandora.$ui.leftPanel.replaceElement(2, pandora.$ui.info = pandora.ui.info()); - pandora.api.find({ - query: { + if (Ox.isUndefined(data.rest)) { + query = { conditions: data.ids.map(function(id) { return { key: 'id', @@ -517,7 +517,23 @@ pandora.ui.list = function() { } }), operator: '|' - } + }; + } else { + query = { + conditions: Ox.merge([ + pandora.user.ui.find + ], data.rest.map(function(id) { + return { + key: 'id', + value: id, + operator: '!=' + }; + })), + operator: '&' + }; + } + pandora.api.find({ + query: query }, function(result) { pandora.$ui.selected.html(pandora.ui.status('selected', result.data)); });