diff --git a/app/models.py b/app/models.py index dad0a03c..eac8d8f4 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 b21459f2..77684837 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) }} diff --git a/app/views/packages.py b/app/views/packages.py index 3a5de3a7..b28ecfcb 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()