forked from 0x2620/pandora
tweak clip table
This commit is contained in:
parent
60c1ecf399
commit
950b6533b0
6 changed files with 24 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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']
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue