Add task to bulk import avatars from forum

This commit is contained in:
rubenwardy 2018-12-25 19:49:17 +00:00
parent 21960f2404
commit 0b83d2f2b5
4 changed files with 24 additions and 5 deletions

View File

@ -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"]

View File

@ -20,6 +20,7 @@
<select name="action">
<option value="importmodlist" selected>Import forum topics</option>
<option value="recalcscores">Recalculate package scores</option>
<option value="checkusers">Check forum users</option>
<option value="importscreenshots">Import screenshots from VCS</option>
<!-- <option value="importdepends">Import dependencies from downloads</option> -->
<!-- <option value="modprovides">Set provides to mod name</option> -->

View File

@ -139,7 +139,7 @@
{% from "macros/packagegridtile.html" import render_pkggrid %}
{{ render_pkggrid(packages, show_author=False) }}
{% if current_user == user or (current_user.is_authenticated and current_user.rank.atLeast(UserRank.EDITOR)) %}
{% if current_user == user or (current_user.is_authenticated and current_user.rank.atLeast(current_user.rank.EDITOR)) %}
<div class="card mt-3">
<a name="unadded-topics"></a>
<h2 class="card-header">Unadded topics</h2>
@ -153,7 +153,7 @@
{% from "macros/topics.html" import render_topics_table %}
{{ render_topics_table(topics_to_add, show_author=False, show_discard=True, current_user=current_user) }}
{% else %}
<p>Congrats! You don't have any topics which aren't on CDB.</p>
<p class="card-body">Congrats! You don't have any topics which aren't on CDB.</p>
{% endif %}
</div>
{% endif %}

View File

@ -22,7 +22,7 @@ from app import app
from app.models import *
from celery import uuid
from app.tasks.importtasks import importRepoScreenshot, importAllDependencies, makeVCSRelease
from app.tasks.forumtasks import importTopicList
from app.tasks.forumtasks import importTopicList, checkAllForumAccounts
from flask_wtf import FlaskForm
from wtforms import *
from app.utils import loginUser, rank_required, triggerNotif
@ -36,6 +36,9 @@ def admin_page():
if action == "importmodlist":
task = importTopicList.delay()
return redirect(url_for("check_task", id=task.id, r=url_for("todo_topics_page")))
elif action == "checkusers":
task = checkAllForumAccounts.delay()
return redirect(url_for("check_task", id=task.id, r=url_for("admin_page")))
elif action == "importscreenshots":
packages = Package.query \
.filter_by(soft_deleted=False) \