Add forum topic validation

This commit is contained in:
rubenwardy 2018-07-07 00:28:27 +01:00
parent 73c65e3561
commit 13837ce88b
No known key found for this signature in database
GPG Key ID: A1E29D52FF81513C
3 changed files with 34 additions and 2 deletions

View File

@ -133,7 +133,7 @@ def parseForumListPage(id, page, out, extra=None):
out[id] = row
return True
return False
def getTopicsFromForum(id, out={}, extra=None):
print("Fetching all topics from forum {}".format(id))

View File

@ -24,6 +24,9 @@
{% elif (package.type == package.type.GAME or package.type == package.type.TXP) and package.screenshots.count() == 0 %}
You need to add at least one screenshot.
{% elif topic_error_lvl == "error" %}
Please fix the below topic issue(s).
{% else %}
{% if package.screenshots.count() == 0 %}
<b>You should add at least one screenshot, but this isn't required.</b><br />
@ -44,6 +47,14 @@
<div style="clear: both;"></div>
</div>
{% if topic_error %}
<div class="box box_grey alert alert-{{ topic_error_lvl }}">
<span class="icon_message"></span>
{{ topic_error | safe }}
<div style="clear: both;"></div>
</div>
{% endif %}
{% if package.author == current_user or package.checkPerm(current_user, "APPROVE_NEW") %}
{% if review_thread %}
<h2>&#x1f512; {{ review_thread.title }}</h2>

View File

@ -116,10 +116,31 @@ def package_page(package):
if review_thread is not None and not review_thread.checkPerm(current_user, Permission.SEE_THREAD):
review_thread = None
topic_error = None
topic_error_lvl = "warning"
if not package.approved and package.forums is not None:
errors = []
if Package.query.filter_by(forums=package.forums, soft_deleted=False).count() > 1:
errors.append("<b>Error: Another package already uses this forum topic!</b>")
topic_error_lvl = "error"
topic = ForumTopic.query.get(package.forums)
if topic is not None:
if topic.author != package.author:
errors.append("<b>Error: Forum topic author doesn't match package author.</b>")
topic_error_lvl = "error"
if topic.wip:
errors.append("Warning: Forum topic is in WIP section, make sure package meets playability standards.")
elif package.type != PackageType.TXP:
errors.append("Warning: Forum topic not found. This may happen if the topic has only just been created.")
topic_error = "<br />".join(errors)
return render_template("packages/view.html", \
package=package, releases=releases, requests=requests, \
alternatives=alternatives, similar_topics=similar_topics, \
review_thread=review_thread)
review_thread=review_thread, topic_error=topic_error, topic_error_lvl=topic_error_lvl)
@app.route("/packages/<author>/<name>/download/")