def addContext(context, request): """ """ # Initialize a Context object from the request newcontext = Context() newcontext.fromRequest(request) # If we have the _id setted, then the object already existed in the DB, # otherwise, proceed to insert it into the DB # In both cases, respond with the JSON of the object and the appropiate # HTTP Status Code if newcontext.get('_id'): # Already Exists code = 200 else: # New User code = 201 contextid = newcontext.insert() newcontext['_id'] = contextid handler = JSONResourceEntity(newcontext.flatten(), status_code=code) return handler.buildResponse()