mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Migrate all()
This commit is contained in:
parent
4332e145b7
commit
af7fcaa59c
1 changed files with 8 additions and 6 deletions
|
@ -1,4 +1,5 @@
|
|||
from flask_security import admin_change_password
|
||||
from sqlalchemy import select
|
||||
|
||||
from ... import app, db
|
||||
from ...independent_funs import randomPassword
|
||||
|
@ -12,15 +13,13 @@ def main():
|
|||
|
||||
with app.app_context():
|
||||
with db.session.begin():
|
||||
admin_query = Admin.query
|
||||
admins = admin_query.filter(Admin.user.has(User.active == True))
|
||||
admins = db.session.execute(select(Admin).join(User).where(User.active == True)).scalars().all()
|
||||
activate_user = False
|
||||
if admins.count() == 0:
|
||||
|
||||
if len(admins) == 0:
|
||||
print("There is no admin with an active user. The user of the choosen admin will be activated")
|
||||
admins = admin_query.all()
|
||||
admins = db.session.execute(select(Admin)).scalars().all()
|
||||
activate_user = True
|
||||
else:
|
||||
admins = admins.all()
|
||||
|
||||
num_admins = len(admins)
|
||||
|
||||
|
@ -44,6 +43,9 @@ def main():
|
|||
choosen_admin_user, new_password, notify=False
|
||||
) # Password is automatically hashed with this function
|
||||
|
||||
if activate_user:
|
||||
choosen_admin_user.active = True
|
||||
|
||||
box(new_password, "New password")
|
||||
|
||||
print("Done!")
|
||||
|
|
Loading…
Reference in a new issue