Fix bug with PackageType to name form

This commit is contained in:
rubenwardy 2018-03-20 03:32:14 +00:00
parent 9fc71a5c99
commit 0fae3a6fcd

@ -24,6 +24,9 @@ class UserRank(enum.Enum):
def atLeast(self, min): def atLeast(self, min):
return self.value >= min.value return self.value >= min.value
def getTitle(self):
return self.name.replace("_", " ").title()
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)
@ -71,13 +74,16 @@ class PackageType(enum.Enum):
GAME = "Game" GAME = "Game"
TXP = "Texture Pack" TXP = "Texture Pack"
def toName(self):
return self.value.lower().replace(" ", "")
@staticmethod @staticmethod
def fromName(name): def fromName(name):
if name == "mod": if name == "mod":
return PackageType.MOD return PackageType.MOD
elif name == "game": elif name == "game":
return PackageType.GAME return PackageType.GAME
elif name == "texturepacks": elif name == "texturepack":
return PackageType.TXP return PackageType.TXP
else: else:
return None return None
@ -118,12 +124,12 @@ class Package(db.Model):
def getDetailsURL(self): def getDetailsURL(self):
return url_for("package_page", return url_for("package_page",
type=self.type.value.lower(), type=self.type.toName(),
author=self.author.username, name=self.name) author=self.author.username, name=self.name)
def getEditURL(self): def getEditURL(self):
return url_for("edit_package_page", return url_for("edit_package_page",
type=self.type.value.lower(), type=self.type.toName(),
author=self.author.username, name=self.name) author=self.author.username, name=self.name)
def checkPerm(self, user, perm): def checkPerm(self, user, perm):