aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models.py19
-rw-r--r--app/templates/package_details.html23
-rw-r--r--app/views/packages.py10
-rw-r--r--setup.py8
4 files changed, 58 insertions, 2 deletions
diff --git a/app/models.py b/app/models.py
index 67adcbf..2943535 100644
--- a/app/models.py
+++ b/app/models.py
@@ -30,6 +30,7 @@ class Permission(enum.Enum):
APPROVE_CHANGES = "APPROVE_CHANGES"
DELETE_PACKAGE = "DELETE_PACKAGE"
CHANGE_AUTHOR = "CHANGE_AUTHOR"
+ MAKE_RELEASE = "MAKE_RELEASE"
APPROVE_RELEASE = "APPROVE_RELEASE"
APPROVE_NEW = "APPROVE_NEW"
@@ -106,6 +107,9 @@ class Package(db.Model):
issueTracker = db.Column(db.String(200), nullable=True)
forums = db.Column(db.String(200), nullable=False)
+ # Releases
+ releases = db.relationship('PackageRelease', backref='package', lazy='dynamic')
+
def getDetailsURL(self):
return url_for("package_page",
type=self.type.toName(),
@@ -128,6 +132,9 @@ class Package(db.Model):
isOwner = user == self.author
# Members can edit their own packages, and editors can edit any packages
+ if perm == Permission.MAKE_RELEASE:
+ return isOwner or user.rank.atLeast(UserRank.EDITOR)
+
if perm == Permission.EDIT_PACKAGE or perm == Permission.APPROVE_CHANGES:
return user.rank.atLeast(UserRank.MEMBER if isOwner else UserRank.EDITOR)
@@ -143,6 +150,18 @@ class Package(db.Model):
else:
raise Exception("Permission {} is not related to packages".format(perm.name))
+class PackageRelease(db.Model):
+ id = db.Column(db.Integer, primary_key=True)
+
+ package_id = db.Column(db.Integer, db.ForeignKey('package.id'))
+ title = db.Column(db.String(100), nullable=False)
+ releaseDate = db.Column(db.Date, nullable=False)
+ url = db.Column(db.String(100), nullable=False)
+ approved = db.Column(db.Boolean, nullable=False, default=False)
+
+ def __init__(self):
+ self.releaseDate = datetime.now()
+
# Setup Flask-User
db_adapter = SQLAlchemyAdapter(db, User) # Register the User model
user_manager = UserManager(db_adapter, app) # Initialize Flask-User
diff --git a/app/templates/package_details.html b/app/templates/package_details.html
index 4f0ff6d..6a1ef35 100644
--- a/app/templates/package_details.html
+++ b/app/templates/package_details.html
@@ -43,4 +43,27 @@
<p class="package-short-large">{{ package.shortDesc }}</p>
{{ package.desc | markdown }}
+
+ <h3>Releases</h3>
+
+ <ul>
+ {% for rel in releases %}
+ <li>
+ {% if not rel.approved %}<i>{% endif %}
+
+ <a href="{{ rel.url }}">{{ rel.title }}</a>,
+ created {{ rel.releaseDate }}.
+ {% if not rel.approved %}
+ Waiting for approval.
+ {% if package.checkPerm(current_user, "APPROVE_RELEASE") %}
+ <a href="">Approve</a>
+ {% endif %}
+ {% endif %}
+
+ {% if not rel.approved %}</i>{% endif %}
+ </li>
+ {% else %}
+ <li>No releases available.</li>
+ {% endfor %}
+ </ul>
{% endblock %}
diff --git a/app/views/packages.py b/app/views/packages.py
index 50c3f88..d6b6e69 100644
--- a/app/views/packages.py
+++ b/app/views/packages.py
@@ -42,11 +42,19 @@ def getPageByInfo(type, author, name):
return package
+def getReleases(package):
+ if package.checkPerm(current_user, Permission.MAKE_RELEASE):
+ return package.releases
+ else:
+ return [rel for rel in package.releases if rel.approved]
+
@app.route("/<type>s/<author>/<name>/")
def package_page(type, author, name):
package = getPageByInfo(type, author, name)
- return render_template('package_details.html', package=package)
+ releases = getReleases(package)
+
+ return render_template('package_details.html', package=package, releases=releases)
class PackageForm(FlaskForm):
diff --git a/setup.py b/setup.py
index a058854..49cd002 100644
--- a/setup.py
+++ b/setup.py
@@ -14,7 +14,7 @@ if not os.path.isfile("db.sqlite"):
ruben = User("rubenwardy")
ruben.github_username = "rubenwardy"
- ruben.rank = UserRank.MEMBER
+ ruben.rank = UserRank.EDITOR
db.session.add(ruben)
jeija = User("Jeija")
@@ -46,6 +46,12 @@ awards.register_achievement("award_mesefind",{
```
"""
+ rel = PackageRelease()
+ rel.package = mod1
+ rel.title = "v1.0.0"
+ rel.url = "https://github.com/rubenwardy/awards/archive/master.zip"
+ db.session.add(rel)
+
mod2 = Package()
mod2.name = "mesecons"
mod2.title = "Mesecons"