mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-31 18:27:30 +01:00
Allow null dev_state
This commit is contained in:
parent
122e1a4677
commit
e4ea44aa5b
@ -229,18 +229,13 @@ def makeLabel(obj):
|
||||
return obj.title
|
||||
|
||||
|
||||
def NotNullOption(_form, field):
|
||||
if field.data is None or field.data.name == "__None":
|
||||
raise ValidationError("This field is required")
|
||||
|
||||
|
||||
class PackageForm(FlaskForm):
|
||||
type = SelectField("Type", [InputRequired()], choices=PackageType.choices(), coerce=PackageType.coerce, default=PackageType.MOD)
|
||||
title = StringField("Title (Human-readable)", [InputRequired(), Length(1, 100)])
|
||||
name = StringField("Name (Technical)", [InputRequired(), Length(1, 100), Regexp("^[a-z0-9_]+$", 0, "Lower case letters (a-z), digits (0-9), and underscores (_) only")])
|
||||
short_desc = StringField("Short Description (Plaintext)", [InputRequired(), Length(1,200)])
|
||||
|
||||
dev_state = SelectField("Maintenance State", [InputRequired(), NotNullOption], choices=PackageDevState.choices(with_none=True), coerce=PackageDevState.coerce)
|
||||
dev_state = SelectField("Maintenance State", [InputRequired()], choices=PackageDevState.choices(with_none=True), coerce=PackageDevState.coerce)
|
||||
|
||||
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)
|
||||
|
@ -120,8 +120,6 @@ def do_edit_package(user: User, package: Package, was_new: bool, was_web: bool,
|
||||
|
||||
if "dev_state" in data:
|
||||
data["dev_state"] = PackageDevState.coerce(data["dev_state"])
|
||||
if data["dev_state"] is None:
|
||||
raise LogicError(400, "dev_state cannot be null")
|
||||
|
||||
if "license" in data:
|
||||
data["license"] = get_license(data["license"])
|
||||
|
@ -121,13 +121,13 @@ class PackageDevState(enum.Enum):
|
||||
ret = [(choice, build_label(choice)) for choice in cls]
|
||||
|
||||
if with_none:
|
||||
ret.insert(0, ("__None", ""))
|
||||
ret.insert(0, (None, ""))
|
||||
|
||||
return ret
|
||||
|
||||
@classmethod
|
||||
def coerce(cls, item):
|
||||
if item is None or (isinstance(item, str) and item.upper() == "__NONE"):
|
||||
if item is None or (isinstance(item, str) and item.upper() == "NONE"):
|
||||
return None
|
||||
return item if type(item) == PackageDevState else PackageDevState[item.upper()]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user