tweak clip table

This commit is contained in:
j 2012-03-22 22:33:42 +01:00
parent 60c1ecf399
commit 950b6533b0
6 changed files with 24 additions and 12 deletions

View file

@ -204,10 +204,13 @@ class ClipManager(Manager):
#anonymous can only see public clips #anonymous can only see public clips
if not user or user.is_anonymous(): if not user or user.is_anonymous():
allowed_level = settings.CONFIG['capabilities']['canSeeItem']['guest'] 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 #users can see public clips, there own clips and clips of there groups
else: else:
allowed_level = settings.CONFIG['capabilities']['canSeeItem'][user.get_profile().get_level()] 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 #admins can see all available clips
return qs return qs

View file

@ -24,8 +24,6 @@ class MetaClip:
else: else:
self.hue = self.saturation = self.lightness = 0 self.hue = self.saturation = self.lightness = 0
self.volume = 0 self.volume = 0
self.director = self.item.sort.director
self.title = self.item.sort.title
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
self.public_id = u"%s/%s-%s" %(self.item.itemId, float(self.start), float(self.end)) 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() streams = self.item.streams()
if streams: if streams:
self.aspect_ratio = streams[0].aspect_ratio 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: if self.id:
sortvalue = '' sortvalue = ''
if self.id: if self.id:
@ -115,6 +116,8 @@ attrs = {
'aspect_ratio': models.FloatField(default=0), 'aspect_ratio': models.FloatField(default=0),
'item': models.ForeignKey('item.Item', related_name='clips'), '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 #seconds
'start': models.FloatField(default=-1, db_index=True), 'start': models.FloatField(default=-1, db_index=True),
@ -128,8 +131,6 @@ attrs = {
'lightness': models.FloatField(default=0, db_index=True), 'lightness': models.FloatField(default=0, db_index=True),
'volume': models.FloatField(default=0, null=True, 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), 'sortvalue': models.CharField(max_length=1000, null=True, db_index=True),
'findvalue': models.TextField(null=True), 'findvalue': models.TextField(null=True),
} }

View file

@ -41,7 +41,6 @@ def order_query(qs, sort):
operator = '' operator = ''
clip_keys = ('public_id', 'start', 'end', 'hue', 'saturation', 'lightness', 'volume', clip_keys = ('public_id', 'start', 'end', 'hue', 'saturation', 'lightness', 'volume',
'duration', 'sortvalue', 'videoRatio', 'duration', 'sortvalue', 'videoRatio',
'director', 'title',
'random__random') 'random__random')
key = { key = {
'id': 'public_id', 'id': 'public_id',
@ -60,7 +59,7 @@ def order_query(qs, sort):
}.get(key, key) }.get(key, key)
elif key not in clip_keys: elif key not in clip_keys:
#key mgith need to be changed, see order_sort in item/views.py #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 = '%s%s' % (operator, key)
order_by.append(order) order_by.append(order)
if order_by: if order_by:
@ -94,7 +93,7 @@ def findClips(request):
keys = filter(lambda k: k not in settings.CONFIG['clipLayers'] + ['annotations'], keys = filter(lambda k: k not in settings.CONFIG['clipLayers'] + ['annotations'],
data['keys']) data['keys'])
if filter(lambda k: k not in models.Clip.clip_keys, 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): def add(p):
ids.append(p.id) ids.append(p.id)

View file

@ -805,8 +805,6 @@ class Item(models.Model):
s.timesaccessed = 0 s.timesaccessed = 0
s.accessed = self.accessed.aggregate(Max('access'))['access__max'] s.accessed = self.accessed.aggregate(Max('access'))['access__max']
s.save() s.save()
#update cached values in clips
self.clips.all().update(director=s.director, title=s.title)
def update_layer_facet(self, key): def update_layer_facet(self, key):
current_values = [a['value'] current_values = [a['value']

View file

@ -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_clip_id_idx" ON "clip_random" ("clip_id")')
cursor.execute('CREATE INDEX "clip_random_random_idx" ON "clip_random" ("random")') 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') @task(ignore_results=True, queue='default')
def update_poster(itemId): def update_poster(itemId):
item = models.Item.objects.get(itemId=itemId) item = models.Item.objects.get(itemId=itemId)

View file

@ -426,6 +426,7 @@ def edit(request):
data: {} data: {}
} }
''' '''
update_clips = False
data = json.loads(request.POST['data']) data = json.loads(request.POST['data'])
item = get_object_or_404_json(models.Item, itemId=data['id']) item = get_object_or_404_json(models.Item, itemId=data['id'])
if item.editable(request.user): if item.editable(request.user):
@ -441,11 +442,16 @@ def edit(request):
if 'user' in data: if 'user' in data:
if request.user.get_profile().get_level() in ('admin', 'staff') and \ if request.user.get_profile().get_level() in ('admin', 'staff') and \
models.User.objects.filter(username=data['user']).exists(): 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'] del data['user']
r = item.edit(data) r = item.edit(data)
if r: if r:
r.wait() r.wait()
if update_clips:
tasks.update_clips.delay(item.itemId)
response['data'] = item.get_json() response['data'] = item.get_json()
else: else:
response = json_response(status=403, text='permissino denied') response = json_response(status=403, text='permissino denied')