Skip to content

Instantly share code, notes, and snippets.

@Busata
Last active August 29, 2015 14:11
Show Gist options
  • Save Busata/a788720c7f7b128cf66a to your computer and use it in GitHub Desktop.
Save Busata/a788720c7f7b128cf66a to your computer and use it in GitHub Desktop.
def create_app(configuration=config.base_config, enable_blueprints=True):
app = Flask(__name__)
app.config.from_object(configuration)
register_extensions(app)
if enable_blueprints:
register_blueprints(app)
register_errorhandlers(app)
return app
def register_blueprints(app):
from staffing import index, authentication, employees, planning, projects, reporting,languages
blueprints = [index.bp, authentication.bp, employees.bp, planning.bp, projects.bp, reporting.bp,languages.bp]
[app.register_blueprint(bp) for bp in blueprints]
def register_extensions(app):
db.init_app(app)
security.init_app(app, user_datastore)
admin.init_app(app)
redis_store.init_app(app)
from celery import signals
from flask.ext.login import LoginManager
from staffing.database import db
login_manager = LoginManager()
from werkzeug.contrib.cache import SimpleCache
cache = SimpleCache()
from flask.ext.security import Security
security = Security()
from celery import Celery
def make_celery_app(app):
celery = Celery(__name__, broker=app.config["CELERY_BROKER_URL"])
celery.conf.update(app.config)
TaskBase = celery.Task
class ContextTask(TaskBase):
abstract=True
def __call__(self,*args,**kwargs):
with app.app_context():
return TaskBase.__call__(self,*args,**kwargs)
celery.Task = ContextTask
return celery
from flask_redis import Redis
redis_store = Redis()
def import_tics(tics_file):
#Reads CSV file, updates the database using db.session.add(Model(...)) etc.
import csv
from staffing import config
from staffing import create_app
from staffing.extensions import make_celery_app, redis_store
app = create_app(config.dev_config, enable_blueprints=False)
celery = make_celery_app(app)
@celery.task
def import_tics_file(file_name):
from staffing.importers import tics
tics.import_tics(file_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment