diff --git a/app/models.py b/app/models.py index 29435350..6a14f943 100644 --- a/app/models.py +++ b/app/models.py @@ -120,6 +120,11 @@ class Package(db.Model): type=self.type.toName(), author=self.author.username, name=self.name) + def getCreateReleaseURL(self): + return url_for("create_release_page", + type=self.type.toName(), + author=self.author.username, name=self.name) + def checkPerm(self, user, perm): if not user.is_authenticated: return False diff --git a/app/templates/package_details.html b/app/templates/package_details.html index 6a1ef352..a2db8759 100644 --- a/app/templates/package_details.html +++ b/app/templates/package_details.html @@ -37,6 +37,9 @@ {% elif current_user.is_authenticated %}
  • Suggest Change
  • {% endif %} + {% if package.checkPerm(current_user, "MAKE_RELEASE") %} +
  • Create Release
  • + {% endif %} diff --git a/app/templates/package_release_new.html b/app/templates/package_release_new.html new file mode 100644 index 00000000..29be43f1 --- /dev/null +++ b/app/templates/package_release_new.html @@ -0,0 +1,19 @@ +{% extends "base.html" %} + +{% block title %} + Create a release | {{ package.title }} +{% endblock %} + +{% block content %} + {% from "macros/forms.html" import render_field, render_submit_field %} +
    + {{ form.hidden_tag() }} + + {{ render_field(form.title) }} + {{ render_field(form.uploadOpt) }} + {{ render_field(form.vcsLabel) }} + {{ render_field(form.fileUpload) }} + {{ render_submit_field(form.submit) }} + +
    +{% endblock %} diff --git a/app/views/packages.py b/app/views/packages.py index d6b6e699..4543503f 100644 --- a/app/views/packages.py +++ b/app/views/packages.py @@ -85,3 +85,35 @@ def edit_package_page(type, author, name): return redirect(package.getDetailsURL()) # redirect return render_template('package_edit.html', package=package, form=form) + + +class PackageReleaseForm(FlaskForm): + name = StringField("Name") + title = StringField("Title") + uploadOpt = RadioField ("File", choices=[("vcs", "From VCS Commit or Branch"), ("upload", "File Upload")]) + vcsLabel = StringField("VCS Commit or Branch", default="master") + fileUpload = FileField("File Upload") + submit = SubmitField('Save') + +@app.route("/s///releases/new/", methods=['GET', 'POST']) +@login_required +def create_release_page(type, author, name): + package = getPageByInfo(type, author, name) + if not package.checkPerm(current_user, Permission.MAKE_RELEASE): + return redirect(package.getDetailsURL()) + + # Initial form class from post data and default data + form = PackageReleaseForm(formdata=request.form) + if request.method == "POST" and form.validate(): + if form["uploadOpt"].data == "vcs": + rel = PackageRelease() + rel.package = package + rel.title = form["title"].data + rel.url = form["vcsLabel"].data + # TODO: get URL to commit from branch name + db.session.commit() + return redirect(package.getDetailsURL()) # redirect + else: + raise Exception("Unimplemented option = file upload") + + return render_template('package_release_new.html', package=package, form=form)