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 <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-06-24 19:28:36 -07:00
parent 4927a61378
commit ef4a7308ee

View file

@ -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 "<AccountType(ID='%s', AccountType='%s')>" % (
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
}