def grantadmin(username): """ Grant admin privileges to given user """ from spendb.model import meta as db from spendb.model.account import Account account = Account.by_name(username) if account is None: raise Exception("Account `%s` not found." % username) account.admin = True db.session.add(account) db.session.commit()
def make_account(name='test', fullname='Test User', email='*****@*****.**', twitter='testuser', admin=False, password='******'): from spendb.model.account import Account # First see if the account already exists and if so, return it account = Account.by_name(name) if account: return account # Account didn't exist so we create it and return it account = Account() account.name = name account.fullname = fullname account.email = email account.twitter_handle = twitter account.admin = admin account.password = generate_password_hash(password) db.session.add(account) db.session.commit() return account