diff --git a/app/models.py b/app/models.py index 30dc27d4..c1ec7274 100644 --- a/app/models.py +++ b/app/models.py @@ -614,8 +614,9 @@ class Tag(db.Model): class MinetestRelease(db.Model): - id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(100), unique=True, nullable=False) + id = db.Column(db.Integer, primary_key=True) + name = db.Column(db.String(100), unique=True, nullable=False) + protocol = db.Column(db.Integer, nullable=False, default=0) def __init__(self, name=None): self.name = name @@ -629,7 +630,7 @@ class PackageRelease(db.Model): package_id = db.Column(db.Integer, db.ForeignKey("package.id")) title = db.Column(db.String(100), nullable=False) - releaseDate = db.Column(db.DateTime, nullable=False) + releaseDate = db.Column(db.DateTime, nullable=False) url = db.Column(db.String(200), nullable=False) approved = db.Column(db.Boolean, nullable=False, default=False) task_id = db.Column(db.String(37), nullable=True) diff --git a/app/querybuilder.py b/app/querybuilder.py index a7f13230..e524bded 100644 --- a/app/querybuilder.py +++ b/app/querybuilder.py @@ -1,7 +1,8 @@ -from .models import db, PackageType, Package, ForumTopic, License +from .models import db, PackageType, Package, ForumTopic, License, MinetestRelease, PackageRelease from .utils import isNo from sqlalchemy.sql.expression import func from flask import abort +from sqlalchemy import or_ class QueryBuilder: title = None @@ -27,6 +28,7 @@ class QueryBuilder: self.limit = 1 if self.lucky else None self.order_by = args.get("sort") or "score" self.order_dir = args.get("order") or "desc" + self.protocol_version = args.get("protocol_version") if self.search is not None and self.search.strip() == "": self.search = None @@ -64,6 +66,18 @@ class QueryBuilder: query = query.filter(Package.license.has(License.is_foss == True)) query = query.filter(Package.media_license.has(License.is_foss == True)) + if self.protocol_version: + self.protocol_version = int(self.protocol_version) + version = MinetestRelease.query.filter(MinetestRelease.protocol>=self.protocol_version).first() + if version is not None: + version = version.id + else: + version = 10000000 + + query = query.join(Package.releases) \ + .filter(or_(PackageRelease.min_rel_id==None, PackageRelease.min_rel_id<=version)) \ + .filter(or_(PackageRelease.max_rel_id==None, PackageRelease.max_rel_id>=version)) + if self.limit: query = query.limit(self.limit) diff --git a/app/views/api.py b/app/views/api.py index 1e7190a0..273ae8e6 100644 --- a/app/views/api.py +++ b/app/views/api.py @@ -61,3 +61,9 @@ def topic_set_discard(): db.session.commit() return jsonify(topic.getAsDictionary()) + + +@app.route("/api/minetest_versions/") +def api_minetest_versions_page(): + return jsonify([{ "name": rel.name, "protocol_version": rel.protocol }\ + for rel in MinetestRelease.query.all() if rel.getActual() is not None]) diff --git a/migrations/versions/97a9c461bc2d_.py b/migrations/versions/97a9c461bc2d_.py new file mode 100644 index 00000000..0960d414 --- /dev/null +++ b/migrations/versions/97a9c461bc2d_.py @@ -0,0 +1,28 @@ +"""empty message + +Revision ID: 97a9c461bc2d +Revises: 7def3e843d04 +Create Date: 2019-01-28 20:49:41.831991 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = '97a9c461bc2d' +down_revision = '7def3e843d04' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('minetest_release', sa.Column('protocol', sa.Integer(), nullable=False, server_default="0")) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('minetest_release', 'protocol') + # ### end Alembic commands ###