diff --git a/.gitignore b/.gitignore index 03d97799..382c3d6e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ config.cfg -config.prod.cfg *.env *.sqlite custom.css diff --git a/Dockerfile b/Dockerfile index c91a69f3..73b620d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,9 +8,10 @@ RUN pip install gunicorn RUN pip install psycopg2 COPY runprodguni.sh ./ +COPY rundebug.sh ./ RUN chmod +x runprodguni.sh COPY setup.py ./setup.py COPY app app COPY migrations migrations -COPY config.prod.cfg ./config.prod.cfg +COPY config.cfg ./config.cfg diff --git a/README.md b/README.md index e8cf5dc0..21e4410d 100644 --- a/README.md +++ b/README.md @@ -21,4 +21,7 @@ FLASK_CONFIG=../config.cfg FLASK_APP=app/__init__.py flask db migrate # Run migration FLASK_CONFIG=../config.cfg FLASK_APP=app/__init__.py flask db upgrade + +# Enter docker +docker exec -it contentdb_app_1 bash ``` diff --git a/app/models.py b/app/models.py index 20c3e601..30dc27d4 100644 --- a/app/models.py +++ b/app/models.py @@ -612,6 +612,18 @@ class Tag(db.Model): regex = re.compile("[^a-z_]") self.name = regex.sub("", self.title.lower().replace(" ", "_")) + +class MinetestRelease(db.Model): + id = db.Column(db.Integer, primary_key=True) + name = db.Column(db.String(100), unique=True, nullable=False) + + def __init__(self, name=None): + self.name = name + + def getActual(self): + return None if self.name == "None" else self + + class PackageRelease(db.Model): id = db.Column(db.Integer, primary_key=True) @@ -623,6 +635,12 @@ class PackageRelease(db.Model): task_id = db.Column(db.String(37), nullable=True) commit_hash = db.Column(db.String(41), nullable=True, default=None) + min_rel_id = db.Column(db.Integer, db.ForeignKey("minetest_release.id"), nullable=True, server_default=None) + min_rel = db.relationship("MinetestRelease", foreign_keys=[min_rel_id]) + + max_rel_id = db.Column(db.Integer, db.ForeignKey("minetest_release.id"), nullable=True, server_default=None) + max_rel = db.relationship("MinetestRelease", foreign_keys=[max_rel_id]) + def getEditURL(self): return url_for("edit_release_page", diff --git a/app/templates/packages/release_edit.html b/app/templates/packages/release_edit.html index c309dacc..32df3064 100644 --- a/app/templates/packages/release_edit.html +++ b/app/templates/packages/release_edit.html @@ -39,6 +39,11 @@ Approved: {{ release.approved }} {% endif %} {% endif %} + +
+ {{ render_field(form.min_rel, class_="col-sm-6") }} + {{ render_field(form.max_rel, class_="col-sm-6") }} +
{{ render_submit_field(form.submit) }} diff --git a/app/templates/packages/release_new.html b/app/templates/packages/release_new.html index 2f3bf68c..32cc8d86 100644 --- a/app/templates/packages/release_new.html +++ b/app/templates/packages/release_new.html @@ -18,6 +18,12 @@ {% endif %} {{ render_field(form.fileUpload, fieldclass="form-control-file") }} + +
+ {{ render_field(form.min_rel, class_="col-sm-6") }} + {{ render_field(form.max_rel, class_="col-sm-6") }} +
+ {{ render_submit_field(form.submit) }} {% endblock %} diff --git a/app/views/packages/releases.py b/app/views/packages/releases.py index b314b810..98a72a16 100644 --- a/app/views/packages/releases.py +++ b/app/views/packages/releases.py @@ -27,12 +27,18 @@ from celery import uuid from flask_wtf import FlaskForm from wtforms import * from wtforms.validators import * +from wtforms.ext.sqlalchemy.fields import QuerySelectField + class CreatePackageReleaseForm(FlaskForm): title = StringField("Title", [InputRequired(), Length(1, 30)]) uploadOpt = RadioField ("Method", choices=[("upload", "File Upload")], default="upload") vcsLabel = StringField("VCS Commit or Branch", default="master") fileUpload = FileField("File Upload") + min_rel = QuerySelectField("Minimum Minetest Version", [InputRequired()], + query_factory=lambda: MinetestRelease.query.order_by(db.asc(MinetestRelease.id)), get_pk=lambda a: a.id, get_label=lambda a: a.name) + max_rel = QuerySelectField("Maximum Minetest Version", [InputRequired()], + query_factory=lambda: MinetestRelease.query.order_by(db.asc(MinetestRelease.id)), get_pk=lambda a: a.id, get_label=lambda a: a.name) submit = SubmitField("Save") class EditPackageReleaseForm(FlaskForm): @@ -40,6 +46,10 @@ class EditPackageReleaseForm(FlaskForm): url = StringField("URL", [URL]) task_id = StringField("Task ID") approved = BooleanField("Is Approved") + min_rel = QuerySelectField("Minimum Minetest Version", [InputRequired()], + query_factory=lambda: MinetestRelease.query.order_by(db.asc(MinetestRelease.id)), get_pk=lambda a: a.id, get_label=lambda a: a.name) + max_rel = QuerySelectField("Maximum Minetest Version", [InputRequired()], + query_factory=lambda: MinetestRelease.query.order_by(db.asc(MinetestRelease.id)), get_pk=lambda a: a.id, get_label=lambda a: a.name) submit = SubmitField("Save") @app.route("/packages///releases/new/", methods=["GET", "POST"]) @@ -63,6 +73,8 @@ def create_release_page(package): rel.title = form["title"].data rel.url = "" rel.task_id = uuid() + rel.min_rel = form["min_rel"].data.getActual() + rel.max_rel = form["max_rel"].data.getActual() db.session.add(rel) db.session.commit() @@ -80,6 +92,8 @@ def create_release_page(package): rel.package = package rel.title = form["title"].data rel.url = uploadedPath + rel.min_rel = form["min_rel"].data.getActual() + rel.max_rel = form["max_rel"].data.getActual() db.session.add(rel) db.session.commit() @@ -128,6 +142,8 @@ def edit_release_page(package, id): wasApproved = release.approved if canEdit: release.title = form["title"].data + release.min_rel = form["min_rel"].data.getActual() + release.max_rel = form["max_rel"].data.getActual() if package.checkPerm(current_user, Permission.CHANGE_RELEASE_URL): release.url = form["url"].data diff --git a/docker-compose.yml b/docker-compose.yml index 93e86bcc..a7e71e69 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,12 +15,13 @@ services: app: build: . - command: ./runprodguni.sh + command: ./rundebug.sh ports: - 5123:5123 volumes: - "./data/uploads:/home/cdb/app/public/uploads" - "./app:/home/cdb/app" + - "./migrations:/home/cdb/migrations" depends_on: - db - redis diff --git a/migrations/versions/7def3e843d04_.py b/migrations/versions/7def3e843d04_.py new file mode 100644 index 00000000..80ffac6d --- /dev/null +++ b/migrations/versions/7def3e843d04_.py @@ -0,0 +1,41 @@ +"""empty message + +Revision ID: 7def3e843d04 +Revises: dce69ad1e4eb +Create Date: 2019-01-28 20:27:33.760232 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = '7def3e843d04' +down_revision = 'dce69ad1e4eb' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('minetest_release', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('name', sa.String(length=100), nullable=False), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('name') + ) + op.add_column('package_release', sa.Column('max_rel_id', sa.Integer(), nullable=True, server_default=None)) + op.add_column('package_release', sa.Column('min_rel_id', sa.Integer(), nullable=True, server_default=None)) + op.create_foreign_key(None, 'package_release', 'minetest_release', ['max_rel_id'], ['id']) + op.create_foreign_key(None, 'package_release', 'minetest_release', ['min_rel_id'], ['id']) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint(None, 'package_release', type_='foreignkey') + op.drop_constraint(None, 'package_release', type_='foreignkey') + op.drop_column('package_release', 'min_rel_id') + op.drop_column('package_release', 'max_rel_id') + op.drop_table('minetest_release') + # ### end Alembic commands ### diff --git a/rundebug.sh b/rundebug.sh index 24270594..31e91375 100755 --- a/rundebug.sh +++ b/rundebug.sh @@ -1,3 +1,3 @@ #!/bin/bash -FLASK_APP=app/__init__.py FLASK_CONFIG=../config.cfg FLASK_DEBUG=1 python3 -m flask run +FLASK_APP=app/__init__.py FLASK_CONFIG=../config.cfg FLASK_DEBUG=1 python3 -m flask run -h 0.0.0.0 -p 5123 diff --git a/runprod.sh b/runprod.sh index 99515166..c64450ca 100755 --- a/runprod.sh +++ b/runprod.sh @@ -1,3 +1,3 @@ #!/bin/bash -FLASK_APP=app/__init__.py FLASK_CONFIG=../config.prod.cfg FLASK_DEBUG=0 python3 -m flask run -h 0.0.0.0 -p 5123 +FLASK_APP=app/__init__.py FLASK_CONFIG=../config.cfg FLASK_DEBUG=0 python3 -m flask run -h 0.0.0.0 -p 5123 diff --git a/runprodguni.sh b/runprodguni.sh index c7e8bb88..68c69623 100644 --- a/runprodguni.sh +++ b/runprodguni.sh @@ -1,3 +1,3 @@ #!/bin/bash -gunicorn -w 4 -b :5123 -e FLASK_APP=app/__init__.py -e FLASK_CONFIG=../config.prod.cfg -e FLASK_DEBUG=1 app:app +gunicorn -w 4 -b :5123 -e FLASK_APP=app/__init__.py -e FLASK_CONFIG=../config.cfg -e FLASK_DEBUG=0 app:app