mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-22 22:12:24 +01:00
Add EditRequest creation
This commit is contained in:
parent
269c8c0eb4
commit
dcfd2b0003
@ -73,6 +73,7 @@ class User(db.Model, UserMixin):
|
|||||||
|
|
||||||
# Content
|
# Content
|
||||||
packages = db.relationship("Package", backref="author", lazy="dynamic")
|
packages = db.relationship("Package", backref="author", lazy="dynamic")
|
||||||
|
requests = db.relationship("EditRequest", backref="author", lazy="dynamic")
|
||||||
|
|
||||||
def __init__(self, username):
|
def __init__(self, username):
|
||||||
import datetime
|
import datetime
|
||||||
@ -104,6 +105,19 @@ class PackageType(enum.Enum):
|
|||||||
def coerce(cls, item):
|
def coerce(cls, item):
|
||||||
return item if type(item) == PackageType else PackageType[item]
|
return item if type(item) == PackageType else PackageType[item]
|
||||||
|
|
||||||
|
|
||||||
|
class PackagePropertyKey(enum.Enum):
|
||||||
|
name = "name"
|
||||||
|
title = "title"
|
||||||
|
shortDesc = "shortDesc"
|
||||||
|
desc = "desc"
|
||||||
|
type = "type"
|
||||||
|
repo = "repo"
|
||||||
|
website = "website"
|
||||||
|
issueTracker = "issueTracker"
|
||||||
|
forums = "forums"
|
||||||
|
|
||||||
|
|
||||||
class Package(db.Model):
|
class Package(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
|
||||||
@ -127,6 +141,10 @@ class Package(db.Model):
|
|||||||
releases = db.relationship("PackageRelease", backref="package",
|
releases = db.relationship("PackageRelease", backref="package",
|
||||||
lazy="dynamic", order_by=db.desc("package_release_releaseDate"))
|
lazy="dynamic", order_by=db.desc("package_release_releaseDate"))
|
||||||
|
|
||||||
|
|
||||||
|
requests = db.relationship("EditRequest", backref="package",
|
||||||
|
lazy="dynamic")
|
||||||
|
|
||||||
def getAsDictionary(self, base_url):
|
def getAsDictionary(self, base_url):
|
||||||
return {
|
return {
|
||||||
"name": self.name,
|
"name": self.name,
|
||||||
@ -224,6 +242,37 @@ class PackageRelease(db.Model):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.releaseDate = datetime.now()
|
self.releaseDate = datetime.now()
|
||||||
|
|
||||||
|
class EditRequest(db.Model):
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
|
||||||
|
package_id = db.Column(db.Integer, db.ForeignKey("package.id"))
|
||||||
|
author_id = db.Column(db.Integer, db.ForeignKey("user.id"))
|
||||||
|
|
||||||
|
title = db.Column(db.String(100), nullable=False)
|
||||||
|
desc = db.Column(db.String(1000), nullable=True)
|
||||||
|
|
||||||
|
|
||||||
|
changes = db.relationship("EditRequestChange", backref="request",
|
||||||
|
lazy="dynamic")
|
||||||
|
|
||||||
|
def applyAll(self, package):
|
||||||
|
for change in self.changes:
|
||||||
|
change.apply(package)
|
||||||
|
|
||||||
|
class EditRequestChange(db.Model):
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
|
||||||
|
request_id = db.Column(db.Integer, db.ForeignKey("edit_request.id"))
|
||||||
|
key = db.Column(db.Enum(PackagePropertyKey), nullable=False)
|
||||||
|
|
||||||
|
# TODO: make diff instead
|
||||||
|
oldValue = db.Column(db.Text, nullable=False)
|
||||||
|
newValue = db.Column(db.Text, nullable=False)
|
||||||
|
|
||||||
|
def apply(self, package):
|
||||||
|
prop = PackagePropertyKey[self.key]
|
||||||
|
|
||||||
|
|
||||||
# Setup Flask-User
|
# Setup Flask-User
|
||||||
db_adapter = SQLAlchemyAdapter(db, User) # Register the User model
|
db_adapter = SQLAlchemyAdapter(db, User) # Register the User model
|
||||||
user_manager = UserManager(db_adapter, app) # Initialize Flask-User
|
user_manager = UserManager(db_adapter, app) # Initialize Flask-User
|
||||||
|
29
app/templates/packages/create_editrequest.html
Normal file
29
app/templates/packages/create_editrequest.html
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
{{ package.title or "Create Package" }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% from "macros/forms.html" import render_field, render_submit_field %}
|
||||||
|
<form method="POST" action="">
|
||||||
|
{{ form.hidden_tag() }}
|
||||||
|
|
||||||
|
{{ render_field(form.name) }}
|
||||||
|
{{ render_field(form.title) }}
|
||||||
|
{{ render_field(form.shortDesc) }}
|
||||||
|
{{ render_field(form.desc) }}
|
||||||
|
{{ render_field(form.type) }}
|
||||||
|
{{ render_field(form.repo) }}
|
||||||
|
{{ render_field(form.website) }}
|
||||||
|
{{ render_field(form.issueTracker) }}
|
||||||
|
{{ render_field(form.forums) }}
|
||||||
|
|
||||||
|
<hr />
|
||||||
|
|
||||||
|
{{ render_field(form.edit_title) }}
|
||||||
|
{{ render_field(form.edit_desc) }}
|
||||||
|
{{ render_submit_field(form.submit) }}
|
||||||
|
<input type="submit" value="Go">
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
@ -127,16 +127,16 @@ def package_download_page(type, author, name):
|
|||||||
|
|
||||||
|
|
||||||
class PackageForm(FlaskForm):
|
class PackageForm(FlaskForm):
|
||||||
name = StringField("Name", [InputRequired(), Length(1, 20), Regexp("^[a-z0-9_]", 0, "Lower case letters (a-z), digits (0-9), and underscores (_) only")])
|
name = StringField("Name", [InputRequired(), Length(1, 20), Regexp("^[a-z0-9_]", 0, "Lower case letters (a-z), digits (0-9), and underscores (_) only")])
|
||||||
title = StringField("Title", [InputRequired(), Length(3, 50)])
|
title = StringField("Title", [InputRequired(), Length(3, 50)])
|
||||||
shortDesc = StringField("Short Description", [InputRequired(), Length(1,200)])
|
shortDesc = StringField("Short Description", [InputRequired(), Length(1,200)])
|
||||||
desc = TextAreaField("Long Description", [Optional(), Length(0,10000)])
|
desc = TextAreaField("Long Description", [Optional(), Length(0,10000)])
|
||||||
type = SelectField("Type", [InputRequired()], choices=PackageType.choices(), coerce=PackageType.coerce, default=PackageType.MOD)
|
type = SelectField("Type", [InputRequired()], choices=PackageType.choices(), coerce=PackageType.coerce, default=PackageType.MOD)
|
||||||
repo = StringField("Repo URL", [Optional(), URL()])
|
repo = StringField("Repo URL", [Optional(), URL()])
|
||||||
website = StringField("Website URL", [Optional(), URL()])
|
website = StringField("Website URL", [Optional(), URL()])
|
||||||
issueTracker = StringField("Issue Tracker URL", [Optional(), URL()])
|
issueTracker = StringField("Issue Tracker URL", [Optional(), URL()])
|
||||||
forums = IntegerField("Forum Topic ID", [InputRequired(), NumberRange(0,999999)])
|
forums = IntegerField("Forum Topic ID", [InputRequired(), NumberRange(0,999999)])
|
||||||
submit = SubmitField("Save")
|
submit = SubmitField("Save")
|
||||||
|
|
||||||
@menu.register_menu(app, ".new", "Create", order=21, visible_when=lambda: current_user.is_authenticated)
|
@menu.register_menu(app, ".new", "Create", order=21, visible_when=lambda: current_user.is_authenticated)
|
||||||
@app.route("/new/", methods=["GET", "POST"])
|
@app.route("/new/", methods=["GET", "POST"])
|
||||||
@ -186,20 +186,80 @@ def approve_package_page(type=None, author=None, name=None):
|
|||||||
|
|
||||||
return redirect(package.getDetailsURL())
|
return redirect(package.getDetailsURL())
|
||||||
|
|
||||||
|
|
||||||
|
class EditRequestForm(PackageForm):
|
||||||
|
edit_title = StringField("Edit Title", [InputRequired(), Length(1, 100)])
|
||||||
|
edit_desc = TextField("Edit Description", [Optional()])
|
||||||
|
|
||||||
|
class UnresolvedPackage(Package):
|
||||||
|
edit_title = ""
|
||||||
|
edit_desc = ""
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/<ptype>s/<author>/<name>/requests/new/", methods=["GET","POST"])
|
||||||
|
@login_required
|
||||||
|
def create_editrequest_page(ptype=None, author=None, name=None):
|
||||||
|
package = getPageByInfo(ptype, author, name)
|
||||||
|
|
||||||
|
form = EditRequestForm(request.form, obj=package)
|
||||||
|
if request.method == "POST" and form.validate():
|
||||||
|
editedPackage = UnresolvedPackage()
|
||||||
|
form.populate_obj(editedPackage)
|
||||||
|
|
||||||
|
erequest = EditRequest()
|
||||||
|
erequest.package = package
|
||||||
|
erequest.author = current_user
|
||||||
|
erequest.title = editedPackage.edit_title
|
||||||
|
erequest.desc = editedPackage.edit_desc
|
||||||
|
db.session.add(erequest)
|
||||||
|
|
||||||
|
wasChangeMade = False
|
||||||
|
for e in PackagePropertyKey:
|
||||||
|
newValue = getattr(editedPackage, e.name)
|
||||||
|
|
||||||
|
oldValue = getattr(package, e.name)
|
||||||
|
if newValue == "":
|
||||||
|
newValue = None
|
||||||
|
|
||||||
|
newValueComp = newValue
|
||||||
|
oldValueComp = oldValue
|
||||||
|
if type(newValue) is str:
|
||||||
|
newValue = newValue.replace("\r\n", "\n")
|
||||||
|
newValueComp = newValue.strip()
|
||||||
|
oldValueComp = oldValue.strip()
|
||||||
|
|
||||||
|
if newValueComp != oldValueComp:
|
||||||
|
change = EditRequestChange()
|
||||||
|
change.request = erequest
|
||||||
|
change.key = e
|
||||||
|
change.oldValue = oldValue
|
||||||
|
change.newValue = newValue
|
||||||
|
db.session.add(change)
|
||||||
|
wasChangeMade = True
|
||||||
|
|
||||||
|
if wasChangeMade:
|
||||||
|
db.session.commit()
|
||||||
|
return redirect(package.getDetailsURL())
|
||||||
|
else:
|
||||||
|
flash("No changes detected", "warning")
|
||||||
|
|
||||||
|
return render_template("packages/create_editrequest.html", package=package, form=form)
|
||||||
|
|
||||||
|
|
||||||
class CreatePackageReleaseForm(FlaskForm):
|
class CreatePackageReleaseForm(FlaskForm):
|
||||||
name = StringField("Name")
|
name = StringField("Name")
|
||||||
title = StringField("Title")
|
title = StringField("Title")
|
||||||
uploadOpt = RadioField ("File", choices=[("vcs", "From VCS Commit or Branch"), ("upload", "File Upload")])
|
uploadOpt = RadioField ("File", choices=[("vcs", "From VCS Commit or Branch"), ("upload", "File Upload")])
|
||||||
vcsLabel = StringField("VCS Commit or Branch", default="master")
|
vcsLabel = StringField("VCS Commit or Branch", default="master")
|
||||||
fileUpload = FileField("File Upload")
|
fileUpload = FileField("File Upload")
|
||||||
submit = SubmitField("Save")
|
submit = SubmitField("Save")
|
||||||
|
|
||||||
class EditPackageReleaseForm(FlaskForm):
|
class EditPackageReleaseForm(FlaskForm):
|
||||||
name = StringField("Name")
|
name = StringField("Name")
|
||||||
title = StringField("Title")
|
title = StringField("Title")
|
||||||
url = StringField("URL", [URL])
|
url = StringField("URL", [URL])
|
||||||
approved = BooleanField("Is Approved")
|
approved = BooleanField("Is Approved")
|
||||||
submit = SubmitField("Save")
|
submit = SubmitField("Save")
|
||||||
|
|
||||||
@app.route("/<type>s/<author>/<name>/releases/new/", methods=["GET", "POST"])
|
@app.route("/<type>s/<author>/<name>/releases/new/", methods=["GET", "POST"])
|
||||||
@login_required
|
@login_required
|
||||||
|
Loading…
Reference in New Issue
Block a user