From 950b6533b07c21f3a9852c35e19650491de1cd4e Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 22 Mar 2012 22:33:42 +0100 Subject: [PATCH] tweak clip table --- pandora/clip/managers.py | 7 +++++-- pandora/clip/models.py | 9 +++++---- pandora/clip/views.py | 5 ++--- pandora/item/models.py | 2 -- pandora/item/tasks.py | 5 +++++ pandora/item/views.py | 8 +++++++- 6 files changed, 24 insertions(+), 12 deletions(-) diff --git a/pandora/clip/managers.py b/pandora/clip/managers.py index 5d5bb87c..a4e95e21 100644 --- a/pandora/clip/managers.py +++ b/pandora/clip/managers.py @@ -204,10 +204,13 @@ class ClipManager(Manager): #anonymous can only see public clips if not user or user.is_anonymous(): allowed_level = settings.CONFIG['capabilities']['canSeeItem']['guest'] - qs = qs.filter(item__level__lte=allowed_level) + qs = qs.filter(sort__rightslevel__lte=allowed_level) #users can see public clips, there own clips and clips of there groups else: allowed_level = settings.CONFIG['capabilities']['canSeeItem'][user.get_profile().get_level()] - qs = qs.filter(Q(item__level__lte=allowed_level)|Q(item__user=user)|Q(item__groups__in=user.groups.all())) + q = Q(sort__rightslevel__lte=allowed_level)|Q(user=user.id) + if user.groups.count(): + q |= Q(item__groups__in=user.groups.all()) + qs = qs.filter(q) #admins can see all available clips return qs diff --git a/pandora/clip/models.py b/pandora/clip/models.py index 46754dd7..a51f148a 100644 --- a/pandora/clip/models.py +++ b/pandora/clip/models.py @@ -24,8 +24,6 @@ class MetaClip: else: self.hue = self.saturation = self.lightness = 0 self.volume = 0 - self.director = self.item.sort.director - self.title = self.item.sort.title def save(self, *args, **kwargs): self.public_id = u"%s/%s-%s" %(self.item.itemId, float(self.start), float(self.end)) @@ -35,6 +33,9 @@ class MetaClip: streams = self.item.streams() if streams: self.aspect_ratio = streams[0].aspect_ratio + if self.item: + self.user = self.item.user and self.item.user.id + self.sort = self.item.sort if self.id: sortvalue = '' if self.id: @@ -115,6 +116,8 @@ attrs = { 'aspect_ratio': models.FloatField(default=0), 'item': models.ForeignKey('item.Item', related_name='clips'), + 'sort': models.ForeignKey('item.ItemSort', related_name='clips'), + 'user': models.IntegerField(db_index=True, null=True), #seconds 'start': models.FloatField(default=-1, db_index=True), @@ -128,8 +131,6 @@ attrs = { 'lightness': models.FloatField(default=0, db_index=True), 'volume': models.FloatField(default=0, null=True, db_index=True), - 'director': models.CharField(max_length=1000, null=True, db_index=True), - 'title': models.CharField(max_length=1000, db_index=True), 'sortvalue': models.CharField(max_length=1000, null=True, db_index=True), 'findvalue': models.TextField(null=True), } diff --git a/pandora/clip/views.py b/pandora/clip/views.py index 595b2684..0024c7cd 100644 --- a/pandora/clip/views.py +++ b/pandora/clip/views.py @@ -41,7 +41,6 @@ def order_query(qs, sort): operator = '' clip_keys = ('public_id', 'start', 'end', 'hue', 'saturation', 'lightness', 'volume', 'duration', 'sortvalue', 'videoRatio', - 'director', 'title', 'random__random') key = { 'id': 'public_id', @@ -60,7 +59,7 @@ def order_query(qs, sort): }.get(key, key) elif key not in clip_keys: #key mgith need to be changed, see order_sort in item/views.py - key = "item__sort__%s" % key + key = "sort__%s" % key order = '%s%s' % (operator, key) order_by.append(order) if order_by: @@ -94,7 +93,7 @@ def findClips(request): keys = filter(lambda k: k not in settings.CONFIG['clipLayers'] + ['annotations'], data['keys']) if filter(lambda k: k not in models.Clip.clip_keys, keys): - qs = qs.select_related('item__sort') + qs = qs.select_related('sort') def add(p): ids.append(p.id) diff --git a/pandora/item/models.py b/pandora/item/models.py index 71ae94c6..c71a495c 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -805,8 +805,6 @@ class Item(models.Model): s.timesaccessed = 0 s.accessed = self.accessed.aggregate(Max('access'))['access__max'] s.save() - #update cached values in clips - self.clips.all().update(director=s.director, title=s.title) def update_layer_facet(self, key): current_values = [a['value'] diff --git a/pandora/item/tasks.py b/pandora/item/tasks.py index 4ada5950..3705941f 100644 --- a/pandora/item/tasks.py +++ b/pandora/item/tasks.py @@ -39,6 +39,11 @@ def update_random_clip_sort(): cursor.execute('CREATE INDEX "clip_random_clip_id_idx" ON "clip_random" ("clip_id")') cursor.execute('CREATE INDEX "clip_random_random_idx" ON "clip_random" ("random")') +@task(ignore_results=True, queue='default') +def update_clips(itemId): + item = models.Item.objects.get(itemId=itemId) + item.clips.all().update(user=item.user.id) + @task(ignore_results=True, queue='default') def update_poster(itemId): item = models.Item.objects.get(itemId=itemId) diff --git a/pandora/item/views.py b/pandora/item/views.py index 68722088..4bb82448 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -426,6 +426,7 @@ def edit(request): data: {} } ''' + update_clips = False data = json.loads(request.POST['data']) item = get_object_or_404_json(models.Item, itemId=data['id']) if item.editable(request.user): @@ -441,11 +442,16 @@ def edit(request): if 'user' in data: if request.user.get_profile().get_level() in ('admin', 'staff') and \ models.User.objects.filter(username=data['user']).exists(): - item.user = models.User.objects.get(username=data['user']) + new_user = models.User.objects.get(username=data['user']) + if new_user != item.user: + item.user = new_user + update_clips = True del data['user'] r = item.edit(data) if r: r.wait() + if update_clips: + tasks.update_clips.delay(item.itemId) response['data'] = item.get_json() else: response = json_response(status=403, text='permissino denied')