Browse Source

solved import madness

master
Juni Kim 2 years ago
parent
commit
77aba216f5
  1. 1
      Dockerfile
  2. 15
      app.py
  3. 7
      entrypoint.sh
  4. 3
      flake.nix
  5. 2
      initialize_db.py

1
Dockerfile

@ -14,4 +14,5 @@ RUN poetry install --no-dev
# now copy over everything # now copy over everything
COPY . /app/ COPY . /app/
EXPOSE 5002
ENTRYPOINT ["/app/entrypoint.sh"] ENTRYPOINT ["/app/entrypoint.sh"]

15
app.py

@ -1,6 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from datetime import date
import os import os
from flask import Flask, render_template, session, request, abort, redirect, url_for, jsonify from flask import Flask, render_template, session, request, abort, redirect, url_for, jsonify
from flask_sqlalchemy import SQLAlchemy from flask_sqlalchemy import SQLAlchemy
@ -11,14 +10,18 @@ from wtforms_alchemy import model_form_factory
from flask_migrate import Migrate from flask_migrate import Migrate
from uuid import uuid4 from uuid import uuid4
import csv import csv
from validate import validate_insertion_csv_fields, validate_query_csv_fields
import validate
# from datetime import date
app = Flask(__name__) app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///project.db" app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///project.db"
app.secret_key = '98d31240f9fbe14c8083586db49c19c3a8d3f726' app.secret_key = '98d31240f9fbe14c8083586db49c19c3a8d3f726'
db: SQLAlchemy = SQLAlchemy(app)
migrate = Migrate(app, db)
db: SQLAlchemy = SQLAlchemy()
migrate = Migrate()
db.init_app(app)
migrate.init_app(app, db)
BaseModelForm = model_form_factory(FlaskForm) BaseModelForm = model_form_factory(FlaskForm)
@ -296,7 +299,7 @@ def batch_add_request():
# read it as a csv # read it as a csv
with open(filename, "r") as csvfile: with open(filename, "r") as csvfile:
reader = csv.DictReader(csvfile) reader = csv.DictReader(csvfile)
results, error = validate_insertion_csv_fields(reader)
results, error = validate.validate_insertion_csv_fields(reader)
if error: if error:
cleanup() cleanup()
return render_template("batchadd.html", invalid=error) return render_template("batchadd.html", invalid=error)
@ -327,7 +330,7 @@ def batch_query_request():
# read it as a csv # read it as a csv
with open(filename, "r") as csvfile: with open(filename, "r") as csvfile:
reader = csv.DictReader(csvfile) reader = csv.DictReader(csvfile)
queries, error = validate_query_csv_fields(reader)
queries, error = validate.validate_query_csv_fields(reader)
if error: if error:
cleanup() cleanup()
return render_template("batchquery.html", invalid=error) return render_template("batchquery.html", invalid=error)

7
entrypoint.sh

@ -1,5 +1,8 @@
#!/bin/sh #!/bin/sh
flask db upgrade
set -x
#flask db upgrade
./initialize_db.py ./initialize_db.py
gunicorn -b 0.0.0.0:5000 app:app
#gunicorn -b 0.0.0.0:5000 'app.__init__.create_app()' --chdir /app
gunicorn -b 0.0.0.0:5000 app:app --chdir /app

3
flake.nix

@ -15,11 +15,10 @@
pkgs = import nixpkgs { inherit system; }; pkgs = import nixpkgs { inherit system; };
version = "0.1.0"; version = "0.1.0";
name = "package name"; name = "package name";
myR = pkgs.rWrapper.override{ packages = with pkgs.rPackages; [ crul ]; };
in { in {
devShell = pkgs.mkShell { devShell = pkgs.mkShell {
buildInputs = with pkgs; [ python3 poetry myR ];
buildInputs = with pkgs; [ python3 poetry gunicorn ];
}; };
defaultPackage = pkgs.stdenv.mkDerivation { inherit name version; }; defaultPackage = pkgs.stdenv.mkDerivation { inherit name version; };

2
initialize_db.py

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from app import db, app
from app import app, db
with app.app_context(): with app.app_context():
db.create_all() db.create_all()
Loading…
Cancel
Save