diff --git a/app/blueprints/admin/tagseditor.py b/app/blueprints/admin/tagseditor.py index 39d69e89..3d351ee2 100644 --- a/app/blueprints/admin/tagseditor.py +++ b/app/blueprints/admin/tagseditor.py @@ -33,9 +33,10 @@ def tag_list(): return render_template("admin/tags/list.html", tags=Tag.query.order_by(db.asc(Tag.title)).all()) class TagForm(FlaskForm): - title = StringField("Title", [InputRequired(), Length(3,100)]) - name = StringField("Name", [Optional(), Length(1, 20), Regexp("^[a-z0-9_]", 0, "Lower case letters (a-z), digits (0-9), and underscores (_) only")]) - submit = SubmitField("Save") + title = StringField("Title", [InputRequired(), Length(3,100)]) + description = TextAreaField("Description", [InputRequired(), Length(0, 500)]) + name = StringField("Name", [Optional(), Length(1, 20), Regexp("^[a-z0-9_]", 0, "Lower case letters (a-z), digits (0-9), and underscores (_) only")]) + submit = SubmitField("Save") @bp.route("/tags/new/", methods=["GET", "POST"]) @bp.route("/tags//edit/", methods=["GET", "POST"]) @@ -54,6 +55,7 @@ def create_edit_tag(name=None): if request.method == "POST" and form.validate(): if tag is None: tag = Tag(form.title.data) + tag.description = form.description.data db.session.add(tag) else: form.populate_obj(tag) diff --git a/app/blueprints/packages/packages.py b/app/blueprints/packages/packages.py index 5a775b2c..3b9ca4af 100644 --- a/app/blueprints/packages/packages.py +++ b/app/blueprints/packages/packages.py @@ -197,6 +197,12 @@ def download(package): return redirect(release.getDownloadURL(), code=302) +def makeLabel(obj): + if obj.description: + return "{}: {}".format(obj.title, obj.description) + else: + return obj.title + class PackageForm(FlaskForm): name = StringField("Name (Technical)", [InputRequired(), Length(1, 100), Regexp("^[a-z0-9_]+$", 0, "Lower case letters (a-z), digits (0-9), and underscores (_) only")]) title = StringField("Title (Human-readable)", [InputRequired(), Length(3, 100)]) @@ -206,8 +212,8 @@ class PackageForm(FlaskForm): license = QuerySelectField("License", [DataRequired()], allow_blank=True, query_factory=lambda: License.query.order_by(db.asc(License.name)), get_pk=lambda a: a.id, get_label=lambda a: a.name) media_license = QuerySelectField("Media License", [DataRequired()], allow_blank=True, query_factory=lambda: License.query.order_by(db.asc(License.name)), get_pk=lambda a: a.id, get_label=lambda a: a.name) provides_str = StringField("Provides (mods included in package)", [Optional()]) - tags = QuerySelectMultipleField('Tags', query_factory=lambda: Tag.query.order_by(db.asc(Tag.name)), get_pk=lambda a: a.id, get_label=lambda a: a.title) - content_warnings = QuerySelectMultipleField('Content Warnings', query_factory=lambda: ContentWarning.query.order_by(db.asc(ContentWarning.name)), get_pk=lambda a: a.id, get_label=lambda a: a.title) + tags = QuerySelectMultipleField('Tags', query_factory=lambda: Tag.query.order_by(db.asc(Tag.name)), get_pk=lambda a: a.id, get_label=makeLabel) + content_warnings = QuerySelectMultipleField('Content Warnings', query_factory=lambda: ContentWarning.query.order_by(db.asc(ContentWarning.name)), get_pk=lambda a: a.id, get_label=makeLabel) harddep_str = StringField("Hard Dependencies", [Optional()]) softdep_str = StringField("Soft Dependencies", [Optional()]) repo = StringField("VCS Repository URL", [Optional(), URL()], filters = [lambda x: x or None]) diff --git a/app/models.py b/app/models.py index b2dbcc04..6b7d0672 100644 --- a/app/models.py +++ b/app/models.py @@ -840,11 +840,11 @@ class ContentWarning(db.Model): self.name = regex.sub("", self.title.lower().replace(" ", "_")) - 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) + description = db.Column(db.String(500), nullable=True, default=None) backgroundColor = db.Column(db.String(6), nullable=False) textColor = db.Column(db.String(6), nullable=False) views = db.Column(db.Integer, nullable=False, default=0) diff --git a/app/public/static/tagselector.js b/app/public/static/tagselector.js index f0994151..566f88a6 100644 --- a/app/public/static/tagselector.js +++ b/app/public/static/tagselector.js @@ -30,6 +30,11 @@ }); function addTag(id, text) { + const idx = text.indexOf(':'); + if (idx > 0) { + text = text.substr(0, idx); + } + $('') .text(text + ' ') .data("id", id) diff --git a/app/templates/admin/tags/edit.html b/app/templates/admin/tags/edit.html index f25312e5..bb8d4625 100644 --- a/app/templates/admin/tags/edit.html +++ b/app/templates/admin/tags/edit.html @@ -17,6 +17,7 @@ {{ form.hidden_tag() }} {{ render_field(form.title) }} + {{ render_field(form.description) }} {% if tag %} {{ render_field(form.name) }} {% endif %} diff --git a/app/templates/admin/tags/list.html b/app/templates/admin/tags/list.html index 8db66ca8..14baf02e 100644 --- a/app/templates/admin/tags/list.html +++ b/app/templates/admin/tags/list.html @@ -14,13 +14,16 @@