def get(event, context): logging.info("received event %s", event) body = { #"message": "Go Serverless v1.0! Your function executed successfully!", # "role" : User.get(User.id == 1).role, # "user_name" : User.get(User.id == 1).user_name, # "first_name" : User.get(User.id == 1).first_name, # "last_name" : User.get(User.id == 1).last_name, # "phone_number" : User.get(User.id == 1).phone_number, # "email_id" : User.get(User.id == 1).email_id } if 'pathParameters' in event and 'id' in event['pathParameters']: _id = event['pathParameters']['id'] try: account = Account.get(id=_id) response = { "statusCode": 200, "body": json.dumps(model_to_dict(account)) } except pw.DoesNotExist: logger.exception( "Account detail does not exist for id {}".format(_id)) body = { "message": "Account detail does not exist for id {}".format(_id), } response = {"statusCode": 404, "body": json.dumps(body)} return response
def _get_default_account(): default = Account.query(Account.username==DEFAULT_NAME, Account.password==DEFAULT_PW, Account.service==DEFAULT_SERVICE).get() if default: return default else: default_key = Account(username=DEFAULT_NAME, password=DEFAULT_PW, service=DEFAULT_SERVICE).put() return default_key.get()
def getAccount(account_id): account_id = convert(int, account_id) return Account.get(account_id).serialize()