From 6835937431255e776712e174346eee09dd7aa153 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 19 Oct 2011 23:20:47 +0200 Subject: [PATCH] clips,default annotations without user --- pandora/item/models.py | 7 +++++-- pandora/item/views.py | 8 +++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index a5c05d12..1fd6e37a 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -1007,8 +1007,11 @@ class Item(models.Model): .filter(selected=True).order_by('part'): subtitles_added = False prefix = os.path.splitext(f.path)[0] - user = f.instances.all()[0].volume.user - + if f.instances.all().count() > 0: + user = f.instances.all()[0].volume.user + else: + #FIXME: allow annotations from no user instead? + user = User.objects.all().order_by('id')[0] #if there is a subtitle with the same prefix, import q = subtitles.filter(path__startswith=prefix, language=language) diff --git a/pandora/item/views.py b/pandora/item/views.py index 3c5b925d..671fbe5d 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -224,11 +224,13 @@ Positions def get_clips(qs): n = qs.count() if n > query['clip_items']: + num = query['clip_items'] clips = [] - step = int(n/query['clip_items']) - offset = int((n - step * query['clip_items']) / 2) - for i in range(offset, n, step): + step = int(n / (num + 1)) + i = step + while i <= (n - step) and i < n and len(clips) < num: clips.append(qs[i]) + i += step else: clips = qs return [c.json(query['clip_keys']) for c in clips]