I have an enum class with the following code:
# enums.py
class AuthCode(Enum):
ALREADY_AUTHENTICATED = 1
MISSING_EMAIL = 2
MISSING_PASSWORD = 3
MISSING_REGISTRATION_TOKEN_CODE = 4
INVALID_EMAIL = 5
REDEEMED_EMAIL = 6
INVALID_PASSWORD = 7
INVALID_REGISTRATION_TOKEN_CODE = 8
REDEEMED_REGISTRATION_TOKEN_CODE = 9
INVALID_CREDENTIALS = 10
SIGNIN_SUCCESSFUL = 11
REGISTRATION_SUCCESSFUL = 12
class AuthCodeMessage(Enum):
AuthCode.ALREADY_AUTHENTICATED = "User was already logged in"
AuthCode.MISSING_EMAIL = "Email was not specified"
AuthCode.MISSING_PASSWORD = "Password was not specified"
AuthCode.MISSING_REGISTRATION_TOKEN_CODE = "Registration token code was not specified"
AuthCode.INVALID_EMAIL = "Email is invalid"
AuthCode.REDEEMED_EMAIL = "An account with this email has been created already"
AuthCode.INVALID_PASSWORD = "Password does not meet minimum password requirements"
AuthCode.INVALID_REGISTRATION_TOKEN_CODE = "Registration token code is invalid"
AuthCode.REDEEMED_REGISTRATION_TOKEN_CODE = "Registration token code has been redeemed already"
AuthCode.INVALID_CREDENTIALS = "Account with these credentials does not exist"
AuthCode.SIGNIN_SUCCESSFUL = "User has been signed in successfully"
AuthCode.REGISTRATION_SUCCESSFUL = "User account has been created successfully"
Is it possible to define the second enum (AuthCodeMessage) the way it is defined (i.e., using another enum as a key). How can I retrieve the enum value?
Edit 1: I would like to call my this enumeration from my code using the an approach similar to the following:
from enums import AuthCode, AuthCodeMessage
def authResponse(authCode):
AuthCode.ALREADY_AUTHENTICATED
return jsonify({
"code": authCode,
"message": AuthCodeMessage.authCode
})
authResponse(AuthCode.ALREADY_AUTHENTICATED)
authResponse()supposed to be doing? Because it isn't doing anything.