From ceb507020b69d58a639fb7b57d0440a3006046be Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 6 Oct 2014 08:26:43 +0000 Subject: [PATCH] data is passed to api functions now --- pandora/annotation/views.py | 15 +++------ pandora/app/views.py | 14 +++----- pandora/archive/views.py | 37 ++++++++------------- pandora/clip/views.py | 3 +- pandora/document/views.py | 18 ++++------- pandora/edit/views.py | 39 ++++++++-------------- pandora/event/views.py | 15 +++------ pandora/item/views.py | 39 ++++++++-------------- pandora/itemlist/views.py | 33 +++++++------------ pandora/log/views.py | 9 ++---- pandora/news/views.py | 13 +++----- pandora/person/views.py | 9 ++---- pandora/place/views.py | 14 +++----- pandora/sequence/views.py | 6 ++-- pandora/text/views.py | 24 +++++--------- pandora/title/views.py | 6 ++-- pandora/tv/views.py | 3 +- pandora/user/persona.py | 3 +- pandora/user/views.py | 64 +++++++++++++++---------------------- 19 files changed, 126 insertions(+), 238 deletions(-) diff --git a/pandora/annotation/views.py b/pandora/annotation/views.py index 9748cd768..00d72ab6b 100644 --- a/pandora/annotation/views.py +++ b/pandora/annotation/views.py @@ -61,7 +61,7 @@ def order_query(qs, sort): qs = qs.order_by(*order_by, nulls_last=True) return qs -def findAnnotations(request): +def findAnnotations(request, data): ''' takes { query: { @@ -82,7 +82,6 @@ def findAnnotations(request): annotations = [{..}, {...}, ...] } ''' - data = json.loads(request.POST['data']) response = json_response() query = parse_query(data, request.user) @@ -111,7 +110,7 @@ actions.register(findAnnotations) @login_required_json -def addAnnotation(request): +def addAnnotation(request, data): ''' takes { item: public_id, @@ -125,7 +124,6 @@ def addAnnotation(request): ... } ''' - data = json.loads(request.POST['data']) for key in ('item', 'layer', 'in', 'out', 'value'): if key not in data: return render_to_json_response(json_response(status=400, @@ -152,7 +150,7 @@ def addAnnotation(request): actions.register(addAnnotation, cache=False) @login_required_json -def addAnnotations(request): +def addAnnotations(request, data): ''' takes { item: public_id, @@ -167,7 +165,6 @@ def addAnnotations(request): taskId: string } ''' - data = json.loads(request.POST['data']) for key in ('item', 'layer', 'annotations'): if key not in data: return render_to_json_response(json_response(status=400, @@ -189,7 +186,7 @@ def addAnnotations(request): actions.register(addAnnotations, cache=False) @login_required_json -def removeAnnotation(request): +def removeAnnotation(request, data): ''' takes { id: annotationId @@ -198,7 +195,6 @@ def removeAnnotation(request): } ''' response = json_response({}) - data = json.loads(request.POST['data']) a = get_object_or_404_json(models.Annotation, public_id=data['id']) if a.editable(request.user): a.log() @@ -210,7 +206,7 @@ actions.register(removeAnnotation, cache=False) @login_required_json -def editAnnotation(request): +def editAnnotation(request, data): ''' takes { id:, @@ -224,7 +220,6 @@ def editAnnotation(request): } ''' response = json_response({}) - data = json.loads(request.POST['data']) a = get_object_or_404_json(models.Annotation, public_id=data['id']) if a.editable(request.user): a.log() diff --git a/pandora/app/views.py b/pandora/app/views.py index 656a9156b..0b44f12f4 100644 --- a/pandora/app/views.py +++ b/pandora/app/views.py @@ -93,7 +93,7 @@ def robots_txt(request, url): 'text/plain' ) -def getPage(request): +def getPage(request, data): ''' takes { name: pagename @@ -103,7 +103,6 @@ def getPage(request): text: } ''' - data = json.loads(request.POST['data']) if isinstance(data, basestring): name = data else: @@ -118,7 +117,7 @@ actions.register(getPage) @login_required_json -def editPage(request): +def editPage(request, data): ''' takes { name: pagename @@ -130,7 +129,6 @@ def editPage(request): } ''' if request.user.get_profile().capability('canEditSitePages'): - data = json.loads(request.POST['data']) page, created = models.Page.objects.get_or_create(name=data['name']) if not created: page.log() @@ -143,7 +141,7 @@ def editPage(request): actions.register(editPage) -def init(request): +def init(request, data): ''' takes {} returns { @@ -162,7 +160,7 @@ def init(request): return render_to_json_response(response) actions.register(init) -def embedURL(request): +def embedURL(request, data): ''' takes { @@ -175,13 +173,12 @@ def embedURL(request): ... } ''' - data = json.loads(request.POST['data']) response = json_response({}) response['data'] = ox.get_embed_code(data['url'], data.get('maxwidth'), data.get('maxheight')) return render_to_json_response(response) actions.register(embedURL) -def getEmbedDefaults(request): +def getEmbedDefaults(request, data): ''' takes {} returns { @@ -202,7 +199,6 @@ def getEmbedDefaults(request): from itemlist.models import List from edit.models import Edit from text.models import Text - data = json.loads(request.POST['data']) response = json_response({}) qs = Document.objects.filter(uploading=False).order_by('id') if qs.exists(): diff --git a/pandora/archive/views.py b/pandora/archive/views.py index d267bd018..df3a2a3c5 100644 --- a/pandora/archive/views.py +++ b/pandora/archive/views.py @@ -27,8 +27,7 @@ from chunk import process_chunk @login_required_json -def removeVolume(request): - data = json.loads(request.POST['data']) +def removeVolume(request, data): user = request.user try: volume = models.Volume.objects.get(user=user, name=data['volume']) @@ -42,7 +41,7 @@ actions.register(removeVolume, cache=False) @login_required_json -def update(request): +def update(request, data): ''' 2 steps: send files @@ -67,7 +66,6 @@ def update(request): file: list // list of files that should be uploaded as is } ''' - data = json.loads(request.POST['data']) user = request.user upload_only = data.get('upload', False) @@ -109,7 +107,7 @@ actions.register(update, cache=False) @login_required_json -def upload(request): +def upload(request, data=None): ''' takes { id: string @@ -156,7 +154,7 @@ actions.register(upload, cache=False) @login_required_json -def addMedia(request): +def addMedia(request, data): ''' takes { id: oshash @@ -169,7 +167,6 @@ def addMedia(request): } ''' response = json_response({}) - data = json.loads(request.POST['data']) oshash = data.pop('id') if not request.user.get_profile().capability('canAddItems'): response = json_response(status=403, text='permission denied') @@ -324,9 +321,8 @@ def direct_upload(request): @login_required_json -def taskStatus(request): +def taskStatus(request, data): #FIXME: should check if user has permissions to get status - data = json.loads(request.POST['data']) if 'taskId' in data: task_id = data['taskId'] else: @@ -337,7 +333,7 @@ actions.register(taskStatus, cache=False) @login_required_json -def moveMedia(request): +def moveMedia(request, data): ''' change file / item link takes { @@ -348,7 +344,6 @@ def moveMedia(request): returns { } ''' - data = json.loads(request.POST['data']) if Item.objects.filter(public_id=data['item']).count() == 1: i = Item.objects.get(public_id=data['item']) else: @@ -384,7 +379,7 @@ def moveMedia(request): actions.register(moveMedia, cache=False) @login_required_json -def editMedia(request): +def editMedia(request, data): ''' change file / item link takes { @@ -398,8 +393,6 @@ def editMedia(request): returns { } ''' - data = json.loads(request.POST['data']) - ignore = [] save_items = [] dont_ignore = [] @@ -443,8 +436,7 @@ actions.register(editMedia, cache=False) @login_required_json -def removeMedia(request): - data = json.loads(request.POST['data']) +def removeMedia(request, data): response = json_response() if request.user.get_profile().get_level() == 'admin': qs = models.File.objects.filter(oshash__in=data['ids'], instances__id=None) @@ -461,7 +453,7 @@ def removeMedia(request): return render_to_json_response(response) actions.register(removeMedia, cache=False) -def getPath(request): +def getPath(request, data): ''' change file / item link takes { @@ -472,7 +464,6 @@ def getPath(request): id: path } ''' - data = json.loads(request.POST['data']) response = json_response() ids = data['id'] if isinstance(ids, basestring): @@ -517,7 +508,7 @@ def _order_query(qs, sort, prefix=''): return qs -def findMedia(request): +def findMedia(request, data): ''' takes { 'query': query, @@ -591,7 +582,6 @@ Positions } } ''' - data = json.loads(request.POST['data']) if not data.get('sort'): data['sort'] = [{'key': 'path', 'operator': '+'}] query = parse_query(data, request.user) @@ -655,7 +645,7 @@ Positions actions.register(findMedia) -def parsePath(request): #parse path and return info +def parsePath(request, data): #parse path and return info ''' takes { path: string @@ -664,12 +654,12 @@ def parsePath(request): #parse path and return info imdb: string } ''' - path = json.loads(request.POST['data'])['path'] + path = data['path'] response = json_response(ox.parse_movie_path(path)) return render_to_json_response(response) actions.register(parsePath) -def getMediaInfo(request): +def getMediaInfo(request, data): ''' takes { id: oshash of stream file @@ -679,7 +669,6 @@ def getMediaInfo(request): file: oshash of source file } ''' - data = json.loads(request.POST['data']) f = None qs = models.Stream.objects.filter(oshash=data['id']) if qs.count() > 0: diff --git a/pandora/clip/views.py b/pandora/clip/views.py index ee578699d..ccacb4f8b 100644 --- a/pandora/clip/views.py +++ b/pandora/clip/views.py @@ -71,7 +71,7 @@ def order_query(qs, sort): qs = qs.order_by(*order_by, nulls_last=True) return qs -def findClips(request): +def findClips(request, data): ''' takes { query: { @@ -93,7 +93,6 @@ def findClips(request): items: [object] } ''' - data = json.loads(request.POST['data']) response = json_response() query = parse_query(data, request.user) diff --git a/pandora/document/views.py b/pandora/document/views.py index 0d1b54ce9..1aa50b13c 100644 --- a/pandora/document/views.py +++ b/pandora/document/views.py @@ -26,7 +26,7 @@ def get_document_or_404_json(id): raise HttpErrorJson(response) @login_required_json -def addDocument(request): +def addDocument(request, data): ''' add document(s) to item takes { @@ -40,7 +40,6 @@ def addDocument(request): } ''' response = json_response() - data = json.loads(request.POST['data']) if 'ids' in data: ids = data['ids'] else: @@ -64,7 +63,7 @@ def addDocument(request): actions.register(addDocument, cache=False) @login_required_json -def editDocument(request): +def editDocument(request, data): ''' takes { id: string @@ -78,7 +77,6 @@ def editDocument(request): } ''' response = json_response() - data = json.loads(request.POST['data']) item = 'item' in data and Item.objects.get(public_id=data['item']) or None if data['id']: document = models.Document.get(data['id']) @@ -136,7 +134,7 @@ def parse_query(data, user): return query -def findDocuments(request): +def findDocuments(request, data): ''' takes { query: { @@ -165,7 +163,6 @@ def findDocuments(request): items: [object] } ''' - data = json.loads(request.POST['data']) query = parse_query(data, request.user) #order @@ -190,7 +187,7 @@ def findDocuments(request): return render_to_json_response(response) actions.register(findDocuments) -def getDocument(request): +def getDocument(request, data): ''' takes { id: string, @@ -201,7 +198,6 @@ def getDocument(request): } ''' response = json_response({}) - data = json.loads(request.POST['data']) data['keys'] = data.get('keys', []) document = get_document_or_404_json(data['id']) response['data'] = document.json(keys=data['keys'], user=request.user) @@ -209,7 +205,7 @@ def getDocument(request): actions.register(getDocument) @login_required_json -def removeDocument(request): +def removeDocument(request, data): ''' takes { id: string, @@ -223,7 +219,6 @@ def removeDocument(request): returns { } ''' - data = json.loads(request.POST['data']) response = json_response() if 'ids' in data: @@ -250,7 +245,7 @@ def removeDocument(request): actions.register(removeDocument, cache=False) @login_required_json -def sortDocuments(request): +def sortDocuments(request, data): ''' takes { item: string @@ -259,7 +254,6 @@ def sortDocuments(request): returns { } ''' - data = json.loads(request.POST['data']) index = 0 item = Item.objects.get(public_id=data['item']) ids = data['ids'] diff --git a/pandora/edit/views.py b/pandora/edit/views.py index 4eb33e2f7..00491c5c6 100644 --- a/pandora/edit/views.py +++ b/pandora/edit/views.py @@ -25,7 +25,7 @@ def get_edit_or_404_json(id): return get_object_or_404_json(models.Edit, user__username=username, name=name) @login_required_json -def addClips(request): +def addClips(request, data): ''' takes { edit: string, @@ -43,7 +43,6 @@ def addClips(request): } ''' response = json_response() - data = json.loads(request.POST['data']) edit = get_edit_or_404_json(data['edit']) clips = [] if edit.editable(request.user): @@ -65,7 +64,7 @@ actions.register(addClips, cache=False) @login_required_json -def removeClips(request): +def removeClips(request, data): ''' takes { edit: string @@ -75,7 +74,6 @@ def removeClips(request): } ''' response = json_response() - data = json.loads(request.POST['data']) edit = get_edit_or_404_json(data['edit']) if 'id' in data: ids = [data['id']] @@ -92,7 +90,7 @@ def removeClips(request): actions.register(removeClips, cache=False) @login_required_json -def editClip(request): +def editClip(request, data): ''' takes { id: string, @@ -103,7 +101,6 @@ def editClip(request): } ''' response = json_response() - data = json.loads(request.POST['data']) clip = get_object_or_404_json(models.Clip, pk=ox.fromAZ(data['id'])) valid = True if clip.edit.editable(request.user): @@ -129,7 +126,7 @@ def editClip(request): actions.register(editClip, cache=False) @login_required_json -def orderClips(request): +def orderClips(request, data): ''' takes { edit: string @@ -138,7 +135,6 @@ def orderClips(request): returns { } ''' - data = json.loads(request.POST['data']) edit = get_edit_or_404_json(data['edit']) response = json_response() ids = map(ox.fromAZ, data['ids']) @@ -187,7 +183,7 @@ def _order_clips(edit, sort): qs = qs.distinct() return qs -def sortClips(request): +def sortClips(request, data): ''' takes { edit: string @@ -196,7 +192,6 @@ def sortClips(request): returns { } ''' - data = json.loads(request.POST['data']) edit = get_edit_or_404_json(data['edit']) response = json_response() clips = _order_clips(edit, data['sort']) @@ -204,7 +199,7 @@ def sortClips(request): return render_to_json_response(response) actions.register(sortClips, cache=False) -def getEdit(request): +def getEdit(request, data): ''' takes { id: @@ -215,7 +210,6 @@ def getEdit(request): clips: } ''' - data = json.loads(request.POST['data']) if 'id' in data: response = json_response() edit = get_edit_or_404_json(data['id']) @@ -229,7 +223,7 @@ def getEdit(request): actions.register(getEdit) @login_required_json -def addEdit(request): +def addEdit(request, data): ''' takes { [name], @@ -240,7 +234,6 @@ def addEdit(request): ... } ''' - data = json.loads(request.POST['data']) data['name'] = re.sub(' \[\d+\]$', '', data.get('name', 'Untitled')).strip() name = data['name'] if not name: @@ -284,7 +277,7 @@ def addEdit(request): actions.register(addEdit, cache=False) @login_required_json -def editEdit(request): +def editEdit(request, data): ''' takes { id @@ -293,7 +286,6 @@ def editEdit(request): ... } ''' - data = json.loads(request.POST['data']) edit = get_edit_or_404_json(data['id']) response = json_response() if edit.editable(request.user): @@ -309,7 +301,7 @@ def editEdit(request): actions.register(editEdit, cache=False) @login_required_json -def removeEdit(request): +def removeEdit(request, data): ''' takes { ... @@ -318,7 +310,6 @@ def removeEdit(request): ... } ''' - data = json.loads(request.POST['data']) edit = get_edit_or_404_json(data['id']) response = json_response() if edit.editable(request.user): @@ -358,7 +349,7 @@ def parse_query(data, user): return query -def findEdits(request): +def findEdits(request, data): ''' takes { query: { @@ -387,7 +378,6 @@ def findEdits(request): items: [object] } ''' - data = json.loads(request.POST['data']) query = parse_query(data, request.user) #order @@ -423,14 +413,13 @@ def findEdits(request): actions.register(findEdits) @login_required_json -def subscribeToEdit(request): +def subscribeToEdit(request, data): ''' takes { id: string, } returns {} ''' - data = json.loads(request.POST['data']) edit = get_edit_or_404_json(data['id']) user = request.user if edit.status == 'public' and \ @@ -447,7 +436,7 @@ actions.register(subscribeToEdit, cache=False) @login_required_json -def unsubscribeFromEdit(request): +def unsubscribeFromEdit(request, data): ''' takes { id: string, @@ -455,7 +444,6 @@ def unsubscribeFromEdit(request): } returns {} ''' - data = json.loads(request.POST['data']) edit = get_edit_or_404_json(data['id']) user = request.user edit.subscribed_users.remove(user) @@ -466,7 +454,7 @@ actions.register(unsubscribeFromEdit, cache=False) @login_required_json -def sortEdits(request): +def sortEdits(request, data): ''' takes { section: 'personal', @@ -477,7 +465,6 @@ def sortEdits(request): returns {} ''' - data = json.loads(request.POST['data']) position = 0 section = data['section'] section = { diff --git a/pandora/event/views.py b/pandora/event/views.py index 762d649f2..411caa0fa 100644 --- a/pandora/event/views.py +++ b/pandora/event/views.py @@ -16,7 +16,7 @@ from item import utils import models @login_required_json -def addEvent(request): +def addEvent(request, data): ''' takes { name: string, @@ -27,7 +27,6 @@ def addEvent(request): id: string } ''' - data = json.loads(request.POST['data']) existing_names = [] exists = False names = [data['name']] + data.get('alternativeNames', []) @@ -66,7 +65,7 @@ actions.register(addEvent, cache=False) @login_required_json -def editEvent(request): +def editEvent(request, data): ''' takes { id: string, @@ -79,7 +78,6 @@ def editEvent(request): ... } ''' - data = json.loads(request.POST['data']) event = get_object_or_404_json(models.Event, pk=ox.fromAZ(data['id'])) if event.editable(request.user): conflict = False @@ -120,7 +118,7 @@ actions.register(editEvent, cache=False) @login_required_json -def removeEvent(request): +def removeEvent(request, data): ''' remove Event with given id takes { @@ -128,7 +126,6 @@ def removeEvent(request): } returns {} ''' - data = json.loads(request.POST['data']) event = get_object_or_404_json(models.Event, pk=ox.fromAZ(data['id'])) if event.editable(request.user): event.delete() @@ -166,7 +163,7 @@ def order_query(qs, sort): qs = qs.order_by(*order_by, nulls_last=True) return qs -def findEvents(request): +def findEvents(request, data): ''' takes { query: object, @@ -208,8 +205,6 @@ Positions ids: ids of events for which positions are required ''' response = json_response(status=200, text='ok') - - data = json.loads(request.POST['data']) query = parse_query(data, request.user) qs = order_query(query['qs'], query['sort']) qs = qs.distinct() @@ -237,7 +232,7 @@ Positions return render_to_json_response(response) actions.register(findEvents) -def getEventNames(request): +def getEventNames(request, data): ''' takes { } diff --git a/pandora/item/views.py b/pandora/item/views.py index 7cbad78a4..5e1246418 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -97,7 +97,7 @@ def parse_query(data, user): #group by only allows sorting by name or number of itmes return query -def find(request): +def find(request, data): ''' Example: find({ @@ -183,7 +183,6 @@ Positions } } ''' - data = json.loads(request.POST['data']) if settings.JSON_DEBUG: print json.dumps(data, indent=2) query = parse_query(data, request.user) @@ -305,7 +304,7 @@ Positions actions.register(find) -def autocomplete(request): +def autocomplete(request, data): ''' takes { key: string, @@ -318,7 +317,6 @@ def autocomplete(request): items: [string, ...] //array of matching values } ''' - data = json.loads(request.POST['data']) if not 'range' in data: data['range'] = [0, 10] op = data.get('operator', '=') @@ -369,7 +367,7 @@ def autocomplete(request): return render_to_json_response(response) actions.register(autocomplete) -def findId(request): +def findId(request, data): ''' takes { 'id': string @@ -378,7 +376,6 @@ def findId(request): 'year': int } ''' - data = json.loads(request.POST['data']) response = json_response({}) response['data']['items'] = [] if 'id' in data: @@ -398,7 +395,7 @@ def findId(request): actions.register(findId) -def getMetadata(request): +def getMetadata(request, data): ''' takes { id: string, @@ -411,7 +408,6 @@ def getMetadata(request): } ''' - data = json.loads(request.POST['data']) response = json_response({}) if settings.DATA_SERVICE: ''' @@ -431,7 +427,7 @@ def getMetadata(request): return render_to_json_response(response) actions.register(getMetadata) -def getIds(request): +def getIds(request, data): ''' takes { title: string, @@ -448,7 +444,6 @@ def getIds(request): }] } ''' - data = json.loads(request.POST['data']) response = json_response({}) if settings.DATA_SERVICE: r = models.external_data('getIds', data) @@ -459,7 +454,7 @@ def getIds(request): return render_to_json_response(response) actions.register(getIds) -def get(request): +def get(request, data): ''' takes { id: string, @@ -470,7 +465,6 @@ def get(request): } ''' response = json_response({}) - data = json.loads(request.POST['data']) data['keys'] = data.get('keys', []) item = get_object_or_404_json(models.Item, public_id=data['id']) if item.access(request.user): @@ -501,7 +495,7 @@ def get(request): actions.register(get) @login_required_json -def add(request): +def add(request, data): ''' takes { title: string, //(optional) @@ -516,7 +510,6 @@ def add(request): if not request.user.get_profile().capability('canAddItems'): response = json_response(status=403, text='permissino denied') else: - data = json.loads(request.POST['data']) data['title'] = data.get('title', 'Untitled') i = models.Item() i.data['title'] = data['title'] @@ -532,7 +525,7 @@ def add(request): actions.register(add, cache=False) @login_required_json -def edit(request): +def edit(request, data): ''' edit item with id, you can pass one or many key/value pairs, returns all key/values for edited item. @@ -548,7 +541,6 @@ def edit(request): } ''' update_clips = False - data = json.loads(request.POST['data']) item = get_object_or_404_json(models.Item, public_id=data['id']) if item.editable(request.user): item.log() @@ -579,7 +571,7 @@ def edit(request): actions.register(edit, cache=False) @login_required_json -def remove(request): +def remove(request, data): ''' remove item with id, return status is 200/removed on sucess or 403/permission deinied. takes { @@ -590,7 +582,6 @@ def remove(request): } ''' response = json_response({}) - data = json.loads(request.POST['data']) item = get_object_or_404_json(models.Item, public_id=data['id']) user = request.user if user.get_profile().capability('canRemoveItems') == True or \ @@ -606,7 +597,7 @@ def remove(request): return render_to_json_response(response) actions.register(remove, cache=False) -def setPosterFrame(request): +def setPosterFrame(request, data): ''' takes { id: string, @@ -615,7 +606,6 @@ def setPosterFrame(request): returns { } ''' - data = json.loads(request.POST['data']) item = get_object_or_404_json(models.Item, public_id=data['id']) if item.editable(request.user): item.poster_frame = data['position'] @@ -628,7 +618,7 @@ def setPosterFrame(request): actions.register(setPosterFrame, cache=False) -def setPoster(request): +def setPoster(request, data): ''' takes { id: string, @@ -642,7 +632,6 @@ def setPoster(request): } } ''' - data = json.loads(request.POST['data']) item = get_object_or_404_json(models.Item, public_id=data['id']) response = json_response() if item.editable(request.user): @@ -662,7 +651,7 @@ def setPoster(request): return render_to_json_response(response) actions.register(setPoster, cache=False) -def updateExternalData(request): +def updateExternalData(request, data): ''' takes { id: string, @@ -670,7 +659,6 @@ def updateExternalData(request): returns { } ''' - data = json.loads(request.POST['data']) item = get_object_or_404_json(models.Item, public_id=data['id']) response = json_response() if item.editable(request.user): @@ -680,7 +668,7 @@ def updateExternalData(request): return render_to_json_response(response) actions.register(updateExternalData, cache=False) -def lookup(request): +def lookup(request, data): ''' takes { title: string, @@ -695,7 +683,6 @@ def lookup(request): id: string } ''' - data = json.loads(request.POST['data']) if 'id' in data: i = models.Item.objects.get(public_id=data['id']) r = {'id': i.public_id} diff --git a/pandora/itemlist/views.py b/pandora/itemlist/views.py index ddc16d2f6..0a582da9f 100644 --- a/pandora/itemlist/views.py +++ b/pandora/itemlist/views.py @@ -55,7 +55,7 @@ def parse_query(data, user): return query -def findLists(request): +def findLists(request, data): ''' takes { query: { @@ -84,7 +84,6 @@ def findLists(request): items: [{name: string, user: string, featured: bool, public...}] } ''' - data = json.loads(request.POST['data']) query = parse_query(data, request.user) #order @@ -119,7 +118,7 @@ def findLists(request): return render_to_json_response(response) actions.register(findLists) -def getList(request): +def getList(request, data): ''' takes { id: listid @@ -130,7 +129,6 @@ def getList(request): ... } ''' - data = json.loads(request.POST['data']) if 'id' in data: response = json_response() list = get_list_or_404_json(data['id']) @@ -144,7 +142,7 @@ def getList(request): actions.register(getList) @login_required_json -def addListItems(request): +def addListItems(request, data): ''' takes { list: listId, @@ -154,7 +152,6 @@ def addListItems(request): returns { } ''' - data = json.loads(request.POST['data']) list = get_list_or_404_json(data['list']) if 'items' in data: if list.editable(request.user): @@ -173,7 +170,7 @@ actions.register(addListItems, cache=False) @login_required_json -def removeListItems(request): +def removeListItems(request, data): ''' takes { list: listId, @@ -183,7 +180,6 @@ def removeListItems(request): returns { } ''' - data = json.loads(request.POST['data']) list = get_list_or_404_json(data['list']) if 'items' in data: if list.editable(request.user): @@ -200,7 +196,7 @@ def removeListItems(request): actions.register(removeListItems, cache=False) @login_required_json -def orderListItems(request): +def orderListItems(request, data): ''' takes { list: string @@ -209,7 +205,6 @@ def orderListItems(request): returns { } ''' - data = json.loads(request.POST['data']) list = get_list_or_404_json(data['list']) response = json_response() if list.editable(request.user) and list.type == 'static': @@ -225,7 +220,7 @@ actions.register(orderListItems, cache=False) @login_required_json -def addList(request): +def addList(request, data): ''' takes { name: value, @@ -245,7 +240,6 @@ def addList(request): ... } ''' - data = json.loads(request.POST['data']) data['name'] = re.sub(' \[\d+\]$', '', data.get('name', 'Untitled')).strip() name = data['name'] if not name: @@ -285,7 +279,7 @@ actions.register(addList, cache=False) @login_required_json -def editList(request): +def editList(request, data): ''' takes { id: listId, @@ -301,7 +295,6 @@ def editList(request): ... } ''' - data = json.loads(request.POST['data']) list = get_list_or_404_json(data['id']) if list.editable(request.user): response = json_response() @@ -313,7 +306,7 @@ def editList(request): actions.register(editList, cache=False) @login_required_json -def removeList(request): +def removeList(request, data): ''' takes { id: listId, @@ -321,7 +314,6 @@ def removeList(request): returns { } ''' - data = json.loads(request.POST['data']) list = get_list_or_404_json(data['id']) response = json_response() if list.editable(request.user): @@ -334,7 +326,7 @@ actions.register(removeList, cache=False) @login_required_json -def subscribeToList(request): +def subscribeToList(request, data): ''' takes { id: listId, @@ -342,7 +334,6 @@ def subscribeToList(request): returns { } ''' - data = json.loads(request.POST['data']) list = get_list_or_404_json(data['id']) user = request.user if list.status == 'public' and \ @@ -359,7 +350,7 @@ actions.register(subscribeToList, cache=False) @login_required_json -def unsubscribeFromList(request): +def unsubscribeFromList(request, data): ''' takes { id: listId, @@ -368,7 +359,6 @@ def unsubscribeFromList(request): returns { } ''' - data = json.loads(request.POST['data']) list = get_list_or_404_json(data['id']) user = request.user list.subscribed_users.remove(user) @@ -379,7 +369,7 @@ actions.register(unsubscribeFromList, cache=False) @login_required_json -def sortLists(request): +def sortLists(request, data): ''' takes { section: 'personal', @@ -390,7 +380,6 @@ def sortLists(request): returns { } ''' - data = json.loads(request.POST['data']) position = 0 section = data['section'] section = { diff --git a/pandora/log/views.py b/pandora/log/views.py index a90da6117..8e1b0cb76 100644 --- a/pandora/log/views.py +++ b/pandora/log/views.py @@ -15,7 +15,7 @@ from item import utils import models -def log(request): +def log(request, data): ''' takes { url: string, @@ -25,7 +25,6 @@ def log(request): returns { } ''' - data = json.loads(request.POST['data']) if request.user.is_authenticated(): user = request.user else: @@ -48,14 +47,13 @@ actions.register(log, cache=False) @admin_required_json -def removeLogs(request): +def removeLogs(request, data): ''' takes { ids: [string] } returns {} ''' - data = json.loads(request.POST['data']) models.Log.objects.filter(id__in=[ox.fromAZ(i) for i in data['ids']]).delete() response = json_response() return render_to_json_response(response) @@ -86,7 +84,7 @@ def order_query(qs, sort): return qs @admin_required_json -def findLogs(request): +def findLogs(request, data): ''' takes { query: { @@ -108,7 +106,6 @@ def findLogs(request): } ''' - data = json.loads(request.POST['data']) response = json_response() query = parse_query(data, request.user) diff --git a/pandora/news/views.py b/pandora/news/views.py index 84f292e37..6e3b524b8 100644 --- a/pandora/news/views.py +++ b/pandora/news/views.py @@ -12,7 +12,7 @@ from ox.django.api import actions import models -def getNews(request): +def getNews(request, data): ''' takes { id: string @@ -30,7 +30,6 @@ def getNews(request): items: [object] } ''' - data = json.loads(request.POST['data']) response = json_response() if 'id' in data: news = get_object_or_404_json(models.News, id=ox.fromAZ(data['id'])) @@ -42,7 +41,7 @@ def getNews(request): actions.register(getNews) @login_required_json -def addNews(request): +def addNews(request, data): ''' takes { title: string, @@ -54,8 +53,6 @@ def addNews(request): ... } ''' - data = json.loads(request.POST['data']) - news = models.News() for key in ('title', 'text', 'date'): if key in data: @@ -66,14 +63,13 @@ def addNews(request): actions.register(addNews, cache=False) @login_required_json -def removeNews(request): +def removeNews(request, data): ''' takes { ids: [] } returns {} ''' - data = json.loads(request.POST['data']) response = json_response({}) news = get_object_or_404_json(models.News, id=ox.fromAZ(data['id'])) if news.editable(request.user): @@ -85,7 +81,7 @@ def removeNews(request): actions.register(removeNews, cache=False) @login_required_json -def editNews(request): +def editNews(request, data): ''' takes { id: string, @@ -99,7 +95,6 @@ def editNews(request): } ''' response = json_response({}) - data = json.loads(request.POST['data']) n = get_object_or_404_json(models.News, id=ox.fromAZ(data['id'])) if n.editable(request.user): for key in ('title', 'text', 'date'): diff --git a/pandora/person/views.py b/pandora/person/views.py index 1fb3bc54c..89ff08b71 100644 --- a/pandora/person/views.py +++ b/pandora/person/views.py @@ -15,7 +15,7 @@ import models import tasks @admin_required_json -def editName(request): +def editName(request, data): ''' takes { id: id, @@ -27,7 +27,6 @@ def editName(request): ... } ''' - data = json.loads(request.POST['data']) person = get_object_or_404_json(models.Person, pk=ox.fromAZ(data['id'])) response = json_response() if 'sortname' in data: @@ -39,7 +38,7 @@ def editName(request): return render_to_json_response(response) actions.register(editName, cache=False) -def sortName(request): +def sortName(request, data): ''' get sort name(s) for given name or names takes { @@ -50,7 +49,6 @@ def sortName(request): name: sortName } ''' - data = json.loads(request.POST['data']) names = data.get('names', []) if 'name' in data: names.append(data['name']) @@ -89,7 +87,7 @@ def order_query(qs, sort): qs = qs.order_by(*order_by, nulls_last=True) return qs -def findNames(request): +def findNames(request, data): ''' takes { query: { @@ -142,7 +140,6 @@ def findNames(request): items: [string] } ''' - data = json.loads(request.POST['data']) response = json_response() query = parse_query(data, request.user) diff --git a/pandora/place/views.py b/pandora/place/views.py index 0112af4e7..5af224887 100644 --- a/pandora/place/views.py +++ b/pandora/place/views.py @@ -17,7 +17,7 @@ from item import utils import models @login_required_json -def addPlace(request): +def addPlace(request, data): ''' takes { name: "", @@ -38,7 +38,6 @@ def addPlace(request): } ''' #FIXME: check permissions - data = json.loads(request.POST['data']) exists = False existing_names = [] existing_geoname = '' @@ -96,7 +95,7 @@ actions.register(addPlace, cache=False) @login_required_json -def editPlace(request): +def editPlace(request, data): ''' takes { id: string, @@ -107,7 +106,6 @@ def editPlace(request): names: [] } ''' - data = json.loads(request.POST['data']) place = get_object_or_404_json(models.Place, pk=ox.fromAZ(data['id'])) names = data.get('name', []) if isinstance(names, basestring): @@ -161,14 +159,13 @@ actions.register(editPlace, cache=False) @login_required_json -def removePlace(request): +def removePlace(request, data): ''' takes { id: string, } returns {} ''' - data = json.loads(request.POST['data']) if isinstance(data, dict): data = data['id'] place = get_object_or_404_json(models.Place, pk=ox.fromAZ(data)) @@ -209,7 +206,7 @@ def order_query(qs, sort): qs = qs.order_by(*order_by, nulls_last=True) return qs -def findPlaces(request): +def findPlaces(request, data): ''' takes { query: { @@ -276,7 +273,6 @@ Positions https://wiki.0x2620.org/wiki/pandora/QuerySyntax positions: ids of places for which positions are required ''' - data = json.loads(request.POST['data']) response = json_response() query = parse_query(data, request.user) @@ -311,7 +307,7 @@ Positions return render_to_json_response(response) actions.register(findPlaces) -def getPlaceNames(request): +def getPlaceNames(request, data): ''' takes {} returns { diff --git a/pandora/sequence/views.py b/pandora/sequence/views.py index fe01a03de..8529fea36 100644 --- a/pandora/sequence/views.py +++ b/pandora/sequence/views.py @@ -48,7 +48,7 @@ def order_query(qs, sort): qs = qs.order_by(*order_by, nulls_last=True) return qs -def findSequences(request): +def findSequences(request, data): ''' takes { query: ... @@ -61,7 +61,6 @@ def findSequences(request): items: [object] } ''' - data = json.loads(request.POST['data']) response = json_response() query = parse_query(data, request.user) @@ -91,7 +90,7 @@ def findSequences(request): return render_to_json_response(response) actions.register(findSequences) -def getSequence(request): +def getSequence(request, data): ''' takes { id @@ -106,7 +105,6 @@ def getSequence(request): out } ''' - data = json.loads(request.POST['data']) response = json_response() position = float('%0.03f' % data['position']) i = Item.objects.get(public_id=data['id']) diff --git a/pandora/text/views.py b/pandora/text/views.py index 832450db1..a715f17b1 100644 --- a/pandora/text/views.py +++ b/pandora/text/views.py @@ -27,7 +27,7 @@ def get_text_or_404_json(id): return get_object_or_404_json(models.Text, user__username=username, name=name) @login_required_json -def addText(request): +def addText(request, data): ''' takes { name: value, @@ -38,7 +38,6 @@ def addText(request): ... } ''' - data = json.loads(request.POST['data']) data['name'] = re.sub(' \[\d+\]$', '', data.get('name', 'Untitled')).strip() name = data['name'] if not name: @@ -71,7 +70,7 @@ def addText(request): return render_to_json_response(response) actions.register(addText, cache=False) -def getText(request): +def getText(request, data): ''' takes { id: textid, @@ -84,7 +83,6 @@ def getText(request): } ''' response = json_response() - data = json.loads(request.POST['data']) public_id = data['id'] if public_id == '': qs = models.Text.objects.filter(name='') @@ -111,7 +109,7 @@ actions.register(getText) @login_required_json -def editText(request): +def editText(request, data): ''' takes { id: @@ -125,7 +123,6 @@ def editText(request): } ''' response = json_response() - data = json.loads(request.POST['data']) if data['id']: public_id = data['id'].split(':') username = public_id[0] @@ -183,7 +180,7 @@ def parse_query(data, user): return query -def findTexts(request): +def findTexts(request, data): ''' takes { query: { @@ -212,7 +209,6 @@ def findTexts(request): items: [object] } ''' - data = json.loads(request.POST['data']) query = parse_query(data, request.user) #order @@ -249,7 +245,7 @@ actions.register(findTexts) @login_required_json -def removeText(request): +def removeText(request, data): ''' takes { id: string, @@ -257,7 +253,6 @@ def removeText(request): returns { } ''' - data = json.loads(request.POST['data']) text = get_text_or_404_json(data['id']) response = json_response() if text.editable(request.user): @@ -269,14 +264,13 @@ actions.register(removeText, cache=False) @login_required_json -def subscribeToText(request): +def subscribeToText(request, data): ''' takes { id: string, } returns {} ''' - data = json.loads(request.POST['data']) text = get_text_or_404_json(data['id']) user = request.user if text.status == 'public' and \ @@ -293,7 +287,7 @@ actions.register(subscribeToText, cache=False) @login_required_json -def unsubscribeFromText(request): +def unsubscribeFromText(request, data): ''' takes { id: string, @@ -301,7 +295,6 @@ def unsubscribeFromText(request): } returns {} ''' - data = json.loads(request.POST['data']) text = get_text_or_404_json(data['id']) user = request.user text.subscribed_users.remove(user) @@ -312,7 +305,7 @@ actions.register(unsubscribeFromText, cache=False) @login_required_json -def sortTexts(request): +def sortTexts(request, data): ''' takes { section: 'personal', @@ -323,7 +316,6 @@ def sortTexts(request): returns {} ''' - data = json.loads(request.POST['data']) position = 0 section = data['section'] section = { diff --git a/pandora/title/views.py b/pandora/title/views.py index 16dff7d76..0baf6b27a 100644 --- a/pandora/title/views.py +++ b/pandora/title/views.py @@ -15,7 +15,7 @@ from item import utils import models @admin_required_json -def editTitle(request): +def editTitle(request, data): ''' takes { id: string @@ -26,7 +26,6 @@ def editTitle(request): id: string } ''' - data = json.loads(request.POST['data']) title = get_object_or_404_json(models.Title, pk=ox.fromAZ(data['id'])) response = json_response() if 'sorttitle' in data: @@ -66,7 +65,7 @@ def order_query(qs, sort): qs = qs.order_by(*order_by, nulls_last=True) return qs -def findTitles(request): +def findTitles(request, data): ''' takes { query: { @@ -122,7 +121,6 @@ def findTitles(request): returns {items: [object]} ''' - data = json.loads(request.POST['data']) response = json_response() query = parse_query(data, request.user) diff --git a/pandora/tv/views.py b/pandora/tv/views.py index eafd470c3..0e745a9be 100644 --- a/pandora/tv/views.py +++ b/pandora/tv/views.py @@ -9,7 +9,7 @@ from ox.django.shortcuts import render_to_json_response, json_response from itemlist.views import get_list_or_404_json from ox.django.api import actions -def tv(request): +def tv(request, data): ''' takes { list: string @@ -21,7 +21,6 @@ def tv(request): ... } ''' - data = json.loads(request.POST['data']) if 'list' in data and data['list']: list = get_list_or_404_json(data['list']) if list.accessible(request.user): diff --git a/pandora/user/persona.py b/pandora/user/persona.py index 8f017cb66..17722679e 100644 --- a/pandora/user/persona.py +++ b/pandora/user/persona.py @@ -18,8 +18,7 @@ import requests import models -def signin(request): - data = json.loads(request.POST['data']) +def signin(request, data): response = json_response({ 'errors': { 'email': 'Failed to verify email' diff --git a/pandora/user/views.py b/pandora/user/views.py index 6eb40c718..8a39b863b 100644 --- a/pandora/user/views.py +++ b/pandora/user/views.py @@ -43,7 +43,7 @@ def get_group_or_404(data): return g -def signin(request): +def signin(request, data): ''' takes { username: string, @@ -60,7 +60,6 @@ def signin(request): } } ''' - data = json.loads(request.POST['data']) if 'assertion' in data: response = persona.signin(request) elif 'username' in data and 'password' in data: @@ -106,7 +105,7 @@ def signin(request): actions.register(signin, cache=False) -def signout(request): +def signout(request, data): ''' takes {} @@ -130,7 +129,7 @@ def signout(request): actions.register(signout, cache=False) -def signup(request): +def signup(request, data): ''' takes { username: string, @@ -148,7 +147,6 @@ def signup(request): } } ''' - data = json.loads(request.POST['data']) if 'username' in data and 'password' in data: data['username'] = data['username'].strip() if 'email' in data: @@ -215,7 +213,7 @@ def signup(request): actions.register(signup, cache=False) -def resetPassword(request): +def resetPassword(request, data): ''' takes { username: string, @@ -231,7 +229,6 @@ def resetPassword(request): } } ''' - data = json.loads(request.POST['data']) if 'code' in data and 'password' in data: if not data['password']: response = json_response({ @@ -268,7 +265,7 @@ def resetPassword(request): actions.register(resetPassword, cache=False) -def requestToken(request): +def requestToken(request, data): ''' takes { username: string, @@ -283,7 +280,6 @@ def requestToken(request): username: user } ''' - data = json.loads(request.POST['data']) user = None if 'username' in data: try: @@ -334,7 +330,7 @@ actions.register(requestToken, cache=False) @capability_required_json('canManageUsers') -def editUser(request): +def editUser(request, data): ''' takes { key: value @@ -346,7 +342,6 @@ def editUser(request): } ''' response = json_response() - data = json.loads(request.POST['data']) user = get_object_or_404_json(User, pk=ox.fromAZ(data['id'])) profile = user.get_profile() @@ -390,7 +385,7 @@ actions.register(editUser, cache=False) @capability_required_json('canManageUsers') -def removeUser(request): +def removeUser(request, data): ''' takes { username: username @@ -398,14 +393,13 @@ def removeUser(request): returns {} ''' response = json_response() - data = json.load(request.POST['data']) u = get_user_or_404(data) u.delete() return render_to_json_response(response) actions.register(removeUser, cache=False) -def findUser(request): +def findUser(request, data): ''' takes { key: string, //username, email @@ -418,7 +412,6 @@ def findUser(request): users: [object] } ''' - data = json.loads(request.POST['data']) response = json_response(status=200, text='ok') #keys = data.get('keys') #if not keys: @@ -481,7 +474,7 @@ def order_query(qs, sort): @capability_required_json('canManageUsers') -def findUsers(request): +def findUsers(request, data): ''' takes { query: { @@ -545,7 +538,6 @@ Positions positions: ids of places for which positions are required ''' response = json_response(status=200, text='ok') - data = json.loads(request.POST['data']) query = parse_query(data, request.user) qs = order_query(query['qs'], query['sort']) if 'keys' in data: @@ -575,7 +567,7 @@ actions.register(findUsers) @capability_required_json('canManageUsers') -def getUser(request): +def getUser(request, data): ''' takes { id: string or username: string, @@ -587,14 +579,13 @@ def getUser(request): } ''' response = json_response() - data = json.loads(request.POST['data']) u = get_user_or_404(data) response['data'] = u.data.get().json(data.get('keys', []), request.user) return render_to_json_response(response) actions.register(getUser) @login_required_json -def mail(request): +def mail(request, data): ''' takes { to: [string], // array of usernames to send mail to @@ -610,7 +601,6 @@ def mail(request): } ''' response = json_response() - data = json.loads(request.POST['data']) p = request.user.get_profile() if p.capability('canSendMail'): email_from = '"%s" <%s>' % (settings.SITENAME, settings.CONFIG['site']['email']['system']) @@ -658,7 +648,7 @@ def mail(request): return render_to_json_response(response) actions.register(mail, cache=False) -def contact(request): +def contact(request, data): ''' takes { email: string, @@ -669,7 +659,6 @@ def contact(request): returns { } ''' - data = json.loads(request.POST['data']) name = data.get('name', '') email = data.get('email', '') if request.user.is_authenticated(): @@ -731,7 +720,7 @@ def getPositionById(list, key): @login_required_json -def editPreferences(request): +def editPreferences(request, data): ''' takes { key: value @@ -739,7 +728,6 @@ def editPreferences(request): keys: email, password returns {} ''' - data = json.loads(request.POST['data']) errors = {} change = False response = json_response() @@ -775,7 +763,7 @@ def reset_ui(request): return redirect('/') -def resetUI(request): +def resetUI(request, data): ''' reset user ui settings to defaults takes { @@ -795,7 +783,7 @@ def resetUI(request): actions.register(resetUI, cache=False) -def setUI(request): +def setUI(request, data): ''' takes { key.subkey: value @@ -806,7 +794,6 @@ def setUI(request): returns { } ''' - data = json.loads(request.POST['data']) if request.user.is_authenticated(): profile = request.user.get_profile() ui = profile.ui @@ -848,8 +835,12 @@ actions.register(setUI, cache=False) @capability_required_json('canManageUsers') -def statistics(request): +def statistics(request, data): ''' + takes {} + returns { + ... + } ''' response = json_response() from app.models import Settings @@ -873,7 +864,7 @@ def group_json(g): @capability_required_json('canManageUsers') -def getGroups(request): +def getGroups(request, data): ''' takes {} returns { @@ -884,7 +875,6 @@ def getGroups(request): ''' response = json_response(status=200, text='ok') - data = json.loads(request.POST['data']) response['data']['groups'] = [] for g in Group.objects.all().order_by('name'): response['data']['groups'].append(group_json(g)) @@ -893,7 +883,7 @@ actions.register(getGroups) @capability_required_json('canManageUsers') -def getGroup(request): +def getGroup(request, data): ''' takes { id: string @@ -909,7 +899,6 @@ def getGroup(request): ''' response = json_response(status=200, text='ok') - data = json.loads(request.POST['data']) g = get_group_or_404(data) response['data'] = group_json(g) return render_to_json_response(response) @@ -917,7 +906,7 @@ actions.register(getGroup, cache=False) @capability_required_json('canManageUsers') -def addGroup(request): +def addGroup(request, data): ''' takes { name: string @@ -931,7 +920,6 @@ def addGroup(request): ''' response = json_response(status=200, text='ok') - data = json.loads(request.POST['data']) created = False n = 1 name = data['name'] @@ -946,7 +934,7 @@ actions.register(addGroup, cache=False) @capability_required_json('canManageUsers') -def editGroup(request): +def editGroup(request, data): ''' takes { id: string, @@ -960,7 +948,6 @@ def editGroup(request): ''' response = json_response(status=200, text='ok') - data = json.loads(request.POST['data']) g = Group.objects.get(id=ox.fromAZ(data['id'])) g.name = data['name'] g.save() @@ -970,7 +957,7 @@ actions.register(editGroup, cache=False) @capability_required_json('canManageUsers') -def removeGroup(request): +def removeGroup(request, data): ''' takes { id: string @@ -980,7 +967,6 @@ def removeGroup(request): ''' response = json_response(status=200, text='ok') - data = json.loads(request.POST['data']) g = get_group_or_404(data) for i in g.items.all(): i.groups.remove(g)