diff --git a/app/models.py b/app/models.py
index ab88fc6a..0c9b2f27 100644
--- a/app/models.py
+++ b/app/models.py
@@ -275,6 +275,7 @@ class Package(db.Model):
class Tag(db.Model):
id = db.Column(db.Integer, primary_key=True)
+ name = db.Column(db.String(100), unique=True, nullable=False)
title = db.Column(db.String(100), nullable=False)
backgroundColor = db.Column(db.String(6), nullable=False)
textColor = db.Column(db.String(6), nullable=False)
@@ -284,10 +285,9 @@ class Tag(db.Model):
self.backgroundColor = backgroundColor
self.textColor = textColor
- def getName(self):
import re
regex = re.compile('[^a-z_]')
- return regex.sub("", self.title.lower().replace(" ", "_"))
+ self.name = regex.sub("", self.title.lower().replace(" ", "_"))
class PackageRelease(db.Model):
id = db.Column(db.Integer, primary_key=True)
diff --git a/app/templates/packages/create_edit.html b/app/templates/packages/create_edit.html
index 26b4c445..ad8ff6bd 100644
--- a/app/templates/packages/create_edit.html
+++ b/app/templates/packages/create_edit.html
@@ -14,6 +14,7 @@
{{ render_field(form.shortDesc) }}
{{ render_field(form.desc) }}
{{ render_field(form.type) }}
+ {{ render_field(form.tags) }}
{{ render_field(form.repo) }}
{{ render_field(form.website) }}
{{ render_field(form.issueTracker) }}
diff --git a/app/templates/packages/list.html b/app/templates/packages/list.html
index 666e5af8..cd7f7d9f 100644
--- a/app/templates/packages/list.html
+++ b/app/templates/packages/list.html
@@ -26,7 +26,7 @@
{% for t in tags %}
- -
+
-
{{ t.title }}
{% else %}
diff --git a/app/views/packages.py b/app/views/packages.py
index c9ad24ff..dfe7af04 100644
--- a/app/views/packages.py
+++ b/app/views/packages.py
@@ -9,6 +9,7 @@ from .utils import *
from flask_wtf import FlaskForm
from wtforms import *
from wtforms.validators import *
+from wtforms.ext.sqlalchemy.fields import QuerySelectMultipleField
# TODO: the following could be made into one route, except I"m not sure how
@@ -134,6 +135,7 @@ class PackageForm(FlaskForm):
shortDesc = StringField("Short Description", [InputRequired(), Length(1,200)])
desc = TextAreaField("Long Description", [Optional(), Length(0,10000)])
type = SelectField("Type", [InputRequired()], choices=PackageType.choices(), coerce=PackageType.coerce, default=PackageType.MOD)
+ tags = QuerySelectMultipleField('Tags', query_factory=lambda: Tag.query, get_pk=lambda a: a.id, get_label=lambda a: a.title)
repo = StringField("Repo URL", [Optional(), URL()])
website = StringField("Website URL", [Optional(), URL()])
issueTracker = StringField("Issue Tracker URL", [Optional(), URL()])
@@ -164,6 +166,10 @@ def create_edit_package_page(type=None, author=None, name=None):
package.author = current_user
# package.approved = package.checkPerm(current_user, Permission.APPROVE_NEW)
+ package.tags.clear()
+ for tag in form.tags.raw_data:
+ package.tags.append(Tag.query.get(tag))
+
form.populate_obj(package) # copy to row
db.session.commit() # save
return redirect(package.getDetailsURL()) # redirect
diff --git a/setup.py b/setup.py
index 0db122ad..6ad5217c 100644
--- a/setup.py
+++ b/setup.py
@@ -40,7 +40,7 @@ if not os.path.isfile("db.sqlite"):
"Environment", "Transport", "Maintenance", "Plants and farming", \
"PvP", "PvE", "Survival", "Creative", "Puzzle", "Multiplayer", "Singleplayer"]:
row = Tag(tag)
- tags[row.getName()] = row
+ tags[row.name] = row
db.session.add(row)