Last active
August 29, 2015 14:11
-
-
Save Busata/a788720c7f7b128cf66a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def import_tics(tics_file): | |
#Reads CSV file, updates the database using db.session.add(Model(...)) etc. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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