mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-09 22:47:36 +01:00
Add task to bulk import avatars from forum
This commit is contained in:
parent
21960f2404
commit
0b83d2f2b5
@ -25,7 +25,8 @@ import urllib.request
|
|||||||
from urllib.parse import urlparse, quote_plus
|
from urllib.parse import urlparse, quote_plus
|
||||||
|
|
||||||
@celery.task()
|
@celery.task()
|
||||||
def checkForumAccount(username):
|
def checkForumAccount(username, forceNoSave=False):
|
||||||
|
print("Checking " + username)
|
||||||
try:
|
try:
|
||||||
profile = getProfile("https://forum.minetest.net", username)
|
profile = getProfile("https://forum.minetest.net", username)
|
||||||
except OSError:
|
except OSError:
|
||||||
@ -52,9 +53,23 @@ def checkForumAccount(username):
|
|||||||
user.profile_pic = pic
|
user.profile_pic = pic
|
||||||
|
|
||||||
# Save
|
# Save
|
||||||
if needsSaving:
|
if needsSaving and not forceNoSave:
|
||||||
db.session.commit()
|
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_]+)\]")
|
regex_tag = re.compile(r"\[([a-z0-9_]+)\]")
|
||||||
BANNED_NAMES = ["mod", "game", "old", "outdated", "wip", "api", "beta", "alpha", "git"]
|
BANNED_NAMES = ["mod", "game", "old", "outdated", "wip", "api", "beta", "alpha", "git"]
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
<select name="action">
|
<select name="action">
|
||||||
<option value="importmodlist" selected>Import forum topics</option>
|
<option value="importmodlist" selected>Import forum topics</option>
|
||||||
<option value="recalcscores">Recalculate package scores</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="importscreenshots">Import screenshots from VCS</option>
|
||||||
<!-- <option value="importdepends">Import dependencies from downloads</option> -->
|
<!-- <option value="importdepends">Import dependencies from downloads</option> -->
|
||||||
<!-- <option value="modprovides">Set provides to mod name</option> -->
|
<!-- <option value="modprovides">Set provides to mod name</option> -->
|
||||||
|
@ -139,7 +139,7 @@
|
|||||||
{% from "macros/packagegridtile.html" import render_pkggrid %}
|
{% from "macros/packagegridtile.html" import render_pkggrid %}
|
||||||
{{ render_pkggrid(packages, show_author=False) }}
|
{{ 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">
|
<div class="card mt-3">
|
||||||
<a name="unadded-topics"></a>
|
<a name="unadded-topics"></a>
|
||||||
<h2 class="card-header">Unadded topics</h2>
|
<h2 class="card-header">Unadded topics</h2>
|
||||||
@ -153,7 +153,7 @@
|
|||||||
{% from "macros/topics.html" import render_topics_table %}
|
{% from "macros/topics.html" import render_topics_table %}
|
||||||
{{ render_topics_table(topics_to_add, show_author=False, show_discard=True, current_user=current_user) }}
|
{{ render_topics_table(topics_to_add, show_author=False, show_discard=True, current_user=current_user) }}
|
||||||
{% else %}
|
{% 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 %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -22,7 +22,7 @@ from app import app
|
|||||||
from app.models import *
|
from app.models import *
|
||||||
from celery import uuid
|
from celery import uuid
|
||||||
from app.tasks.importtasks import importRepoScreenshot, importAllDependencies, makeVCSRelease
|
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 flask_wtf import FlaskForm
|
||||||
from wtforms import *
|
from wtforms import *
|
||||||
from app.utils import loginUser, rank_required, triggerNotif
|
from app.utils import loginUser, rank_required, triggerNotif
|
||||||
@ -36,6 +36,9 @@ def admin_page():
|
|||||||
if action == "importmodlist":
|
if action == "importmodlist":
|
||||||
task = importTopicList.delay()
|
task = importTopicList.delay()
|
||||||
return redirect(url_for("check_task", id=task.id, r=url_for("todo_topics_page")))
|
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":
|
elif action == "importscreenshots":
|
||||||
packages = Package.query \
|
packages = Package.query \
|
||||||
.filter_by(soft_deleted=False) \
|
.filter_by(soft_deleted=False) \
|
||||||
|
Loading…
Reference in New Issue
Block a user