make private annotations private

This commit is contained in:
j 2011-02-11 15:51:25 +05:30
parent 45e530763b
commit b13c43c832
4 changed files with 38 additions and 8 deletions

View file

@ -8,6 +8,21 @@ import ox
import utils
def load_layers(layers):
for l in layers:
create_or_update_layer(l)
def create_or_update_layer(data):
layer, created = Layer.objects.get_or_create(name=data['id'])
for key in ('title', 'type', 'overlap', 'overlay', 'private'):
if key in data and getattr(layer, key) != data[key]:
setattr(layer, key, data[key])
created = True
if created:
layer.save()
return layer
class Layer(models.Model):
class Meta:
@ -26,7 +41,7 @@ class Layer(models.Model):
overlap = models.BooleanField(default=True)
overlay = models.BooleanField(default=True)
public = models.BooleanField(default=True) #false=users only see there own bins
private = models.BooleanField(default=False) #false=users only see there own bins
#find/sort integration
find = models.BooleanField(default=True) #true part of find all
@ -42,7 +57,13 @@ class Layer(models.Model):
return p
def json(self):
return {'id': self.name, 'title': self.title, 'type': self.type}
return {
'id': self.name,
'overlap': self.overlap,
'private': self.private,
'title': self.title,
'type': self.type
}
def __unicode__(self):
return self.title

View file

@ -6,11 +6,13 @@ from ox.utils import json
from ox.django.decorators import login_required_json
from ox.django.shortcuts import render_to_json_response, get_object_or_404_json, json_response
import models
from item.models import Item
from app.models import site_config
from item.models import Item
from api.actions import actions
import models
def findAnnotations(request):
'''
@ -56,6 +58,9 @@ def addAnnotation(request):
return render_to_json_response(json_response(status=400,
text='invalid data'))
#FIXME: this should be only called starting up server
models.load_layers(site_config()['layers'])
item = get_object_or_404_json(Item, itemId=data['item'])
layer = get_object_or_404_json(models.Layer, name=data['layer'])

View file

@ -336,7 +336,7 @@ class Item(models.Model):
stream['formats'] = list(set(map(lambda s: os.path.splitext(s['profile'])[1][1:], self.streams.all().values('profile'))))
return stream
def get_layers(self):
def get_layers(self, user=None):
layers = {}
layers['subtitles'] = []
#FIXME: should subtitles be stored in Annotation?
@ -345,7 +345,12 @@ class Item(models.Model):
layers['subtitles'] = qs[0].srt()
for l in Layer.objects.all():
ll = layers.setdefault(l.name, [])
for a in Annotation.objects.filter(layer=l, item=self).order_by('start'):
qs = Annotation.objects.filter(layer=l, item=self)
if l.private:
if user.is_anonymous():
user = None
qs = qs.filter(user=user)
for a in qs.order_by('start'):
ll.append(a.json())
return layers
@ -863,7 +868,6 @@ for key in filter(lambda k: 'columnWidth' in k, config['itemKeys']):
ItemSort = type('ItemSort', (models.Model,), attrs)
ItemSort.fields = [f.name for f in ItemSort._meta.fields]
class Access(models.Model):
class Meta:
unique_together = ("item", "user")

View file

@ -314,7 +314,7 @@ def getItem(request):
if item.access(request.user):
info = item.get_json()
info['stream'] = item.get_stream()
info['layers'] = item.get_layers()
info['layers'] = item.get_layers(request.user)
response['data']['item'] = info
else:
response = json_response(status=403, text='permission denied')