WIP
This commit is contained in:
parent
8a29e14212
commit
0826f45b49
8 changed files with 105 additions and 21 deletions
20
app/__init__.py
Normal file
20
app/__init__.py
Normal file
|
@ -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
|
||||||
|
|
7
app/main/__init__.py
Normal file
7
app/main/__init__.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
from flask import Blueprint
|
||||||
|
|
||||||
|
|
||||||
|
main = Blueprint('main', __name__)
|
||||||
|
|
||||||
|
|
||||||
|
from . import views
|
6
app/main/views.py
Normal file
6
app/main/views.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
from . import main
|
||||||
|
|
||||||
|
@main.route('/')
|
||||||
|
def index():
|
||||||
|
return '<h1>Hello world</h1>'
|
||||||
|
|
47
app/models.py
Normal file
47
app/models.py
Normal file
|
@ -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)
|
13
config.py
13
config.py
|
@ -7,9 +7,20 @@ class Config:
|
||||||
APP_NAME = 'AKIndices'
|
APP_NAME = 'AKIndices'
|
||||||
APP_VERSION = '0.2.0'
|
APP_VERSION = '0.2.0'
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def init_app(app):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DevelopmentConfig(Config):
|
class DevelopmentConfig(Config):
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
SECRET_KEY = os.environ.get('SECRET_KEY') or 'top secret'
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -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'
|
|
|
@ -2,14 +2,15 @@
|
||||||
import os
|
import os
|
||||||
from app import create_app, db
|
from app import create_app, db
|
||||||
from flask.ext.script import Manager, Shell
|
from flask.ext.script import Manager, Shell
|
||||||
from flask.ext.migrate import Migrate, MigrateCommand
|
|
||||||
|
|
||||||
|
|
||||||
app = create_app(os.getenv('FLASK_CONFIG') or 'default')
|
app = create_app(os.getenv('FLASK_CONFIG') or 'default')
|
||||||
manager = Manager(app)
|
manager = Manager(app)
|
||||||
migrate = Migrate(app, db)
|
|
||||||
|
|
||||||
manager.add_command('db', MigrateCommand)
|
|
||||||
|
@manager.command
|
||||||
|
def initdb():
|
||||||
|
db.create_all(app=app)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
9
requirements.txt
Normal file
9
requirements.txt
Normal file
|
@ -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
|
Loading…
Add table
Reference in a new issue