mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-08 22:17:34 +01:00
Add package licenses
This commit is contained in:
parent
743d1d909f
commit
5f2a399260
@ -116,6 +116,18 @@ class User(db.Model, UserMixin):
|
||||
else:
|
||||
raise Exception("Permission {} is not related to users".format(perm.name))
|
||||
|
||||
class License(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(50), nullable=False, unique=True)
|
||||
packages = db.relationship("Package", backref="license", lazy="dynamic")
|
||||
|
||||
def __init__(self, v):
|
||||
self.name = v
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class PackageType(enum.Enum):
|
||||
MOD = "Mod"
|
||||
GAME = "Game"
|
||||
@ -142,6 +154,7 @@ class PackagePropertyKey(enum.Enum):
|
||||
shortDesc = "Short Description"
|
||||
desc = "Description"
|
||||
type = "Type"
|
||||
license = "License"
|
||||
tags = "Tags"
|
||||
repo = "Repository"
|
||||
website = "Website"
|
||||
@ -170,6 +183,8 @@ class Package(db.Model):
|
||||
desc = db.Column(db.Text, nullable=True)
|
||||
type = db.Column(db.Enum(PackageType))
|
||||
|
||||
license_id = db.Column(db.Integer, db.ForeignKey("license.id"))
|
||||
|
||||
approved = db.Column(db.Boolean, nullable=False, default=False)
|
||||
|
||||
# Downloads
|
||||
@ -198,6 +213,7 @@ class Package(db.Model):
|
||||
"author": self.author.display_name,
|
||||
"shortDesc": self.shortDesc,
|
||||
"type": self.type.toName(),
|
||||
"license": self.license.name,
|
||||
"repo": self.repo,
|
||||
"url": base_url + self.getDownloadURL(),
|
||||
"screenshots": [base_url + ss.url for ss in self.screenshots]
|
||||
|
@ -14,6 +14,7 @@
|
||||
{{ render_field(form.shortDesc) }}
|
||||
{{ render_field(form.desc) }}
|
||||
{{ render_field(form.type) }}
|
||||
{{ render_field(form.license) }}
|
||||
{{ render_field(form.tags) }}
|
||||
{{ render_field(form.repo) }}
|
||||
{{ render_field(form.website) }}
|
||||
|
@ -14,6 +14,7 @@
|
||||
{{ render_field(form.shortDesc) }}
|
||||
{{ render_field(form.desc) }}
|
||||
{{ render_field(form.type) }}
|
||||
{{ render_field(form.license) }}
|
||||
{{ render_field(form.tags) }}
|
||||
{{ render_field(form.repo) }}
|
||||
{{ render_field(form.website) }}
|
||||
|
@ -46,6 +46,10 @@
|
||||
<td>Type</td>
|
||||
<td>{{ package.type.value }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>License</td>
|
||||
<td>{{ package.license.name }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<ul class="buttonset linedbuttonset">
|
||||
|
@ -9,7 +9,7 @@ from .utils import *
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import *
|
||||
from wtforms.validators import *
|
||||
from wtforms.ext.sqlalchemy.fields import QuerySelectMultipleField
|
||||
from wtforms.ext.sqlalchemy.fields import QuerySelectField, QuerySelectMultipleField
|
||||
|
||||
|
||||
# TODO: the following could be made into one route, except I"m not sure how
|
||||
@ -135,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)
|
||||
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()])
|
||||
@ -227,11 +228,6 @@ class EditRequestForm(PackageForm):
|
||||
edit_title = StringField("Edit Title", [InputRequired(), Length(1, 100)])
|
||||
edit_desc = TextField("Edit Description", [Optional()])
|
||||
|
||||
class UnresolvedPackage(Package):
|
||||
edit_title = ""
|
||||
edit_desc = ""
|
||||
|
||||
|
||||
@app.route("/<ptype>s/<author>/<name>/requests/new/", methods=["GET","POST"])
|
||||
@login_required
|
||||
def create_editrequest_page(ptype, author, name):
|
||||
@ -239,19 +235,16 @@ def create_editrequest_page(ptype, author, name):
|
||||
|
||||
form = EditRequestForm(request.form, obj=package)
|
||||
if request.method == "POST" and form.validate():
|
||||
editedPackage = UnresolvedPackage()
|
||||
form.populate_obj(editedPackage)
|
||||
|
||||
erequest = EditRequest()
|
||||
erequest.package = package
|
||||
erequest.author = current_user
|
||||
erequest.title = editedPackage.edit_title
|
||||
erequest.desc = editedPackage.edit_desc
|
||||
erequest.title = form["edit_title"].data
|
||||
erequest.desc = form["edit_desc"].data
|
||||
db.session.add(erequest)
|
||||
|
||||
wasChangeMade = False
|
||||
for e in PackagePropertyKey:
|
||||
newValue = getattr(editedPackage, e.name)
|
||||
newValue = form[e.name].data
|
||||
oldValue = getattr(package, e.name)
|
||||
|
||||
newValueComp = newValue
|
||||
|
11
setup.py
11
setup.py
@ -44,10 +44,19 @@ if not os.path.isfile("db.sqlite"):
|
||||
db.session.add(row)
|
||||
|
||||
|
||||
|
||||
licenses = {}
|
||||
for license in ["LGPLv2.1", "LGPLv3", "GPLv2.1", "GPLv3", "AGPLv2.1", "AGPLv3",
|
||||
"MIT", "Apache", "BSD", "ZLib", "CC0", "CC-BY-SA", "CC-BY", "CC-BY-NC-SA"]:
|
||||
row = License(license)
|
||||
licenses[row.name] = row
|
||||
db.session.add(row)
|
||||
|
||||
mod1 = Package()
|
||||
mod1.approved = True
|
||||
mod1.name = "awards"
|
||||
mod1.title = "Awards"
|
||||
mod1.license = licenses["LGPLv2.1"]
|
||||
mod1.type = PackageType.MOD
|
||||
mod1.author = ruben
|
||||
mod1.tags.append(tags["player_effects"])
|
||||
@ -83,6 +92,7 @@ awards.register_achievement("award_mesefind",{
|
||||
mod2.title = "Mesecons"
|
||||
mod2.tags.append(tags["tools"])
|
||||
mod2.type = PackageType.MOD
|
||||
mod2.license = licenses["LGPLv3"]
|
||||
mod2.author = jeija
|
||||
mod2.repo = "https://github.com/minetest-mods/mesecons/"
|
||||
mod2.issueTracker = "https://github.com/minetest-mods/mesecons/issues"
|
||||
@ -180,6 +190,7 @@ No warranty is provided, express or implied, for any part of the project.
|
||||
game1.name = "capturetheflag"
|
||||
game1.title = "Capture The Flag"
|
||||
game1.type = PackageType.GAME
|
||||
game1.license = licenses["LGPLv2.1"]
|
||||
game1.author = ruben
|
||||
game1.tags.append(tags["pvp"])
|
||||
game1.tags.append(tags["survival"])
|
||||
|
Loading…
Reference in New Issue
Block a user