api.api add cache info, add list type

This commit is contained in:
j 2011-01-13 08:33:14 +00:00
parent b99931b3ab
commit 839c9761fd
11 changed files with 68 additions and 51 deletions

View file

@ -70,7 +70,7 @@ def addAnnotation(request):
response = {'status': {'code': 501, 'text': 'not implemented'}}
return render_to_json_response(response)
actions.register(addAnnotation)
actions.register(addAnnotation, cache=False)
@login_required_json
@ -86,7 +86,7 @@ def removeAnnotation(request):
'''
response = {'status': {'code': 501, 'text': 'not implemented'}}
return render_to_json_response(response)
actions.register(removeAnnotation)
actions.register(removeAnnotation, cache=False)
@login_required_json
@ -114,4 +114,4 @@ def editAnnotation(request):
response = json_response(status=501, text='not implemented')
return render_to_json_response(response)
actions.register(editAnnotation)
actions.register(editAnnotation, cache=False)

View file

@ -48,7 +48,7 @@ def trim(docstring):
class ApiActions(dict):
properties = {}
def __init__(self):
def api(request):
@ -57,11 +57,14 @@ class ApiActions(dict):
return {'status': {'code': int, 'text': string},
'data': {actions: ['api', 'hello', ...]}}
'''
actions = self.keys()
actions.sort()
_actions = self.keys()
_actions.sort()
actions = {}
for a in _actions:
actions[a] = self.properties[a]
response = json_response({'actions': actions})
return render_to_json_response(response)
self['api'] = api
self.register(api)
def apidoc(request):
'''
@ -74,15 +77,16 @@ class ApiActions(dict):
docs[f] = self.doc(f)
return render_to_json_response(json_response({'actions': docs}))
self['apidoc'] = apidoc
self.register(apidoc)
def doc(self, f):
return trim(self[f].__doc__)
def register(self, method, action=None):
def register(self, method, action=None, cache=True):
if not action:
action = method.func_name
self[action] = method
self.properties[action] = {'cache': cache}
def unregister(self, action):
if action in self:

View file

@ -34,7 +34,7 @@ def removeVolume(request):
except models.Volume.DoesNotExist:
response = json_response(status=404, text='volume not found')
return render_to_json_response(response)
actions.register(removeVolume)
actions.register(removeVolume, cache=False)
@login_required_json
@ -99,7 +99,7 @@ def update(request):
response['data']['file'] = [f.file.oshash for f in files.filter(file__is_subtitle=True)]
return render_to_json_response(response)
actions.register(update)
actions.register(update, cache=False)
@login_required_json
@ -147,7 +147,7 @@ def upload(request):
else:
response = json_response(status=403, text='permissino denied')
return render_to_json_response(response)
actions.register(upload)
actions.register(upload, cache=False)
class VideoChunkForm(forms.Form):
@ -216,7 +216,7 @@ def taskStatus(request):
task_id = data['task_id']
response = task_status(request, task_id)
return render_to_json_response(response)
actions.register(taskStatus)
actions.register(taskStatus, cache=False)
@login_required_json
@ -251,7 +251,7 @@ def editFile(request):
#FIXME: other things might need updating here
response = json_response(text='updated')
return render_to_json_response(response)
actions.register(editFile)
actions.register(editFile, cache=False)
def lookup_file(request, oshash):

View file

@ -20,7 +20,7 @@ def addDate(request):
else:
response = json_response(status=403, text='place name exists')
return render_to_json_response(response)
actions.register(addDate)
actions.register(addDate, cache=False)
@login_required_json
@ -51,14 +51,14 @@ def editDate(request):
else:
response = json_response(status=403, text='permission denied')
return render_to_json_response(response)
actions.register(editDate)
actions.register(editDate, cache=False)
@login_required_json
def removeDate(request):
response = json_response(status=501, text='not implemented')
return render_to_json_response(response)
actions.register(removeDate)
actions.register(removeDate, cache=False)
def findDate(request):

View file

@ -207,7 +207,7 @@ Positions
response['data']['items'] = [only_p(m['json']) for m in qs.values('json')]
else: # otherwise stats
items = query['qs']
files = File.objects.all().filter(item__in=items)
files = File.objects.all().filter(item__in=items).exclude(size__gt=0)
r = files.aggregate(
Sum('duration'),
Sum('pixels'),
@ -217,7 +217,7 @@ Positions
response['data']['files'] = files.count()
response['data']['items'] = items.count()
response['data']['pixels'] = r['pixels__sum']
response['data']['runtime'] = items.filter(sort__runtime__gt=0).aggregate(Sum('sort__runtime'))['sort__runtime__sum']
response['data']['runtime'] = items.filter(sort__runtime_desc__gt=0).aggregate(Sum('sort__runtime_desc'))['sort__runtime_desc__sum']
if response['data']['runtime'] == None:
response['data']['runtime'] = 1337
response['data']['size'] = r['size__sum']
@ -309,7 +309,7 @@ def editItem(request):
else:
response = json_response(status=403, text='permissino denied')
return render_to_json_response(response)
actions.register(editItem)
actions.register(editItem, cache=False)
@login_required_json
def removeItem(request):
@ -327,7 +327,7 @@ def removeItem(request):
else:
response = json_response(status=403, text='permission denied')
return render_to_json_response(response)
actions.register(removeItem)
actions.register(removeItem, cache=False)
'''
Poster API
@ -372,7 +372,7 @@ def setPosterFrame(request): #parse path and return info
else:
response = json_response(status=403, text='permissino denied')
return render_to_json_response(response)
actions.register(setPosterFrame)
actions.register(setPosterFrame, cache=False)
def setPoster(request): #parse path and return info
'''
@ -404,7 +404,7 @@ def setPoster(request): #parse path and return info
else:
response = json_response(status=403, text='permission denied')
return render_to_json_response(response)
actions.register(setPoster)
actions.register(setPoster, cache=False)
def getImdbId(request):
'''

View file

@ -23,6 +23,7 @@ class List(models.Model):
status = models.CharField(max_length=20, default='private')
_status = ['private', 'public', 'featured']
query = DictField(default={"static": True})
type= models.CharField(max_length=255, default='static')
items = models.ManyToManyField('item.Item', related_name='lists',
through='ListItem')
@ -32,6 +33,10 @@ class List(models.Model):
objects = managers.ListManager()
def save(self, *args, **kwargs):
if self.query.get('static', False):
self.type = 'static'
else:
self.type = 'smart'
super(List, self).save(*args, **kwargs)
def get_number_of_items(self, user=None):
@ -64,7 +69,7 @@ class List(models.Model):
return True
return False
def json(self, keys=['id', 'name', 'user', 'query', 'status'], user=None):
def json(self, keys=['id', 'name', 'user', 'type', 'query', 'status'], user=None):
response = {}
for key in keys:
if key == 'items':

View file

@ -122,7 +122,7 @@ def addListItem(request):
else:
response = json_response(status=501, text='not implemented')
return render_to_json_response(response)
actions.register(addListItem)
actions.register(addListItem, cache=False)
@login_required_json
@ -154,7 +154,7 @@ def removeListItem(request):
else:
response = json_response(status=501, text='not implemented')
return render_to_json_response(response)
actions.register(removeListItem)
actions.register(removeListItem, cache=False)
@login_required_json
@ -184,7 +184,7 @@ def addList(request):
response = json_response(status=200, text='list already exists')
response['data']['errors'] = {'name': 'List already exists'}
return render_to_json_response(response)
actions.register(addList)
actions.register(addList, cache=False)
@login_required_json
@ -208,10 +208,18 @@ def editList(request):
if list.editable(request.user):
response = json_response()
for key in data:
if key in ('name', 'status', 'query'):
if key in ('name', 'status', 'query', 'type'):
if key in data:
if key == 'query' and not data['query']:
setattr(list, key, {"static":True})
elif key == 'type':
if data[key] == 'static':
list.query = {"static":True}
list.type = 'static'
else:
list.type = 'dynamic'
if list.query.get('static', False):
list.query = {}
elif key == 'status':
value = data[key]
if value not in list._status:
@ -239,7 +247,7 @@ def editList(request):
else:
response = json_response(status=403, text='not allowed')
return render_to_json_response(response)
actions.register(editList)
actions.register(editList, cache=False)
@login_required_json
@ -265,7 +273,7 @@ def removeList(request):
else:
response = json_response(status=403, text='not allowed')
return render_to_json_response(response)
actions.register(removeList)
actions.register(removeList, cache=False)
@login_required_json
@ -291,7 +299,7 @@ def subscribeToList(request):
pos.save()
response = json_response()
return render_to_json_response(response)
actions.register(subscribeToList)
actions.register(subscribeToList, cache=False)
@login_required_json
def unsubscribeFromList(request):
@ -313,7 +321,7 @@ def unsubscribeFromList(request):
models.Position.objects.filter(list=list, user=request.user, section='public').delete()
response = json_response()
return render_to_json_response(response)
actions.register(unsubscribeFromList)
actions.register(unsubscribeFromList, cache=False)
@login_required_json
@ -359,5 +367,5 @@ def sortLists(request):
response = json_response()
return render_to_json_response(response)
actions.register(sortLists)
actions.register(sortLists, cache=False)

View file

@ -36,7 +36,7 @@ def addPlace(request):
else:
response = json_response(status=403, text='place name exists')
return render_to_json_response(response)
actions.register(addPlace)
actions.register(addPlace, cache=False)
@login_required_json
@ -67,14 +67,14 @@ def editPlace(request):
else:
response = json_response(status=403, text='permission denied')
return render_to_json_response(response)
actions.register(editPlace)
actions.register(editPlace, cache=False)
@login_required_json
def removePlace(request):
response = json_response(status=501, text='not implemented')
return render_to_json_response(response)
actions.register(removePlace)
actions.register(removePlace, cache=False)
def findPlace(request):

View file

@ -39,7 +39,7 @@ def editNews(request):
item = get_object_or_404_json(models.Text, pk=itemId)
response['data']['page'] = item.html()
return render_to_json_response(response)
actions.register(editNews)
actions.register(editNews, cache=False)
def findNews(request):
@ -78,7 +78,7 @@ def editText(request):
item = get_object_or_404_json(models.Text, pk=itemId)
response['data']['page'] = item.html()
return render_to_json_response(response)
actions.register(editText)
actions.register(editText, cache=False)
def findText(request):

View file

@ -37,7 +37,7 @@ def addClip(request):
else:
response = json_response(status=501, text='not implemented')
return render_to_json_response(response)
actions.register(addClip)
actions.register(addClip, cache=False)
@login_required_json
@ -65,7 +65,7 @@ def removeClip(request):
else:
response = json_response(status=501, text='not implemented')
return render_to_json_response(response)
actions.register(removeClip)
actions.register(removeClip, cache=False)
def getTimeline(request):
@ -123,7 +123,7 @@ def addTimeline(request):
'name': 'List already exists'
}
return render_to_json_response(response)
actions.register(addTimeline)
actions.register(addTimeline, cache=False)
@login_required_json
@ -145,7 +145,7 @@ def editTimeline(request):
else:
response = json_response(status=403, text='not allowed')
return render_to_json_response(response)
actions.register(editTimeline)
actions.register(editTimeline, cache=False)
@login_required_json
@ -163,4 +163,4 @@ def removeTimeline(request):
else:
response = json_response(status=403, text='not allowed')
return render_to_json_response(response)
actions.register(removeTimeline)
actions.register(removeTimeline, cache=False)

View file

@ -79,7 +79,7 @@ def signin(request):
else:
response = json_response(status=400, text='invalid data')
return render_to_json_response(response)
actions.register(signin)
actions.register(signin, cache=False)
def signout(request):
@ -103,7 +103,7 @@ def signout(request):
response['data']['user'] = site_config['user']
return render_to_json_response(response)
actions.register(signout)
actions.register(signout, cache=False)
class SignupForm(forms.Form):
@ -180,7 +180,7 @@ def signup(request):
else:
response = json_response(status=400, text='invalid data')
return render_to_json_response(response)
actions.register(signup)
actions.register(signup, cache=False)
def resetPassword(request):
@ -235,7 +235,7 @@ def resetPassword(request):
else:
response = json_response(status=400, text='invalid data')
return render_to_json_response(response)
actions.register(resetPassword)
actions.register(resetPassword, cache=False)
def requestToken(request):
@ -301,7 +301,7 @@ def requestToken(request):
else:
response = json_response(status=400, text='invalid data')
return render_to_json_response(response)
actions.register(requestToken)
actions.register(requestToken, cache=False)
def findUser(request):
@ -366,7 +366,7 @@ def contact(request):
else:
response = json_response(status=400, text='invalid data')
return render_to_json_response(response)
actions.register(contact)
actions.register(contact, cache=False)
def getPositionById(list, key):
@ -399,7 +399,7 @@ def setPreferences(request):
profile.save()
response = json_response()
return render_to_json_response(response)
actions.register(setPreferences)
actions.register(setPreferences, cache=False)
@login_required_json
@ -430,5 +430,5 @@ def setUI(request):
profile.save()
response = json_response()
return render_to_json_response(response)
actions.register(setUI)
actions.register(setUI, cache=False)