From 0826f45b496486dea06e863397bccc3557930bc9 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Mon, 22 Jun 2015 13:09:41 -0800 Subject: [PATCH] WIP --- app/__init__.py | 20 +++++++++++++++++++ app/main/__init__.py | 7 +++++++ app/main/views.py | 6 ++++++ app/models.py | 47 ++++++++++++++++++++++++++++++++++++++++++++ config.py | 13 +++++++++++- config.py.default | 17 ---------------- manage.py | 7 ++++--- requirements.txt | 9 +++++++++ 8 files changed, 105 insertions(+), 21 deletions(-) create mode 100644 app/__init__.py create mode 100644 app/main/__init__.py create mode 100644 app/main/views.py create mode 100644 app/models.py delete mode 100644 config.py.default create mode 100644 requirements.txt diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..8ada18a --- /dev/null +++ b/app/__init__.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask.ext.sqlalchemy import SQLAlchemy +from config import config + + +db = SQLAlchemy() + + +def create_app(config_name): + app = Flask(__name__) + app.config.from_object(config[config_name]) + config[config_name].init_app(app) + + db.init_app(app) + + from .main import main as main_blueprint + app.register_blueprint(main_blueprint) + + return app + diff --git a/app/main/__init__.py b/app/main/__init__.py new file mode 100644 index 0000000..a4b038e --- /dev/null +++ b/app/main/__init__.py @@ -0,0 +1,7 @@ +from flask import Blueprint + + +main = Blueprint('main', __name__) + + +from . import views diff --git a/app/main/views.py b/app/main/views.py new file mode 100644 index 0000000..053c0f8 --- /dev/null +++ b/app/main/views.py @@ -0,0 +1,6 @@ +from . import main + +@main.route('/') +def index(): + return '

Hello world

' + diff --git a/app/models.py b/app/models.py new file mode 100644 index 0000000..18a297a --- /dev/null +++ b/app/models.py @@ -0,0 +1,47 @@ +from . import db + + +class Community(db.Model): + __tablename__ = 'communities' + + id = db.Column(db.Integer, primary_key=True) + name = db.Column(db.String(50), nullable=False, unique=True) + northing = db.Column(db.Float, nullable=False) + easting = db.Column(db.Float, nullable=False) + latitude = db.Column(db.Float, nullable=False) + longitude = db.Column(db.Float, nullable=False) + temperatures = db.relationship('Temperature', backref='communities') + + +class Dataset(db.Model): + __tablename__ = 'datasets' + + id = db.Column(db.Integer, primary_key=True + datatype = db.Column(db.String(15), nullable=False) + model = db.Column(db.String(15), nullable=False) + modelname = db.Column(db.String(50), nullable=False) + scenario = db.Column(db.String(15), nullable=False) + resolution = db.Column(db.String(15), nullable=False) + temperatures = db.relationship('Temperature', backref='datasets') + + +class Temperature(db.Model): + __tablename__ = 'temperatures' + + id = db.Column(db.Integer, primary_key=True) + dataset_id = db.Column(db.Integer, db.ForeignKey('datasets.id')) + community_id = db.Column(db.Integer, db.ForeignKey('communities.id')) + year = db.Column(db.Integer, nullable=False) + january = db.Column(db.Float, nullable=False) + february = db.Column(db.Float, nullable=False) + march = db.Column(db.Float, nullable=False) + april = db.Column(db.Float, nullable=False) + may = db.Column(db.Float, nullable=False) + june = db.Column(db.Float, nullable=False) + july = db.Column(db.Float, nullable=False) + august = db.Column(db.Float, nullable=False) + september = db.Column(db.Float, nullable=False) + october = db.Column(db.Float, nullable=False) + november = db.Column(db.Float, nullable=False) + december = db.Column(db.Float, nullable=False) + updated = db.Column(db.DateTime, nullable=True) diff --git a/config.py b/config.py index 26ecea8..d0cf2cb 100644 --- a/config.py +++ b/config.py @@ -7,9 +7,20 @@ class Config: APP_NAME = 'AKIndices' APP_VERSION = '0.2.0' + @staticmethod + def init_app(app): + pass + class DevelopmentConfig(Config): DEBUG = True SECRET_KEY = os.environ.get('SECRET_KEY') or 'top secret' - DATABASE_URL = os.environ.get('DATABASE_URL') + SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \ + 'postgres://user:pass@localhost/akindices' + +config = { + 'development': DevelopmentConfig, + + 'default': DevelopmentConfig +} diff --git a/config.py.default b/config.py.default deleted file mode 100644 index 2087a3f..0000000 --- a/config.py.default +++ /dev/null @@ -1,17 +0,0 @@ -# -*- coding: utf-8 -*- - -import datetime - -PERMANENT_SESSION_LIFETIME = datetime.timedelta(minutes=30) -CSRF_ENABLED = True -SECRET_KEY = 'A super secret key' -DEBUG = False - -# Custom -ENGINE = 'postgres://user:pass@localhost/akindices' -SNAPDATA = '/path/to/raw/data' -COMMUNITIES = '/path/to/list/of/communities' -LOG = 'akindices.log' -MAXLOG = 1000000 -BACKUPCOUNT = 10 -TITLE = 'AKIndices' diff --git a/manage.py b/manage.py index a118c65..9c65577 100644 --- a/manage.py +++ b/manage.py @@ -2,14 +2,15 @@ import os from app import create_app, db from flask.ext.script import Manager, Shell -from flask.ext.migrate import Migrate, MigrateCommand app = create_app(os.getenv('FLASK_CONFIG') or 'default') manager = Manager(app) -migrate = Migrate(app, db) -manager.add_command('db', MigrateCommand) + +@manager.command +def initdb(): + db.create_all(app=app) if __name__ == '__main__': diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a8d4b83 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,9 @@ +Flask==0.10.1 +Flask-SQLAlchemy==2.0 +Flask-Script==2.0.5 +Jinja2==2.7.3 +MarkupSafe==0.23 +SQLAlchemy==1.0.5 +Werkzeug==0.10.4 +itsdangerous==0.24 +wsgiref==0.1.2