1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-08 21:21:06 +00:00

Migrate all()

This commit is contained in:
Mo 2022-05-16 18:12:53 +02:00
parent 4332e145b7
commit af7fcaa59c

View file

@ -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!")