Add EditRequest view page

This commit is contained in:
rubenwardy 2018-03-23 19:25:48 +00:00
parent dcfd2b0003
commit a5042a986a
5 changed files with 82 additions and 12 deletions

@ -107,15 +107,15 @@ class PackageType(enum.Enum):
class PackagePropertyKey(enum.Enum):
name = "name"
title = "title"
shortDesc = "shortDesc"
desc = "desc"
type = "type"
repo = "repo"
website = "website"
issueTracker = "issueTracker"
forums = "forums"
name = "Name"
title = "Title"
shortDesc = "Short Description"
desc = "Description"
type = "Type"
repo = "Repository"
website = "Website"
issueTracker = "Issue Tracker"
forums = "Forum Topic ID"
class Package(db.Model):
@ -248,17 +248,26 @@ class EditRequest(db.Model):
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)
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 getURL(self):
return url_for("view_editrequest_page",
ptype=self.package.type.toName(),
author=self.package.author.username,
name=self.package.name,
id=self.id)
def applyAll(self, package):
for change in self.changes:
change.apply(package)
class EditRequestChange(db.Model):
id = db.Column(db.Integer, primary_key=True)

@ -0,0 +1,34 @@
{% extends "base.html" %}
{% block title %}
{{ request.title }} - {{ package.title }}
{% endblock %}
{% block content %}
<h1>{{ request.title }} by {{ request.author.display_name }}</h1>
<p>
Package: <a href="{{ package.getDetailsURL() }}">{{ package.title }}</a>
</p>
<p>
{% if request.desc %}
{{ request.desc }}
{% else %}
<i>No description given</i>
{% endif %}
</p>
<table>
<tr>
<th>Property</th>
<th>Old</th>
<th>New</th>
</tr>
{% for change in request.changes %}
<tr>
<td>{{ change.key.value }}</td>
<td>{{ change.oldValue }}</td>
<td>{{ change.newValue }}</td>
</tr>
{% endfor %}
{% endblock %}

@ -86,4 +86,20 @@
<li>No releases available.</li>
{% endfor %}
</ul>
{% if current_user.is_authenticated or package.requests %}
<h3>Edit Requests</h3>
<ul>
{% for r in package.requests %}
<li>
<a href="{{ r.getURL() }}">{{ r.title }}</a>
by
<a href="{{ url_for('user_profile_page', username=r.author.username) }}">{{ r.author.display_name }}</a>
</li>
{% else %}
<li>No edit requests have been made.</li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}

@ -198,7 +198,7 @@ class UnresolvedPackage(Package):
@app.route("/<ptype>s/<author>/<name>/requests/new/", methods=["GET","POST"])
@login_required
def create_editrequest_page(ptype=None, author=None, name=None):
def create_editrequest_page(ptype, author, name):
package = getPageByInfo(ptype, author, name)
form = EditRequestForm(request.form, obj=package)
@ -243,7 +243,18 @@ def create_editrequest_page(ptype=None, author=None, name=None):
else:
flash("No changes detected", "warning")
return render_template("packages/create_editrequest.html", package=package, form=form)
return render_template("packages/editrequest_create.html", package=package, form=form)
@app.route("/<ptype>s/<author>/<name>/requests/<id>/")
def view_editrequest_page(ptype, author, name, id):
package = getPageByInfo(ptype, author, name)
erequest = EditRequest.query.filter_by(id=id).first()
if erequest is None:
abort(404)
return render_template("packages/editrequest_view.html", package=package, request=erequest)
class CreatePackageReleaseForm(FlaskForm):