Add create links to topic table

This commit is contained in:
rubenwardy 2018-06-05 23:45:15 +01:00
parent 8601c5e075
commit c9542427b4
No known key found for this signature in database
GPG Key ID: A1E29D52FF81513C
6 changed files with 64 additions and 60 deletions

View File

@ -659,6 +659,10 @@ class EditRequestChange(db.Model):
setattr(package, self.key.name, self.newValue)
REPO_BLACKLIST = [".zip", "mediafire.com", "dropbox.com", "weebly.com", \
"minetest.net", "dropboxusercontent.com", "4shared.com", \
"digitalaudioconcepts.com", "hg.intevation.org", "www.wtfpl.net", \
"imageshack.com", "imgur.com"]
class KrockForumTopic(db.Model):
topic_id = db.Column(db.Integer, primary_key=True, autoincrement=False)
@ -676,6 +680,13 @@ class KrockForumTopic(db.Model):
elif self.ttype == 6:
return PackageType.GAME
def getRepoURL(self):
for item in REPO_BLACKLIST:
if item in self.link:
return None
return self.link.replace("repo.or.cz/w/", "repo.or.cz/")
# Setup Flask-User
db_adapter = SQLAlchemyAdapter(db, User) # Register the User model

View File

@ -9,20 +9,11 @@ $(function() {
$(".pkg_meta").show()
}
function repoIsSupported(url) {
// try {
// return URI(url).hostname() == "github.com"
// } catch(e) {
// return false
// }
return true
}
$(".pkg_meta").hide()
$(".pkg_wiz_1").show()
$("#pkg_wiz_1_next").click(function() {
const repoURL = $("#repo").val();
if (repoIsSupported(repoURL)) {
if (repoURL.trim() != "") {
$(".pkg_wiz_1").hide()
$(".pkg_wiz_2").show()
$(".pkg_repo").hide()
@ -36,22 +27,22 @@ $(function() {
}
performTask("/tasks/getmeta/new/?url=" + encodeURI(repoURL)).then(function(result) {
$("#name").val(result.name || "")
setSpecial("#provides_str", result.provides || "")
$("#title").val(result.title || "")
$("#name").val(result.name)
setSpecial("#provides_str", result.provides)
$("#title").val(result.title)
$("#repo").val(result.repo || repoURL)
$("#issueTracker").val(result.issueTracker || "")
$("#desc").val(result.description || "")
$("#shortDesc").val(result.short_description || "")
setSpecial("#harddep_str", result.depends || "")
setSpecial("#softdep_str", result.optional_depends || "")
$("#shortDesc").val(result.short_description || "")
$("#issueTracker").val(result.issueTracker)
$("#desc").val(result.description)
$("#shortDesc").val(result.short_description)
setSpecial("#harddep_str", result.depends)
setSpecial("#softdep_str", result.optional_depends)
$("#shortDesc").val(result.short_description)
if (result.forumId) {
$("#forums").val(result.forumId)
}
if (result.type && result.type.length > 2) {
$("#type").val(result.type);
$("#type").val(result.type)
}
finish()

View File

@ -0,0 +1,26 @@
{% macro render_topictable(topics, show_author=True) -%}
<table>
<tr>
<th>Id</th>
<th>Title</th>
{% if show_author %}<th>Author</th>{% endif %}
<th>Name</th>
<th>Link</th>
<th>Actions</th>
</tr>
{% for topic in topics %}
<tr>
<td>{{ topic.topic_id }}</td>
<td>[{{ topic.getType().value }}] <a href="https://forum.minetest.net/viewtopic.php?t={{ topic.topic_id}}">{{ topic.title }}</a></td>
{% if show_author %}
<td><a href="{{ url_for('user_profile_page', username=topic.author.username) }}">{{ topic.author.display_name}}</a></td>
{% endif %}
<td>{{ topic.name or ""}}</td>
<td><a href="{{ topic.link }}">{{ topic.link | domain }}</a></td>
<td>
<a href="{{ url_for('create_edit_package_page', author=topic.author.username, repo=topic.getRepoURL(), forums=topic.topic_id, title=topic.title) }}">Create</a>
</td>
</tr>
{% endfor %}
</table>
{% endmacro %}

View File

@ -12,23 +12,6 @@ Topics to be Added
{{ topics | count }} remaining.
</p>
<table>
<tr>
<th>Id</th>
<th>Title</th>
<th>Author</th>
<th>Name</th>
<th>Link</th>
</tr>
{% for topic in topics %}
<tr>
<td>{{ topic.topic_id }}</td>
<td>[{{ topic.getType().value }}] <a href="https://forum.minetest.net/viewtopic.php?t={{ topic.topic_id}}">{{ topic.title }}</a></td>
<td><a href="{{ url_for('user_profile_page', username=topic.author.username) }}">{{ topic.author.display_name}}</a></td>
<td>{{ topic.name or ""}}</td>
<td><a href="{{ topic.link }}">{{ topic.link | domain }}</a></td>
</tr>
{% endfor %}
</table>
{% from "macros/topictable.html" import render_topictable %}
{{ render_topictable(topics) }}
{% endblock %}

View File

@ -108,22 +108,10 @@
Powered by Krock's Mod Search.
</p>
<table>
<tr>
<th>Id</th>
<th>Title</th>
<th>Name</th>
<th>Link</th>
</tr>
{% for topic in topics_to_add %}
<tr>
<td>{{ topic.topic_id }}</td>
<td>[{{ topic.getType().value }}] <a href="https://forum.minetest.net/viewtopic.php?t={{ topic.topic_id}}">{{ topic.title }}</a></td>
<td>{{ topic.name or ""}}</td>
<td><a href="{{ topic.link }}">{{ topic.link | domain }}</a></td>
</tr>
{% endfor %}
</table>
{% from "macros/topictable.html" import render_topictable %}
{{ render_topictable(topics_to_add, show_author=False) }}
</div>
</div>
{% endif %}

View File

@ -180,11 +180,16 @@ def create_edit_package_page(author=None, name=None):
form = PackageForm(formdata=request.form, obj=package)
# Initial form class from post data and default data
if request.method == "GET" and package is not None:
deps = package.dependencies
form.harddep_str.data = ",".join([str(x) for x in deps if not x.optional])
form.softdep_str.data = ",".join([str(x) for x in deps if x.optional])
form.provides_str.data = MetaPackage.ListToSpec(package.provides)
if request.method == "GET":
if package is None:
form.repo.data = request.args.get("repo")
form.title.data = request.args.get("title")
form.forums.data = request.args.get("forums")
else:
deps = package.dependencies
form.harddep_str.data = ",".join([str(x) for x in deps if not x.optional])
form.softdep_str.data = ",".join([str(x) for x in deps if x.optional])
form.provides_str.data = MetaPackage.ListToSpec(package.provides)
if request.method == "POST" and form.validate():
wasNew = False