diff --git a/aurweb/models/account_type.py b/aurweb/models/account_type.py index 502a86b1..ca302e5b 100644 --- a/aurweb/models/account_type.py +++ b/aurweb/models/account_type.py @@ -1,5 +1,6 @@ from sqlalchemy import Column, Integer +from aurweb import db from aurweb.models.declarative import Base @@ -20,3 +21,30 @@ class AccountType(Base): def __repr__(self): return "" % ( self.ID, str(self)) + + +# Define some AccountType.AccountType constants. +USER = "User" +TRUSTED_USER = "Trusted User" +DEVELOPER = "Developer" +TRUSTED_USER_AND_DEV = "Trusted User & Developer" + +# Fetch account type IDs from the database for constants. +_account_types = db.query(AccountType) +USER_ID = _account_types.filter( + AccountType.AccountType == USER).first().ID +TRUSTED_USER_ID = _account_types.filter( + AccountType.AccountType == TRUSTED_USER).first().ID +DEVELOPER_ID = _account_types.filter( + AccountType.AccountType == DEVELOPER).first().ID +TRUSTED_USER_AND_DEV_ID = _account_types.filter( + AccountType.AccountType == TRUSTED_USER_AND_DEV).first().ID +_account_types = None # Get rid of the query handle. + +# Map string constants to integer constants. +ACCOUNT_TYPE_ID = { + USER: USER_ID, + TRUSTED_USER: TRUSTED_USER_ID, + DEVELOPER: DEVELOPER_ID, + TRUSTED_USER_AND_DEV: TRUSTED_USER_AND_DEV_ID +}