From 0b83d2f2b5461c402120b089e2686c1ce4c63b25 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Tue, 25 Dec 2018 19:49:17 +0000 Subject: [PATCH] Add task to bulk import avatars from forum --- app/tasks/forumtasks.py | 19 +++++++++++++++++-- app/templates/admin/list.html | 1 + app/templates/users/user_profile_page.html | 4 ++-- app/views/admin.py | 5 ++++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/tasks/forumtasks.py b/app/tasks/forumtasks.py index 0a5f028..9e4cbfb 100644 --- a/app/tasks/forumtasks.py +++ b/app/tasks/forumtasks.py @@ -25,7 +25,8 @@ import urllib.request from urllib.parse import urlparse, quote_plus @celery.task() -def checkForumAccount(username): +def checkForumAccount(username, forceNoSave=False): + print("Checking " + username) try: profile = getProfile("https://forum.minetest.net", username) except OSError: @@ -52,9 +53,23 @@ def checkForumAccount(username): user.profile_pic = pic # Save - if needsSaving: + if needsSaving and not forceNoSave: db.session.commit() + return needsSaving + +@celery.task() +def checkAllForumAccounts(forceNoSave=False): + needsSaving = False + query = User.query.filter(User.forums_username.isnot(None)) + for user in query.all(): + needsSaving = checkForumAccount(user.username) or needsSaving + + if needsSaving and not forceNoSave: + db.session.commit() + + return needsSaving + regex_tag = re.compile(r"\[([a-z0-9_]+)\]") BANNED_NAMES = ["mod", "game", "old", "outdated", "wip", "api", "beta", "alpha", "git"] diff --git a/app/templates/admin/list.html b/app/templates/admin/list.html index 5237304..d4e4da6 100644 --- a/app/templates/admin/list.html +++ b/app/templates/admin/list.html @@ -20,6 +20,7 @@