mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-09 22:47:36 +01:00
Add support for getting MinetestRelease using engine_version
This commit is contained in:
parent
720457e876
commit
14cf3912f0
@ -531,9 +531,9 @@ class Package(db.Model):
|
|||||||
"type": self.type.toName(),
|
"type": self.type.toName(),
|
||||||
}
|
}
|
||||||
|
|
||||||
def getAsDictionaryShort(self, base_url, version=None, protonum=None):
|
def getAsDictionaryShort(self, base_url, version=None):
|
||||||
tnurl = self.getThumbnailURL(1)
|
tnurl = self.getThumbnailURL(1)
|
||||||
release = self.getDownloadRelease(version=version, protonum=protonum)
|
release = self.getDownloadRelease(version=version)
|
||||||
return {
|
return {
|
||||||
"name": self.name,
|
"name": self.name,
|
||||||
"title": self.title,
|
"title": self.title,
|
||||||
@ -544,9 +544,9 @@ class Package(db.Model):
|
|||||||
"thumbnail": (base_url + tnurl) if tnurl is not None else None
|
"thumbnail": (base_url + tnurl) if tnurl is not None else None
|
||||||
}
|
}
|
||||||
|
|
||||||
def getAsDictionary(self, base_url, version=None, protonum=None):
|
def getAsDictionary(self, base_url, version=None):
|
||||||
tnurl = self.getThumbnailURL(1)
|
tnurl = self.getThumbnailURL(1)
|
||||||
release = self.getDownloadRelease(version=version, protonum=protonum)
|
release = self.getDownloadRelease(version=version)
|
||||||
return {
|
return {
|
||||||
"author": self.author.username,
|
"author": self.author.username,
|
||||||
"name": self.name,
|
"name": self.name,
|
||||||
@ -630,19 +630,11 @@ class Package(db.Model):
|
|||||||
return url_for("packages.download",
|
return url_for("packages.download",
|
||||||
author=self.author.username, name=self.name)
|
author=self.author.username, name=self.name)
|
||||||
|
|
||||||
def getDownloadRelease(self, version=None, protonum=None):
|
def getDownloadRelease(self, version=None):
|
||||||
if version is None and protonum is not None:
|
|
||||||
version = MinetestRelease.query.filter(MinetestRelease.protocol >= int(protonum)).first()
|
|
||||||
if version is not None:
|
|
||||||
version = version.id
|
|
||||||
else:
|
|
||||||
version = 10000000
|
|
||||||
|
|
||||||
|
|
||||||
for rel in self.releases:
|
for rel in self.releases:
|
||||||
if rel.approved and (version is None or
|
if rel.approved and (version is None or
|
||||||
((rel.min_rel is None or rel.min_rel_id <= version) and \
|
((rel.min_rel is None or rel.min_rel_id <= version.id) and \
|
||||||
(rel.max_rel is None or rel.max_rel_id >= version))):
|
(rel.max_rel is None or rel.max_rel_id >= version.id))):
|
||||||
return rel
|
return rel
|
||||||
|
|
||||||
return None
|
return None
|
||||||
@ -795,6 +787,28 @@ class MinetestRelease(db.Model):
|
|||||||
def getActual(self):
|
def getActual(self):
|
||||||
return None if self.name == "None" else self
|
return None if self.name == "None" else self
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get(cls, version, protocol_num):
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if version:
|
||||||
|
parts = version.split(".")
|
||||||
|
if len(parts) >= 2:
|
||||||
|
major_minor = parts[0] + "." + parts[1]
|
||||||
|
query = MinetestRelease.query.filter(MinetestRelease.name.like("%{}%".format(major_minor)))
|
||||||
|
if protocol_num:
|
||||||
|
query = query.filter_by(protocol=protocol_num)
|
||||||
|
|
||||||
|
release = query.one_or_none()
|
||||||
|
if release:
|
||||||
|
return release
|
||||||
|
|
||||||
|
if protocol_num:
|
||||||
|
release = MinetestRelease.query.filter_by(protocol=protocol_num).one_or_none()
|
||||||
|
return release
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class PackageRelease(db.Model):
|
class PackageRelease(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
@ -42,7 +42,8 @@ class QueryBuilder:
|
|||||||
# Filters
|
# Filters
|
||||||
|
|
||||||
self.search = args.get("q")
|
self.search = args.get("q")
|
||||||
self.protocol_version = args.get("protocol_version")
|
self.minetest_version = args.get("engine_version")
|
||||||
|
self.protocol_version = get_int_or_abort(args.get("protocol_version"))
|
||||||
self.author = args.get("author")
|
self.author = args.get("author")
|
||||||
|
|
||||||
self.show_discarded = isYes(args.get("show_discarded"))
|
self.show_discarded = isYes(args.get("show_discarded"))
|
||||||
@ -58,15 +59,10 @@ class QueryBuilder:
|
|||||||
self.order_by = name
|
self.order_by = name
|
||||||
|
|
||||||
def getMinetestVersion(self):
|
def getMinetestVersion(self):
|
||||||
if not self.protocol_version:
|
if not self.protocol_version and not self.minetest_version:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
self.protocol_version = get_int_or_abort(self.protocol_version)
|
return MinetestRelease.get(self.minetest_version, self.protocol_version)
|
||||||
version = MinetestRelease.query.filter(MinetestRelease.protocol>=self.protocol_version).first()
|
|
||||||
if version is not None:
|
|
||||||
return version.id
|
|
||||||
else:
|
|
||||||
return 10000000
|
|
||||||
|
|
||||||
def buildPackageQuery(self):
|
def buildPackageQuery(self):
|
||||||
query = Package.query.filter_by(soft_deleted=False, approved=True)
|
query = Package.query.filter_by(soft_deleted=False, approved=True)
|
||||||
@ -111,12 +107,13 @@ class QueryBuilder:
|
|||||||
query = query.filter(Package.license.has(License.is_foss == True))
|
query = query.filter(Package.license.has(License.is_foss == True))
|
||||||
query = query.filter(Package.media_license.has(License.is_foss == True))
|
query = query.filter(Package.media_license.has(License.is_foss == True))
|
||||||
|
|
||||||
if self.protocol_version:
|
if self.protocol_version or self.minetest_version:
|
||||||
version = self.getMinetestVersion()
|
version = self.getMinetestVersion()
|
||||||
query = query.join(Package.releases) \
|
if version:
|
||||||
.filter(PackageRelease.approved==True) \
|
query = query.join(Package.releases) \
|
||||||
.filter(or_(PackageRelease.min_rel_id==None, PackageRelease.min_rel_id<=version)) \
|
.filter(PackageRelease.approved==True) \
|
||||||
.filter(or_(PackageRelease.max_rel_id==None, PackageRelease.max_rel_id>=version))
|
.filter(or_(PackageRelease.min_rel_id==None, PackageRelease.min_rel_id<=version.id)) \
|
||||||
|
.filter(or_(PackageRelease.max_rel_id==None, PackageRelease.max_rel_id>=version.id))
|
||||||
|
|
||||||
if self.limit:
|
if self.limit:
|
||||||
query = query.limit(self.limit)
|
query = query.limit(self.limit)
|
||||||
|
@ -31,6 +31,9 @@ def abs_url(path):
|
|||||||
return urljoin(app.config["BASE_URL"], path)
|
return urljoin(app.config["BASE_URL"], path)
|
||||||
|
|
||||||
def get_int_or_abort(v, default=None):
|
def get_int_or_abort(v, default=None):
|
||||||
|
if v is None:
|
||||||
|
return default
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return int(v or default)
|
return int(v or default)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
Loading…
Reference in New Issue
Block a user