def POST(self, auth_user=None, auth_app_id=None): '''Record the given events.''' list_id = None params = web.input(data=None) try: if params.data: data = decode_json(params.data) else: data = decode_json(web.ctx.data) except ValueError, e: logging.warn(e) return error_response(400, 'Could not parse JSON')
def POST(self, auth_user=None, auth_app_id=None): ''' Create a new app and return a JSON object containing the new app information. ''' params = web.input(data=None) try: if params.data: data = decode_json(params.data) else: data = decode_json(web.ctx.data) App.validate(data) except Exception, e: logging.error(e) return error_response(400, 'Data did not pass validation')
def POST(self, auth_user=None, auth_app_id=None): ''' Creates a new user and returns a JSON object containing the id and auth token for the new user. ''' params = web.input(data=None) try: if params.data: data = decode_json(params.data) else: data = decode_json(web.ctx.data) User.validate(data) except ValueError, e: logging.warn(e) return error_response(400, 'Could not parse JSON')
def POST(self, auth_user=None, auth_app_id=None): ''' Creates a new AssignmentTemplate and returns a JSON object containing the id for the new AssignmentTemplate. ''' params = web.input(data=None) depth = parse_int_param(util.get_header('X-OpenMinds-Depth'), 0) try: if params.data: data = decode_json(params.data) else: data = decode_json(web.ctx.data) AssignmentTemplate.validate(data) except ValueError, e: logging.warn(e) return error_response(400, 'Could not parse JSON')
def POST(self, auth_user=None, auth_app_id=None): ''' Creates a new Assignment and returns a JSON object containing the id for the new Assignment. You could pass up a fully specified assignment, but as a convenience we also allow you to pass up an assignment template id, which will fill in all the data for you. ''' params = web.input(data=None) depth = parse_int_param(util.get_header('X-OpenMinds-Depth'), 0) try: if params.data: data = decode_json(params.data) else: data = decode_json(web.ctx.data) except ValueError, e: logging.warn(e) return error_response(400, 'Could not parse JSON')
def PUT(self, list_id, auth_user=None, auth_app_id=None): ''' Update the given list, and returns a JSON object containing the new timestamp. ''' item_list = get_generic_document(list_id, List) try: data = decode_json(web.ctx.data) List.validate(data) except ValueError, e: logging.warn(e) return error_response(400, 'Could not parse JSON')
def _get_json(self, method, path, body={}, params={}): response = self._api_response(method, path, body, params).read() return decode_json(response)
return error_response(500, 'Server Error') @public_api_auth def PUT(self, app_id, auth_user=None, auth_app_id=None): ''' Update the given app, and returns a JSON object containing the new timestamp. ''' try: app_id = ObjectId(app_id) except Exception, e: logging.error(e) return error_response(400, 'Not a valid app id') try: data = decode_json(web.ctx.data) App.validate(data) except Exception, e: return error_response(400, 'Data did not pass validation') try: app = App.collection.find_one({'_id': app_id, 'deleted': False}) except Exception, e: logging.error(e) return error_response(500, 'Server Error') if not app: message = 'App does not exist' logging.warn(message) return error_response(404, message) if not app.user_can_update(auth_user):
def PUT(self, class_id, auth_user=None, auth_app_id=None): ''' Update the given class, and returns a JSON object containing the new timestamp. ''' try: school_class = get_generic_document(class_id, Class) except HTTPError, e: return e.error_response() if not school_class.user_can_update(auth_user): message = 'Class cannot be modified by the user' logging.warn(message) return error_response(403, message) try: data = decode_json(web.ctx.data) Class.validate(data) # Convert string user ids to object ids. If an object id is not # valid, return an error response code. if 'instructor' in data: data['instructor'] = ObjectId(data['instructor']) except ValueError, e: logging.warn(e) return error_response(400, 'Could not parse JSON') except ValidationError, e: logging.warn(e) return error_response(400, e.error) try: school_class.update_class(data) school_class.save()