Improve admin list design

This commit is contained in:
rubenwardy 2020-07-12 03:38:14 +01:00
parent a123f42291
commit d7ecf8041a
3 changed files with 54 additions and 67 deletions

@ -33,10 +33,12 @@ import datetime, os
def admin_page():
if request.method == "POST":
action = request.form["action"]
if action == "delstuckreleases":
PackageRelease.query.filter(PackageRelease.task_id != None).delete()
db.session.commit()
return redirect(url_for("admin.admin_page"))
elif action == "checkreleases":
releases = PackageRelease.query.filter(PackageRelease.url.like("/uploads/%")).all()
@ -52,6 +54,7 @@ def admin_page():
time.sleep(0.1)
return redirect(url_for("todo.view"))
elif action == "reimportpackages":
tasks = []
for package in Package.query.filter_by(approved=True, soft_deleted=False).all():
@ -67,12 +70,15 @@ def admin_page():
time.sleep(0.1)
return redirect(url_for("todo.view"))
elif action == "importmodlist":
task = importTopicList.delay()
return redirect(url_for("tasks.check", id=task.id, r=url_for("todo.topics")))
elif action == "checkusers":
task = checkAllForumAccounts.delay()
return redirect(url_for("tasks.check", id=task.id, r=url_for("admin.admin_page")))
elif action == "importscreenshots":
packages = Package.query \
.filter_by(soft_deleted=False) \
@ -83,6 +89,7 @@ def admin_page():
importRepoScreenshot.delay(package.id)
return redirect(url_for("admin.admin_page"))
elif action == "restore":
package = Package.query.get(request.form["package"])
if package is None:
@ -91,40 +98,13 @@ def admin_page():
package.soft_deleted = False
db.session.commit()
return redirect(url_for("admin.admin_page"))
elif action == "modprovides":
packages = Package.query.filter_by(type=PackageType.MOD).all()
mpackage_cache = {}
for p in packages:
if len(p.provides) == 0:
p.provides.append(MetaPackage.GetOrCreate(p.name, mpackage_cache))
db.session.commit()
return redirect(url_for("admin.admin_page"))
elif action == "recalcscores":
for p in Package.query.all():
p.recalcScore()
db.session.commit()
return redirect(url_for("admin.admin_page"))
elif action == "vcsrelease":
for package in Package.query.filter(Package.repo.isnot(None)).all():
if package.releases.count() != 0:
continue
rel = PackageRelease()
rel.package = package
rel.title = datetime.date.today().isoformat()
rel.url = ""
rel.task_id = uuid()
rel.approved = True
db.session.add(rel)
db.session.commit()
makeVCSRelease.apply_async((rel.id, "master"), task_id=rel.task_id)
msg = "Release {} created".format(rel.title)
addNotification(package.maintainers, current_user, msg, rel.getEditURL(), package)
db.session.commit()
elif action == "cleanuploads":
upload_dir = app.config['UPLOAD_DIR']

@ -5,48 +5,55 @@
{% endblock %}
{% block content %}
<ul>
<li><a href="{{ url_for('users.list_all') }}">User list</a></li>
<li><a href="{{ url_for('admin.tag_list') }}">Tag Editor</a></li>
<li><a href="{{ url_for('admin.license_list') }}">License Editor</a></li>
<li><a href="{{ url_for('admin.version_list') }}">Version Editor</a></li>
<li><a href="{{ url_for('admin.switch_user') }}">Sign in as another user</a></li>
</ul>
<div class="row">
<div class="col-md-6">
<div class="list-group">
<a class="list-group-item list-group-item-action" href="{{ url_for('users.list_all') }}">User list</a>
<a class="list-group-item list-group-item-action" href="{{ url_for('admin.tag_list') }}">Tag Editor</a>
<a class="list-group-item list-group-item-action" href="{{ url_for('admin.license_list') }}">License Editor</a>
<a class="list-group-item list-group-item-action" href="{{ url_for('admin.version_list') }}">Version Editor</a>
<a class="list-group-item list-group-item-action" href="{{ url_for('admin.switch_user') }}">Sign in as another user</a>
</div>
</div>
<div class="card my-4">
<h2 class="card-header">Do action</h2>
<div class="col-md-6">
<div class="card mb-4">
<h2 class="card-header">Do action</h2>
<form method="post" action="" class="card-body">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<select name="action">
<option value="delstuckreleases" selected>Delete stuck releases</option>
<option value="checkreleases">Validate all Zip releases</option>
<option value="reimportpackages">Reimport meta</option>
<option value="importmodlist">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="cleanuploads">Delete unreachable uploads</option>
<!-- <option value="importdepends">Import dependencies from downloads</option> -->
<!-- <option value="modprovides">Set provides to mod name</option> -->
<!-- <option value="vcsrelease">Create VCS releases</option> -->
</select>
<input type="submit" value="Perform" />
</form>
</div>
<form method="post" action="" class="card-body">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<div class="row px-3">
<select name="action" class="custom-select col">
<option value="delstuckreleases" selected>Delete stuck releases</option>
<option value="checkreleases">Validate all Zip releases</option>
<option value="reimportpackages">Reimport meta</option>
<option value="importmodlist">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="cleanuploads">Delete unreachable uploads</option>
</select>
<input type="submit" value="Perform" class="col-sm-auto btn btn-primary ml-2" />
</div>
</form>
</div>
<div class="card my-4">
<h2 class="card-header">Restore Package</h2>
<div class="card">
<h2 class="card-header">Restore Package</h2>
<form method="post" action="" class="card-body">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input type="hidden" name="action" value="restore" />
<select name="package">
{% for p in deleted_packages %}
<option value={{ p.id }}>{{ p.id}}) {{ p.title }} by {{ p.author.display_name }}</option>
{% endfor %}
</select>
<input type="submit" value="Restore" />
</form>
<form method="post" action="" class="card-body">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input type="hidden" name="action" value="restore" />
<div class="row px-3">
<select name="package" class="custom-select col">
{% for p in deleted_packages %}
<option value={{ p.id }}>{{ p.id}}) {{ p.title }} by {{ p.author.display_name }}</option>
{% endfor %}
</select>
<input type="submit" value="Restore" class="col-sm-auto btn btn-primary ml-2" />
</div>
</form>
</div>
</div>
</div>
{% endblock %}

@ -99,7 +99,7 @@
</p>
{% endif %}
<h2 class="mt-4">Unadded Topic List</h2>
<h2 class="mt-5">Unadded Topic List</h2>
{% if total_topics > 0 %}
<p>