def create_db (app):
    db = ZODB(app)
    return db
示例#2
0
# add a file rotation handler of 1Mb of size and 3 backups
fh = logging.handlers.RotatingFileHandler(app.config['LOG_FILE'],
                                          maxBytes=1048576,
                                          backupCount=3)
fh.setLevel(app.config['LOG_LEVEL'])
# create a formatter and set the formatter for the handler.
frmt = logging.Formatter(
    '[%(asctime)s] - %(funcName)s - %(levelname)s - %(message)s')
fh.setFormatter(frmt)
# add the Handler to the logger
log.addHandler(fh)

celery = Celery('baby_care')
celery.conf.update(app.config)

db = ZODB(app)


@app.before_first_request
def before_first_request():
    if not db.has_key('lvl_normal'):
        db['lvl_normal'] = app.config['LVL_NORMAL']
    if not db.has_key('normal_interval'):
        db['normal_interval'] = app.config['NORMAL_INTERVAL']
    if not db.has_key('active_interval'):
        db['active_interval'] = app.config['ACTIVE_INTERVAL']
    if not db.has_key('agi_normal'):
        db['agi_normal'] = app.config['AGI_NORMAL']


import Baby_Care_WS
示例#3
0
'''
Created on 2 lis 2013

@author: karol
'''
import inspect

import transaction

from flask.ext.zodb import ZODB  # @UnresolvedImport
from flask.ext.zodb import Dict, BTree  # @UnresolvedImport

storage = ZODB()


def bootstrap_storage(application, storage, modules_map):
    for prefix, module in modules_map.items():
        cls = [t for t in inspect.getmembers(module, inspect.isclass)]
        cleaned = [c for c in cls if c[1].__module__ == module.__name__]
        for pc in cleaned:
            classname, klass = pc
            for_join = [prefix, classname] if prefix else [classname]
            name = ".".join(for_join)
            with application.test_request_context():
                try:
                    storage[name]
                except KeyError:
                    storage[name] = klass.Meta.persist_in()
                    transaction.commit()
                augment_with_active_record(klass, name)