mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-08 22:17:34 +01:00
Add dependency support
This commit is contained in:
parent
47432ea7e4
commit
acad90c312
@ -218,13 +218,23 @@ class PackagePropertyKey(enum.Enum):
|
||||
|
||||
def convert(self, value):
|
||||
if self == PackagePropertyKey.tags:
|
||||
return ','.join([t.title for t in value])
|
||||
return ",".join([t.title for t in value])
|
||||
else:
|
||||
return str(value)
|
||||
|
||||
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)
|
||||
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)
|
||||
)
|
||||
|
||||
harddeps = db.Table("harddeps",
|
||||
db.Column("package_id", db.Integer, db.ForeignKey("package.id"), primary_key=True),
|
||||
db.Column("dependency_id", db.Integer, db.ForeignKey("package.id"), primary_key=True)
|
||||
)
|
||||
|
||||
softdeps = db.Table("softdeps",
|
||||
db.Column("package_id", db.Integer, db.ForeignKey("package.id"), primary_key=True),
|
||||
db.Column("dependency_id", db.Integer, db.ForeignKey("package.id"), primary_key=True)
|
||||
)
|
||||
|
||||
class Package(db.Model):
|
||||
@ -248,9 +258,20 @@ class Package(db.Model):
|
||||
issueTracker = db.Column(db.String(200), nullable=True)
|
||||
forums = db.Column(db.Integer, nullable=False)
|
||||
|
||||
tags = db.relationship("Tag", secondary=tags, lazy="subquery",
|
||||
backref=db.backref("packages", lazy=True))
|
||||
|
||||
tags = db.relationship('Tag', secondary=tags, lazy='subquery',
|
||||
backref=db.backref('packages', lazy=True))
|
||||
harddeps = db.relationship("Package",
|
||||
secondary=harddeps,
|
||||
primaryjoin=id==harddeps.c.package_id,
|
||||
secondaryjoin=id==harddeps.c.dependency_id,
|
||||
backref="dependents")
|
||||
|
||||
softdeps = db.relationship("Package",
|
||||
secondary=softdeps,
|
||||
primaryjoin=id==softdeps.c.package_id,
|
||||
secondaryjoin=id==softdeps.c.dependency_id,
|
||||
backref="softdependents")
|
||||
|
||||
releases = db.relationship("PackageRelease", backref="package",
|
||||
lazy="dynamic", order_by=db.desc("package_release_releaseDate"))
|
||||
@ -357,7 +378,7 @@ class Tag(db.Model):
|
||||
self.textColor = textColor
|
||||
|
||||
import re
|
||||
regex = re.compile('[^a-z_]')
|
||||
regex = re.compile("[^a-z_]")
|
||||
self.name = regex.sub("", self.title.lower().replace(" ", "_"))
|
||||
|
||||
class PackageRelease(db.Model):
|
||||
|
@ -374,3 +374,7 @@ table.fancyTable tfoot td {
|
||||
background: #444;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.table-topalign td {
|
||||
vertical-align: top;
|
||||
}
|
||||
|
@ -21,6 +21,8 @@
|
||||
{{ render_field(form.type, class_="pkg_meta") }}
|
||||
{{ render_field(form.license, class_="pkg_meta") }}
|
||||
{{ render_field(form.tags, class_="pkg_meta") }}
|
||||
{{ render_field(form.harddeps, class_="pkg_meta") }}
|
||||
{{ render_field(form.softdeps, class_="pkg_meta") }}
|
||||
|
||||
<div class="pkg_wiz_1">
|
||||
<p>Enter the repo URL for the package.
|
||||
|
@ -118,6 +118,41 @@
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
<table class="table-topalign">
|
||||
<tr>
|
||||
<td>
|
||||
<h3>Dependencies</h3>
|
||||
<ul>
|
||||
{% for p in package.harddeps %}
|
||||
<li><a href="{{ p.getDetailsURL() }}">{{ p.title }}</a> by {{ p.author.display_name }}</li>
|
||||
{% else %}
|
||||
{% if not package.softdeps %}
|
||||
<li>No dependencies.</li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% for p in package.softdeps %}
|
||||
<li><a href="{{ p.getDetailsURL() }}">{{ p.title }}</a> by {{ p.author.display_name }} [optional]</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</td>
|
||||
<td>
|
||||
<h3>Required by</h3>
|
||||
<ul>
|
||||
{% for p in package.dependents %}
|
||||
<li><a href="{{ p.getDetailsURL() }}">{{ p.title }}</a> by {{ p.author.display_name }}</li>
|
||||
{% else %}
|
||||
{% if not package.softdependents %}
|
||||
<li>No dependents.</li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% for p in package.softdependents %}
|
||||
<li><a href="{{ p.getDetailsURL() }}">{{ p.title }}</a> by {{ p.author.display_name }} [optional]</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
{% if current_user.is_authenticated or requests %}
|
||||
<h3>Edit Requests</h3>
|
||||
|
||||
|
@ -118,18 +118,20 @@ def package_download_page(package):
|
||||
|
||||
|
||||
class PackageForm(FlaskForm):
|
||||
name = StringField("Name", [InputRequired(), Length(1, 20), Regexp("^[a-z0-9_]", 0, "Lower case letters (a-z), digits (0-9), and underscores (_) only")])
|
||||
title = StringField("Title", [InputRequired(), Length(3, 50)])
|
||||
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)
|
||||
license = QuerySelectField("License", [InputRequired()], query_factory=lambda: License.query, get_pk=lambda a: a.id, get_label=lambda a: a.name)
|
||||
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()])
|
||||
forums = IntegerField("Forum Topic ID", [InputRequired(), NumberRange(0,999999)])
|
||||
submit = SubmitField("Save")
|
||||
name = StringField("Name", [InputRequired(), Length(1, 20), Regexp("^[a-z0-9_]", 0, "Lower case letters (a-z), digits (0-9), and underscores (_) only")])
|
||||
title = StringField("Title", [InputRequired(), Length(3, 50)])
|
||||
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)
|
||||
license = QuerySelectField("License", [InputRequired()], query_factory=lambda: License.query, get_pk=lambda a: a.id, get_label=lambda a: a.name)
|
||||
tags = QuerySelectMultipleField('Tags', query_factory=lambda: Tag.query, get_pk=lambda a: a.id, get_label=lambda a: a.title)
|
||||
harddeps = QuerySelectMultipleField('Dependencies', query_factory=lambda: Package.query, get_pk=lambda a: a.id, get_label=lambda a: a.title + " by " + a.author.display_name)
|
||||
softdeps = QuerySelectMultipleField('Soft Dependencies', query_factory=lambda: Package.query, get_pk=lambda a: a.id, get_label=lambda a: a.title + " by " + a.author.display_name)
|
||||
repo = StringField("Repo URL", [Optional(), URL()])
|
||||
website = StringField("Website URL", [Optional(), URL()])
|
||||
issueTracker = StringField("Issue Tracker URL", [Optional(), URL()])
|
||||
forums = IntegerField("Forum Topic ID", [InputRequired(), NumberRange(0,999999)])
|
||||
submit = SubmitField("Save")
|
||||
|
||||
@app.route("/packages/new/", methods=["GET", "POST"])
|
||||
@app.route("/packages/<author>/<name>/edit/", methods=["GET", "POST"])
|
||||
|
9
setup.py
9
setup.py
@ -52,11 +52,6 @@ if not os.path.isfile("db.sqlite"):
|
||||
jeija.github_username = "Jeija"
|
||||
db.session.add(jeija)
|
||||
|
||||
sam = User("fillthisinlater")
|
||||
sam.github_username = "fillthisinlater"
|
||||
sam.rank = UserRank.EDITOR
|
||||
db.session.add(sam)
|
||||
|
||||
tags = {}
|
||||
for tag in ["Inventory", "Mapgen", "Building", \
|
||||
"Mobs and NPCs", "Tools", "Player effects", \
|
||||
@ -235,7 +230,7 @@ No warranty is provided, express or implied, for any part of the project.
|
||||
mod = Package()
|
||||
mod.approved = True
|
||||
mod.name = "handholds"
|
||||
mod.title = "Mountain Climbing"
|
||||
mod.title = "Handholds"
|
||||
mod.license = licenses["MIT"]
|
||||
mod.type = PackageType.MOD
|
||||
mod.author = ez
|
||||
@ -283,6 +278,7 @@ No warranty is provided, express or implied, for any part of the project.
|
||||
mod.forums = 2960
|
||||
mod.shortDesc = "Adds lots of food and an API to manage ingredients"
|
||||
mod.desc = "This is the long desc"
|
||||
food = mod
|
||||
db.session.add(mod)
|
||||
|
||||
mod = Package()
|
||||
@ -291,6 +287,7 @@ No warranty is provided, express or implied, for any part of the project.
|
||||
mod.title = "Sweet Foods"
|
||||
mod.license = licenses["CC0"]
|
||||
mod.type = PackageType.MOD
|
||||
mod.harddeps.append(food)
|
||||
mod.author = ruben
|
||||
mod.tags.append(tags["player_effects"])
|
||||
mod.repo = "https://github.com/rubenwardy/food_sweet/"
|
||||
|
Loading…
Reference in New Issue
Block a user