Browse Source

solved import madness

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

3
Dockerfile

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

15
app.py

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

2
docker-compose.yml

@ -5,4 +5,4 @@ services:
- "5002:5000"
build: .
volumes:
- ./instance:/app/instance
- ./instance:/app/instance

7
entrypoint.sh

@ -1,5 +1,8 @@
#!/bin/sh
flask db upgrade
set -x
#flask db upgrade
./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; };
version = "0.1.0";
name = "package name";
myR = pkgs.rWrapper.override{ packages = with pkgs.rPackages; [ crul ]; };
in {
devShell = pkgs.mkShell {
buildInputs = with pkgs; [ python3 poetry myR ];
buildInputs = with pkgs; [ python3 poetry gunicorn ];
};
defaultPackage = pkgs.stdenv.mkDerivation { inherit name version; };

2
initialize_db.py

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