aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2018-05-24 19:02:27 +0100
committerrubenwardy <rw@rubenwardy.com>2018-05-24 19:08:01 +0100
commit746ce990bd5ff156b26a1f30829409b6ff2e02d1 (patch)
treeb0850f9dd4b31589bb3fe1504d43e0eee0531b69
parentb93a6122077eb08547b691c4042abc9ba6a3a3c8 (diff)
downloadcheatdb-746ce990bd5ff156b26a1f30829409b6ff2e02d1.tar.xz
Hide VCS release option when not available
-rw-r--r--app/models.py21
-rw-r--r--app/templates/packages/release_new.html4
-rw-r--r--app/views/packages.py16
3 files changed, 33 insertions, 8 deletions
diff --git a/app/models.py b/app/models.py
index dad0a03..eac8d8f 100644
--- a/app/models.py
+++ b/app/models.py
@@ -18,6 +18,7 @@
from flask import Flask, url_for
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
+from urllib.parse import urlparse
from app import app
from datetime import datetime
from sqlalchemy.orm import validates
@@ -339,6 +340,26 @@ class Package(db.Model):
return None
+ def canImportScreenshot(self):
+ if self.repo is None:
+ return False
+
+ url = urlparse(self.repo)
+ if url.netloc == "github.com":
+ return True
+
+ return False
+
+ def canMakeReleaseFromVCS(self):
+ if self.repo is None:
+ return False
+
+ url = urlparse(self.repo)
+ if url.netloc == "github.com":
+ return True
+
+ return False
+
def checkPerm(self, user, perm):
if not user.is_authenticated:
return False
diff --git a/app/templates/packages/release_new.html b/app/templates/packages/release_new.html
index b21459f..7768483 100644
--- a/app/templates/packages/release_new.html
+++ b/app/templates/packages/release_new.html
@@ -11,7 +11,9 @@
{{ render_field(form.title) }}
{{ render_field(form.uploadOpt) }}
- {{ render_field(form.vcsLabel) }}
+ {% if package.canMakeReleaseFromVCS() %}
+ {{ render_field(form.vcsLabel) }}
+ {% endif %}
{{ render_field(form.fileUpload) }}
{{ render_submit_field(form.submit) }}
</form>
diff --git a/app/views/packages.py b/app/views/packages.py
index 3a5de3a..b28ecfc 100644
--- a/app/views/packages.py
+++ b/app/views/packages.py
@@ -25,7 +25,6 @@ from app.tasks.importtasks import importRepoScreenshot, makeVCSRelease
from app.utils import *
from celery import uuid
-from urllib.parse import urlparse
from flask_wtf import FlaskForm
from wtforms import *
from wtforms.validators import *
@@ -188,11 +187,9 @@ def create_edit_package_page(author=None, name=None):
db.session.commit() # save
- if wasNew:
- url = urlparse(package.repo)
- if url.netloc == "github.com":
- task = importRepoScreenshot.delay(package.id)
- return redirect(url_for("check_task", id=task.id, r=package.getDetailsURL()))
+ if wasNew and package.canImportScreenshot():
+ task = importRepoScreenshot.delay(package.id)
+ return redirect(url_for("check_task", id=task.id, r=package.getDetailsURL()))
return redirect(package.getDetailsURL())
@@ -395,7 +392,7 @@ def reject_editrequest_page(package, id):
class CreatePackageReleaseForm(FlaskForm):
name = StringField("Name")
title = StringField("Title")
- uploadOpt = RadioField ("File", choices=[("vcs", "From VCS Commit or Branch"), ("upload", "File Upload")])
+ uploadOpt = RadioField ("Method", choices=[("upload", "File Upload")], default="upload")
vcsLabel = StringField("VCS Commit or Branch", default="master")
fileUpload = FileField("File Upload")
submit = SubmitField("Save")
@@ -417,6 +414,11 @@ def create_release_page(package):
# Initial form class from post data and default data
form = CreatePackageReleaseForm()
+ if package.canMakeReleaseFromVCS():
+ form["uploadOpt"].choices = [("vcs", "From VCS Commit or Branch"), ("upload", "File Upload")]
+ if request.method != "POST":
+ form["uploadOpt"].data = "vcs"
+
if request.method == "POST" and form.validate():
if form["uploadOpt"].data == "vcs":
rel = PackageRelease()