def addUser(context, request): """ """ username = request.matchdict['username'] rest_params = {'username': username} # Initialize a User object from the request newuser = User() newuser.fromRequest(request, rest_params=rest_params) # 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 newuser.get('_id'): # Already Exists code = 200 else: # New User code = 201 userid = newuser.insert() newuser['_id'] = userid handler = JSONResourceEntity(newuser.flatten(), status_code=code) return handler.buildResponse()