mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-03 19:57:29 +01:00
Add create release page
This commit is contained in:
parent
596f725d59
commit
d03947462d
@ -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
|
||||
|
@ -37,6 +37,9 @@
|
||||
{% elif current_user.is_authenticated %}
|
||||
<li><a href="">Suggest Change</a></li>
|
||||
{% endif %}
|
||||
{% if package.checkPerm(current_user, "MAKE_RELEASE") %}
|
||||
<li><a href="{{ package.getCreateReleaseURL() }}">Create Release</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</aside>
|
||||
|
||||
|
19
app/templates/package_release_new.html
Normal file
19
app/templates/package_release_new.html
Normal file
@ -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 method="POST" action="">
|
||||
{{ form.hidden_tag() }}
|
||||
|
||||
{{ render_field(form.title) }}
|
||||
{{ render_field(form.uploadOpt) }}
|
||||
{{ render_field(form.vcsLabel) }}
|
||||
{{ render_field(form.fileUpload) }}
|
||||
{{ render_submit_field(form.submit) }}
|
||||
<input type="submit" value="Go">
|
||||
</form>
|
||||
{% endblock %}
|
@ -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("/<type>s/<author>/<name>/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)
|
||||
|
Loading…
Reference in New Issue
Block a user