def workspaceGET(): ''' ''' # TODO - should whoami redirect to a login page? ### yes the client should only expect to handle HTTP CODES ### compare on userID identity = auth.whoami() if not identity: abort(403) else: wout = {} dolog("INFO", "Calling workspace with %s" % identity.userID) w = model.workspace_by_user(identity.userID) dolog("INFO", repr(w)) ## w is a list of models (folders, cols etc). # it would require some flattening or a JSONEncoder but we just want # short form for now short_format_list = [{ "id": i.id_, "title": i.title, "mediaType": i.mediaType} for i in w] flatten = json.dumps(short_format_list) resp = flask.make_response(flatten) resp.content_type = 'application/json; charset=utf-8' resp.headers["Access-Control-Allow-Origin"] = "*" auth.callstatsd('rhaptos2.e2repo.workspace.GET') return resp
def folder_get(folderuri): """ """ foldbody=[] fold = model.get_by_id(model.Folder, folderuri, g.user_id) foldjson = fold.to_dict() for obj in fold.body: try: mod = model.get_by_id(model.Module, obj, g.user_id) foldbody.append({"id":mod.id_,"title":mod.title,"mediaType":mod.mediaType}) except: # FIXME want to catch no such object error pass foldjson['body'] = foldbody foldjson['id'] = foldjson.pop('id_') resp = flask.make_response(json.dumps(foldjson)) resp.content_type = 'application/json' resp.headers["Access-Control-Allow-Origin"] = "*" auth.callstatsd('rhaptos2.e2repo.workspace.GET') return resp