diff --git a/app/models.py b/app/models.py
index f3903ff5..ab88fc6a 100644
--- a/app/models.py
+++ b/app/models.py
@@ -147,6 +147,10 @@ class PackagePropertyKey(enum.Enum):
issueTracker = "Issue Tracker"
forums = "Forum Topic ID"
+tags = db.Table('tags',
+ db.Column('tag_id', db.Integer, db.ForeignKey('tag.id'), primary_key=True),
+ db.Column('package_id', db.Integer, db.ForeignKey('package.id'), primary_key=True)
+)
class Package(db.Model):
id = db.Column(db.Integer, primary_key=True)
@@ -167,7 +171,10 @@ class Package(db.Model):
issueTracker = db.Column(db.String(200), nullable=True)
forums = db.Column(db.Integer, nullable=False)
- # Releases
+
+ tags = db.relationship('Tag', secondary=tags, lazy='subquery',
+ backref=db.backref('packages', lazy=True))
+
releases = db.relationship("PackageRelease", backref="package",
lazy="dynamic", order_by=db.desc("package_release_releaseDate"))
@@ -266,6 +273,22 @@ class Package(db.Model):
else:
raise Exception("Permission {} is not related to packages".format(perm.name))
+class Tag(db.Model):
+ id = db.Column(db.Integer, primary_key=True)
+ title = db.Column(db.String(100), nullable=False)
+ backgroundColor = db.Column(db.String(6), nullable=False)
+ textColor = db.Column(db.String(6), nullable=False)
+
+ def __init__(self, title, backgroundColor="000000", textColor="ffffff"):
+ self.title = title
+ self.backgroundColor = backgroundColor
+ self.textColor = textColor
+
+ def getName(self):
+ import re
+ regex = re.compile('[^a-z_]')
+ return regex.sub("", self.title.lower().replace(" ", "_"))
+
class PackageRelease(db.Model):
id = db.Column(db.Integer, primary_key=True)
diff --git a/app/templates/packages/list.html b/app/templates/packages/list.html
index 1c40cfa7..666e5af8 100644
--- a/app/templates/packages/list.html
+++ b/app/templates/packages/list.html
@@ -19,4 +19,18 @@
No packages available
{% endfor %}
+
+ Tags
+
+ Filtering by tag doesn't actually work yet!
+
+
+ {% endfor %}
+
{% endblock %}
diff --git a/app/templates/packages/view.html b/app/templates/packages/view.html
index 58631c99..55d0d574 100644
--- a/app/templates/packages/view.html
+++ b/app/templates/packages/view.html
@@ -98,6 +98,15 @@
{% endfor %}
+ Tags
+
+ {% for t in package.tags %}
+ - {{ t.title }}
+ {% else %}
+ - No tags.
+ {% endfor %}
+
+
{% if current_user.is_authenticated or requests %}
Edit Requests
diff --git a/app/views/packages.py b/app/views/packages.py
index 6f809f26..c9ad24ff 100644
--- a/app/views/packages.py
+++ b/app/views/packages.py
@@ -29,7 +29,8 @@ def doPackageList(type):
if shouldReturnJson():
return jsonify([package.getAsDictionary(app.config["BASE_URL"]) for package in query.all()])
else:
- return render_template("packages/list.html", title=title, packages=query.all(), query=search)
+ tags = Tag.query.all()
+ return render_template("packages/list.html", title=title, packages=query.all(), query=search, tags=tags)
@app.route("/packages/")
diff --git a/setup.py b/setup.py
index a6a5568f..e5a4240a 100644
--- a/setup.py
+++ b/setup.py
@@ -34,12 +34,23 @@ if not os.path.isfile("db.sqlite"):
sam.rank = UserRank.EDITOR
db.session.add(sam)
+ tags = {}
+ for tag in ["Inventory", "Mapgen", "Building", \
+ "Animals, monsters and NPCs", "Tools", "Player effects", \
+ "Environment", "Transport", "Maintenance", "Plants and farming", \
+ "Player vs Player", "Survival", "Creative", "Puzzle", "Multiplayer focused"]:
+ row = Tag(tag)
+ tags[row.getName()] = row
+ db.session.add(row)
+
+
mod1 = Package()
mod1.approved = True
mod1.name = "awards"
mod1.title = "Awards"
mod1.type = PackageType.MOD
mod1.author = ruben
+ mod1.tags.append(tags["player_effects"])
mod1.repo = "https://github.com/rubenwardy/awards"
mod1.issueTracker = "https://github.com/rubenwardy/awards/issues"
mod1.forums = 4870
@@ -70,6 +81,7 @@ awards.register_achievement("award_mesefind",{
mod2.approved = True
mod2.name = "mesecons"
mod2.title = "Mesecons"
+ mod2.tags.append(tags["tools"])
mod2.type = PackageType.MOD
mod2.author = jeija
mod2.repo = "https://github.com/minetest-mods/mesecons/"
@@ -169,6 +181,9 @@ No warranty is provided, express or implied, for any part of the project.
game1.title = "Capture The Flag"
game1.type = PackageType.GAME
game1.author = ruben
+ game1.tags.append(tags["player_vs_player"])
+ game1.tags.append(tags["survival"])
+ game1.tags.append(tags["multiplayer_focused"])
game1.repo = "https://github.com/rubenwardy/capturetheflag"
game1.issueTracker = "https://github.com/rubenwardy/capturetheflag/issues"
game1.forums = 12835
@@ -182,7 +197,6 @@ Uses the CTF PvP Engine.
db.session.add(game1)
-
db.session.commit()
else:
print("Database already exists")