From c9542427b41d9223508a64225a4e6e64671b1c22 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Tue, 5 Jun 2018 23:45:15 +0100 Subject: [PATCH] Add create links to topic table --- app/models.py | 11 ++++++++ app/public/static/package_create.js | 31 ++++++++-------------- app/templates/macros/topictable.html | 26 ++++++++++++++++++ app/templates/todo/topics.html | 21 ++------------- app/templates/users/user_profile_page.html | 20 +++----------- app/views/packages/__init__.py | 15 +++++++---- 6 files changed, 64 insertions(+), 60 deletions(-) create mode 100644 app/templates/macros/topictable.html diff --git a/app/models.py b/app/models.py index a50c4d0..7f0d8f3 100644 --- a/app/models.py +++ b/app/models.py @@ -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 diff --git a/app/public/static/package_create.js b/app/public/static/package_create.js index 36d1853..86c5140 100644 --- a/app/public/static/package_create.js +++ b/app/public/static/package_create.js @@ -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() diff --git a/app/templates/macros/topictable.html b/app/templates/macros/topictable.html new file mode 100644 index 0000000..43324fa --- /dev/null +++ b/app/templates/macros/topictable.html @@ -0,0 +1,26 @@ +{% macro render_topictable(topics, show_author=True) -%} + + + + + {% if show_author %}{% endif %} + + + + + {% for topic in topics %} + + + + {% if show_author %} + + {% endif %} + + + + + {% endfor %} +
IdTitleAuthorNameLinkActions
{{ topic.topic_id }}[{{ topic.getType().value }}] {{ topic.title }}{{ topic.author.display_name}}{{ topic.name or ""}}{{ topic.link | domain }} + Create +
+{% endmacro %} diff --git a/app/templates/todo/topics.html b/app/templates/todo/topics.html index 77f32c0..f53c4eb 100644 --- a/app/templates/todo/topics.html +++ b/app/templates/todo/topics.html @@ -12,23 +12,6 @@ Topics to be Added {{ topics | count }} remaining.

- - - - - - - - - {% for topic in topics %} - - - - - - - - - {% endfor %} -
IdTitleAuthorNameLink
{{ topic.topic_id }}[{{ topic.getType().value }}] {{ topic.title }}{{ topic.author.display_name}}{{ topic.name or ""}}{{ topic.link | domain }}
+ {% from "macros/topictable.html" import render_topictable %} + {{ render_topictable(topics) }} {% endblock %} diff --git a/app/templates/users/user_profile_page.html b/app/templates/users/user_profile_page.html index 5c5113b..636a610 100644 --- a/app/templates/users/user_profile_page.html +++ b/app/templates/users/user_profile_page.html @@ -108,22 +108,10 @@ Powered by Krock's Mod Search.

- - - - - - - - {% for topic in topics_to_add %} - - - - - - - {% endfor %} -
IdTitleNameLink
{{ topic.topic_id }}[{{ topic.getType().value }}] {{ topic.title }}{{ topic.name or ""}}{{ topic.link | domain }}
+ + + {% from "macros/topictable.html" import render_topictable %} + {{ render_topictable(topics_to_add, show_author=False) }} {% endif %} diff --git a/app/views/packages/__init__.py b/app/views/packages/__init__.py index a486445..a27c468 100644 --- a/app/views/packages/__init__.py +++ b/app/views/packages/__init__.py @@ -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