mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-25 15:31:37 +01:00
parent
39ef712817
commit
536da2add2
@ -275,6 +275,7 @@ class Package(db.Model):
|
|||||||
|
|
||||||
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)
|
||||||
title = db.Column(db.String(100), nullable=False)
|
title = db.Column(db.String(100), nullable=False)
|
||||||
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)
|
||||||
@ -284,10 +285,9 @@ class Tag(db.Model):
|
|||||||
self.backgroundColor = backgroundColor
|
self.backgroundColor = backgroundColor
|
||||||
self.textColor = textColor
|
self.textColor = textColor
|
||||||
|
|
||||||
def getName(self):
|
|
||||||
import re
|
import re
|
||||||
regex = re.compile('[^a-z_]')
|
regex = re.compile('[^a-z_]')
|
||||||
return regex.sub("", self.title.lower().replace(" ", "_"))
|
self.name = regex.sub("", self.title.lower().replace(" ", "_"))
|
||||||
|
|
||||||
class PackageRelease(db.Model):
|
class PackageRelease(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
{{ render_field(form.shortDesc) }}
|
{{ render_field(form.shortDesc) }}
|
||||||
{{ render_field(form.desc) }}
|
{{ render_field(form.desc) }}
|
||||||
{{ render_field(form.type) }}
|
{{ render_field(form.type) }}
|
||||||
|
{{ render_field(form.tags) }}
|
||||||
{{ render_field(form.repo) }}
|
{{ render_field(form.repo) }}
|
||||||
{{ render_field(form.website) }}
|
{{ render_field(form.website) }}
|
||||||
{{ render_field(form.issueTracker) }}
|
{{ render_field(form.issueTracker) }}
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<ul>
|
<ul>
|
||||||
{% for t in tags %}
|
{% for t in tags %}
|
||||||
<li><a href="{{ url_for('packages_page', q=(query or '')+' tag:'+t.getName()) }}">
|
<li><a href="{{ url_for('packages_page', q=(query or '')+' tag:'+t.name) }}">
|
||||||
{{ t.title }}
|
{{ t.title }}
|
||||||
</a></li>
|
</a></li>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
@ -9,6 +9,7 @@ from .utils import *
|
|||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from wtforms import *
|
from wtforms import *
|
||||||
from wtforms.validators 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
|
# 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)])
|
shortDesc = StringField("Short Description", [InputRequired(), Length(1,200)])
|
||||||
desc = TextAreaField("Long Description", [Optional(), Length(0,10000)])
|
desc = TextAreaField("Long Description", [Optional(), Length(0,10000)])
|
||||||
type = SelectField("Type", [InputRequired()], choices=PackageType.choices(), coerce=PackageType.coerce, default=PackageType.MOD)
|
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()])
|
repo = StringField("Repo URL", [Optional(), URL()])
|
||||||
website = StringField("Website URL", [Optional(), URL()])
|
website = StringField("Website URL", [Optional(), URL()])
|
||||||
issueTracker = StringField("Issue Tracker 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.author = current_user
|
||||||
# package.approved = package.checkPerm(current_user, Permission.APPROVE_NEW)
|
# 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
|
form.populate_obj(package) # copy to row
|
||||||
db.session.commit() # save
|
db.session.commit() # save
|
||||||
return redirect(package.getDetailsURL()) # redirect
|
return redirect(package.getDetailsURL()) # redirect
|
||||||
|
2
setup.py
2
setup.py
@ -40,7 +40,7 @@ if not os.path.isfile("db.sqlite"):
|
|||||||
"Environment", "Transport", "Maintenance", "Plants and farming", \
|
"Environment", "Transport", "Maintenance", "Plants and farming", \
|
||||||
"PvP", "PvE", "Survival", "Creative", "Puzzle", "Multiplayer", "Singleplayer"]:
|
"PvP", "PvE", "Survival", "Creative", "Puzzle", "Multiplayer", "Singleplayer"]:
|
||||||
row = Tag(tag)
|
row = Tag(tag)
|
||||||
tags[row.getName()] = row
|
tags[row.name] = row
|
||||||
db.session.add(row)
|
db.session.add(row)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user