Hide VCS release option when not available

This commit is contained in:
rubenwardy 2018-05-24 19:02:27 +01:00
parent b93a612207
commit 746ce990bd
No known key found for this signature in database
GPG Key ID: A1E29D52FF81513C
3 changed files with 33 additions and 8 deletions

@ -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

@ -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>

@ -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()