mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-23 06:22:24 +01:00
Fix crash in upgrade_new_members task
This commit is contained in:
parent
4435679737
commit
ba7ed40d6a
@ -159,12 +159,11 @@ def get_locale():
|
||||
locale = request.accept_languages.best_match(locales)
|
||||
|
||||
if locale and current_user.is_authenticated:
|
||||
new_session = models.db.create_session({})()
|
||||
with models.db.create_session({})() as new_session:
|
||||
new_session.query(models.User) \
|
||||
.filter(models.User.username == current_user.username) \
|
||||
.update({ "locale": locale })
|
||||
new_session.commit()
|
||||
new_session.close()
|
||||
|
||||
return locale
|
||||
|
||||
|
@ -29,6 +29,7 @@ from app.models import PackageRelease, db, Package, PackageState, PackageScreens
|
||||
from app.tasks.emails import send_pending_digests
|
||||
from app.tasks.forumtasks import importTopicList, checkAllForumAccounts
|
||||
from app.tasks.importtasks import importRepoScreenshot, checkZipRelease, check_for_updates, updateAllGameSupport
|
||||
from app.tasks.usertasks import upgrade_new_members
|
||||
from app.utils import addNotification, get_system_user
|
||||
from app.utils.image import get_image_size
|
||||
|
||||
@ -339,10 +340,6 @@ def do_send_pending_digests():
|
||||
|
||||
@action("Set users to new member")
|
||||
def set_new_members():
|
||||
threshold = datetime.datetime.now() - datetime.timedelta(days=7)
|
||||
|
||||
User.query.filter(User.rank == UserRank.MEMBER,
|
||||
~User.replies.any(ThreadReply.created_at < threshold),
|
||||
~User.packages.any(Package.approved_at < threshold)).update({"rank": UserRank.NEW_MEMBER}, synchronize_session=False)
|
||||
|
||||
db.session.commit()
|
||||
task_id = uuid()
|
||||
upgrade_new_members.apply_async((), task_id=task_id)
|
||||
return redirect(url_for("tasks.check", id=task_id, r=url_for("admin.admin_page")))
|
||||
|
@ -37,10 +37,11 @@ def delete_inactive_users():
|
||||
|
||||
@celery.task()
|
||||
def upgrade_new_members():
|
||||
with db.create_session({})() as session:
|
||||
threshold = datetime.datetime.now() - datetime.timedelta(days=7)
|
||||
|
||||
User.query.filter(and_(User.rank == UserRank.NEW_MEMBER, or_(
|
||||
session.query(User).filter(and_(User.rank == UserRank.NEW_MEMBER, or_(
|
||||
User.replies.any(ThreadReply.created_at < threshold),
|
||||
User.packages.any(Package.approved_at < threshold)))).update({"rank": UserRank.MEMBER})
|
||||
User.packages.any(Package.approved_at < threshold)))).update({"rank": UserRank.MEMBER}, synchronize_session=False)
|
||||
|
||||
db.session.commit()
|
||||
session.commit()
|
||||
|
Loading…
Reference in New Issue
Block a user