From ef4a7308ee16e0e42b6adff170dccc259807cade Mon Sep 17 00:00:00 2001 From: Kevin Morris Date: Thu, 24 Jun 2021 19:28:36 -0700 Subject: [PATCH] add AccountType constants New constants (in aurweb.models.account_type): - USER: "User" - USER_ID: USER's ID - TRUSTED_USER: "Trusted User" - TRUSTED_USER_ID: TRUSTED_USER's ID - DEVELOPER: "Developer" - DEVELOPER_ID: DEVELOPER's ID - TRUSTED_USER_AND_DEV: "TRUSTED_USER_AND_DEV" - TRUSTED_USER_AND_DEV_ID: TRUSTED_USER_AND_DEV's ID Signed-off-by: Kevin Morris --- aurweb/models/account_type.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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 +}