From e61ea929ee45c2666ccb6cc4d803a3d3f845c977 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 13 Jan 2011 08:33:14 +0000 Subject: [PATCH] api.api add cache info, add list type --- pandora/annotaion/views.py | 6 +++--- pandora/api/actions.py | 16 ++++++++++------ pandora/archive/views.py | 10 +++++----- pandora/date/views.py | 6 +++--- pandora/item/views.py | 12 ++++++------ pandora/itemlist/models.py | 7 ++++++- pandora/itemlist/views.py | 26 +++++++++++++++++--------- pandora/place/views.py | 6 +++--- pandora/text/views.py | 4 ++-- pandora/timeline/views.py | 10 +++++----- pandora/user/views.py | 16 ++++++++-------- 11 files changed, 68 insertions(+), 51 deletions(-) diff --git a/pandora/annotaion/views.py b/pandora/annotaion/views.py index 1f2c477..c9446b6 100644 --- a/pandora/annotaion/views.py +++ b/pandora/annotaion/views.py @@ -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) diff --git a/pandora/api/actions.py b/pandora/api/actions.py index 4fca44c..787a9f4 100644 --- a/pandora/api/actions.py +++ b/pandora/api/actions.py @@ -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: diff --git a/pandora/archive/views.py b/pandora/archive/views.py index 3f2cf5e..b4784ac 100644 --- a/pandora/archive/views.py +++ b/pandora/archive/views.py @@ -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): diff --git a/pandora/date/views.py b/pandora/date/views.py index 7c68ac1..b95bc19 100644 --- a/pandora/date/views.py +++ b/pandora/date/views.py @@ -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): diff --git a/pandora/item/views.py b/pandora/item/views.py index 29521fb..a66e410 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -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): ''' diff --git a/pandora/itemlist/models.py b/pandora/itemlist/models.py index 63452af..083f899 100644 --- a/pandora/itemlist/models.py +++ b/pandora/itemlist/models.py @@ -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': diff --git a/pandora/itemlist/views.py b/pandora/itemlist/views.py index ed7c347..f0fd7bf 100644 --- a/pandora/itemlist/views.py +++ b/pandora/itemlist/views.py @@ -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) diff --git a/pandora/place/views.py b/pandora/place/views.py index 32a25d4..880b670 100644 --- a/pandora/place/views.py +++ b/pandora/place/views.py @@ -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): diff --git a/pandora/text/views.py b/pandora/text/views.py index ff894f9..71e157a 100644 --- a/pandora/text/views.py +++ b/pandora/text/views.py @@ -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): diff --git a/pandora/timeline/views.py b/pandora/timeline/views.py index 9664880..fe05a9f 100644 --- a/pandora/timeline/views.py +++ b/pandora/timeline/views.py @@ -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) diff --git a/pandora/user/views.py b/pandora/user/views.py index 9e38ada..7a98d70 100644 --- a/pandora/user/views.py +++ b/pandora/user/views.py @@ -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)