mirror of
https://github.com/minetest/contentdb.git
synced 2024-11-08 16:43:47 +01:00
Add descriptions to tags, and show in multiselect
This commit is contained in:
parent
b067fd2e77
commit
2a7318eca2
@ -34,6 +34,7 @@ def tag_list():
|
|||||||
|
|
||||||
class TagForm(FlaskForm):
|
class TagForm(FlaskForm):
|
||||||
title = StringField("Title", [InputRequired(), Length(3,100)])
|
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")])
|
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")
|
submit = SubmitField("Save")
|
||||||
|
|
||||||
@ -54,6 +55,7 @@ def create_edit_tag(name=None):
|
|||||||
if request.method == "POST" and form.validate():
|
if request.method == "POST" and form.validate():
|
||||||
if tag is None:
|
if tag is None:
|
||||||
tag = Tag(form.title.data)
|
tag = Tag(form.title.data)
|
||||||
|
tag.description = form.description.data
|
||||||
db.session.add(tag)
|
db.session.add(tag)
|
||||||
else:
|
else:
|
||||||
form.populate_obj(tag)
|
form.populate_obj(tag)
|
||||||
|
@ -197,6 +197,12 @@ def download(package):
|
|||||||
return redirect(release.getDownloadURL(), code=302)
|
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):
|
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")])
|
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)])
|
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)
|
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)
|
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()])
|
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)
|
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=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=makeLabel)
|
||||||
harddep_str = StringField("Hard Dependencies", [Optional()])
|
harddep_str = StringField("Hard Dependencies", [Optional()])
|
||||||
softdep_str = StringField("Soft Dependencies", [Optional()])
|
softdep_str = StringField("Soft Dependencies", [Optional()])
|
||||||
repo = StringField("VCS Repository URL", [Optional(), URL()], filters = [lambda x: x or None])
|
repo = StringField("VCS Repository URL", [Optional(), URL()], filters = [lambda x: x or None])
|
||||||
|
@ -840,11 +840,11 @@ class ContentWarning(db.Model):
|
|||||||
self.name = regex.sub("", self.title.lower().replace(" ", "_"))
|
self.name = regex.sub("", self.title.lower().replace(" ", "_"))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Tag(db.Model):
|
class Tag(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
name = db.Column(db.String(100), unique=True, nullable=False)
|
name = db.Column(db.String(100), unique=True, nullable=False)
|
||||||
title = db.Column(db.String(100), 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)
|
backgroundColor = db.Column(db.String(6), nullable=False)
|
||||||
textColor = db.Column(db.String(6), nullable=False)
|
textColor = db.Column(db.String(6), nullable=False)
|
||||||
views = db.Column(db.Integer, nullable=False, default=0)
|
views = db.Column(db.Integer, nullable=False, default=0)
|
||||||
|
@ -30,6 +30,11 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
function addTag(id, text) {
|
function addTag(id, text) {
|
||||||
|
const idx = text.indexOf(':');
|
||||||
|
if (idx > 0) {
|
||||||
|
text = text.substr(0, idx);
|
||||||
|
}
|
||||||
|
|
||||||
$('<span class="badge badge-pill badge-primary"/>')
|
$('<span class="badge badge-pill badge-primary"/>')
|
||||||
.text(text + ' ')
|
.text(text + ' ')
|
||||||
.data("id", id)
|
.data("id", id)
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
{{ form.hidden_tag() }}
|
{{ form.hidden_tag() }}
|
||||||
|
|
||||||
{{ render_field(form.title) }}
|
{{ render_field(form.title) }}
|
||||||
|
{{ render_field(form.description) }}
|
||||||
{% if tag %}
|
{% if tag %}
|
||||||
{{ render_field(form.name) }}
|
{{ render_field(form.name) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -14,13 +14,16 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="list-group">
|
<div class="list-group">
|
||||||
|
|
||||||
<div class="list-group-item">
|
<div class="list-group-item">
|
||||||
<div class="row text-muted">
|
<div class="row text-muted">
|
||||||
<div class="col-sm">
|
<div class="col-sm-2">
|
||||||
{{ _("Name") }}
|
{{ _("Name") }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="col-sm">
|
||||||
|
{{ _("Description") }}
|
||||||
|
</div>
|
||||||
|
|
||||||
<span class="col-sm-1 text-center">
|
<span class="col-sm-1 text-center">
|
||||||
{{ _("Views") }}
|
{{ _("Views") }}
|
||||||
</span>
|
</span>
|
||||||
@ -35,10 +38,14 @@
|
|||||||
<a class="list-group-item list-group-item-action"
|
<a class="list-group-item list-group-item-action"
|
||||||
href="{{ url_for('admin.create_edit_tag', name=t.name) }}">
|
href="{{ url_for('admin.create_edit_tag', name=t.name) }}">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm">
|
<div class="col-sm-2">
|
||||||
{{ t.title }}
|
{{ t.title }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="col-sm">
|
||||||
|
{{ t.description or "" }}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="col-sm-1 text-center">
|
<div class="col-sm-1 text-center">
|
||||||
{{ t.views }}
|
{{ t.views }}
|
||||||
</div>
|
</div>
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
{% macro form_scripts() -%}
|
{% macro form_scripts() -%}
|
||||||
<link href="/static/jquery-ui.min.css" rel="stylesheet" type="text/css">
|
<link href="/static/jquery-ui.min.css" rel="stylesheet" type="text/css">
|
||||||
<script src="/static/jquery-ui.min.js"></script>
|
<script src="/static/jquery-ui.min.js"></script>
|
||||||
<script src="/static/tagselector.js?v=2"></script>
|
<script src="/static/tagselector.js?v=3"></script>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro package_lists() -%}
|
{% macro package_lists() -%}
|
||||||
|
28
migrations/versions/3a24fc02365e_.py
Normal file
28
migrations/versions/3a24fc02365e_.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: 3a24fc02365e
|
||||||
|
Revises: b370c3eb4227
|
||||||
|
Create Date: 2020-07-17 20:58:31.130449
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '3a24fc02365e'
|
||||||
|
down_revision = 'b370c3eb4227'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.add_column('tag', sa.Column('description', sa.String(length=500), nullable=True, server_default=None))
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_column('tag', 'description')
|
||||||
|
# ### end Alembic commands ###
|
Loading…
Reference in New Issue
Block a user