mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-23 06:22:24 +01:00
Simplify PackageType
This commit is contained in:
parent
363f9d8016
commit
623ca3da07
@ -9,11 +9,6 @@ import enum
|
|||||||
# Initialise database
|
# Initialise database
|
||||||
db = SQLAlchemy(app)
|
db = SQLAlchemy(app)
|
||||||
|
|
||||||
def title_to_url(title):
|
|
||||||
return title.lower().replace(" ", "_")
|
|
||||||
|
|
||||||
def url_to_title(url):
|
|
||||||
return url.replace("_", " ")
|
|
||||||
|
|
||||||
class UserRank(enum.Enum):
|
class UserRank(enum.Enum):
|
||||||
NOT_JOINED = 0
|
NOT_JOINED = 0
|
||||||
@ -29,6 +24,16 @@ class UserRank(enum.Enum):
|
|||||||
def getTitle(self):
|
def getTitle(self):
|
||||||
return self.name.replace("_", " ").title()
|
return self.name.replace("_", " ").title()
|
||||||
|
|
||||||
|
|
||||||
|
class Permission(enum.Enum):
|
||||||
|
EDIT_PACKAGE = "EDIT_PACKAGE"
|
||||||
|
APPROVE_CHANGES = "APPROVE_CHANGES"
|
||||||
|
DELETE_PACKAGE = "DELETE_PACKAGE"
|
||||||
|
CHANGE_AUTHOR = "CHANGE_AUTHOR"
|
||||||
|
APPROVE_RELEASE = "APPROVE_RELEASE"
|
||||||
|
APPROVE_NEW = "APPROVE_NEW"
|
||||||
|
|
||||||
|
|
||||||
class User(db.Model, UserMixin):
|
class User(db.Model, UserMixin):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
|
||||||
@ -65,32 +70,16 @@ class User(db.Model, UserMixin):
|
|||||||
def isClaimed(self):
|
def isClaimed(self):
|
||||||
return self.password is not None and self.password != ""
|
return self.password is not None and self.password != ""
|
||||||
|
|
||||||
class Permission(enum.Enum):
|
|
||||||
EDIT_PACKAGE = "EDIT_PACKAGE"
|
|
||||||
APPROVE_CHANGES = "APPROVE_CHANGES"
|
|
||||||
DELETE_PACKAGE = "DELETE_PACKAGE"
|
|
||||||
CHANGE_AUTHOR = "CHANGE_AUTHOR"
|
|
||||||
APPROVE_RELEASE = "APPROVE_RELEASE"
|
|
||||||
APPROVE_NEW = "APPROVE_NEW"
|
|
||||||
|
|
||||||
class PackageType(enum.Enum):
|
class PackageType(enum.Enum):
|
||||||
MOD = "Mod"
|
MOD = "Mod"
|
||||||
GAME = "Game"
|
GAME = "Game"
|
||||||
TXP = "Texture Pack"
|
TXP = "Texture Pack"
|
||||||
|
|
||||||
def toName(self):
|
def toName(self):
|
||||||
return self.value.lower().replace(" ", "")
|
return self.name.lower()
|
||||||
|
|
||||||
@staticmethod
|
def __str__(self):
|
||||||
def fromName(name):
|
return self.name
|
||||||
if name == "mod":
|
|
||||||
return PackageType.MOD
|
|
||||||
elif name == "game":
|
|
||||||
return PackageType.GAME
|
|
||||||
elif name == "texturepack":
|
|
||||||
return PackageType.TXP
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def choices(cls):
|
def choices(cls):
|
||||||
@ -98,16 +87,7 @@ class PackageType(enum.Enum):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def coerce(cls, item):
|
def coerce(cls, item):
|
||||||
"""item will be both type(enum) AND type(unicode).
|
return item if type(item) == PackageType else PackageType[item]
|
||||||
"""
|
|
||||||
if item == 'PackageType.MOD' or item == PackageType.MOD:
|
|
||||||
return PackageType.MOD
|
|
||||||
elif item == 'PackageType.GAME' or item == PackageType.GAME:
|
|
||||||
return PackageType.GAME
|
|
||||||
elif item == 'PackageType.TXP' or item == PackageType.TXP:
|
|
||||||
return PackageType.TXP
|
|
||||||
else:
|
|
||||||
print("Can't coerce", item, type(item))
|
|
||||||
|
|
||||||
class Package(db.Model):
|
class Package(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
@ -36,7 +36,7 @@ def getPageByInfo(type, author, name):
|
|||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
package = Package.query.filter_by(name=name, author_id=user.id,
|
package = Package.query.filter_by(name=name, author_id=user.id,
|
||||||
type=PackageType.fromName(type)).first()
|
type=PackageType[type.upper()]).first()
|
||||||
if package is None:
|
if package is None:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user