Exemplo n.º 1
0
def send_async_email(email_data):

    """Background task to send an email with Flask-Mail."""
    with app.app_context():
        msg = Message(email_data['subject'],
                      sender=app.config['MAIL_DEFAULT_SENDER'],
                      recipients=[email_data['to']])
        msg.body = email_data['body']
        mail.send(msg)
Exemplo n.º 2
0
 def __init__(self, database):
     """ Receive database, declare context and set collection and
     structure as None to be defined in other classes.
     :param database: Receive mongodb instance connected to database
     """
     self.__context = app.app_context()
     self.__collection = None
     self.structure = None
     self.database = database
Exemplo n.º 3
0
    def setUp(self):

        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + 'test.db'
        self.app_context = app.app_context()
        self.app = app
        self.client = self.app.test_client()
        self.app.testing = True
        db.create_all()
Exemplo n.º 4
0
    def create(self):
        '''
            Cria o banco de dados se ainda nao foi criado 
        '''

        # Verifica se o Banco de dados existe ou nao para evitar sobrescrever
        if os.path.isfile(self.db_name):
            print('Database  ja Criado')
        else:
            with app.app_context():
                db.create_all()
                print(
                    'Banco de dados criado con sucesso \n \n proceda com o commando: \n ---> python app.py'
                )
Exemplo n.º 5
0
def refresh_news():
    with app.app_context():
        sets = Settings.query.options(load_only(
            Settings.latest_news_date)).one()
        print(sets)

        news = newslib.get_news(app.config['VK_GROUP_DOMAIN'],
                                app.config['VK_TOKEN'],
                                from_date=sets.latest_news_date)

        if news:
            # change latest date
            sets.latest_news_date = news[-1].get('date')

            for n in news:
                db.session.add(News(vk_json=n))

            db.session.commit()
Exemplo n.º 6
0
def create_tables():
    with app.app_context():
        database_session = open_session()

        # Create schema
        with app.open_resource('database/schema.sql', mode='r') as schema:
            database_session.cursor().executescript(schema.read())
        database_session.commit()

        # Initialize data
        for text in fixtures.texts:
            database_session.execute(
                'insert into texts (identifier, content, published) values (?, ?, ?)',
                [text['identifier'], text['content'], text['published']]
            )
            database_session.commit()

        for image in fixtures.images:
            database_session.execute(
                'insert into images (identifier, filename, published) values (?, ?, ?)',
                [image['identifier'], image['filename'], image['published']]
            )
            database_session.commit()

        for container in fixtures.containers:
            database_session.execute(
                'insert into containers (identifier, size, published) values (?, ?, ?)',
                [container['identifier'], container['size'], container['published']]
            )
            database_session.commit()

        database_session.execute(
            'insert into mapbox (geojson) values (?)',
            [fixtures.mapbox['geojson']]
        )
        database_session.commit()
Exemplo n.º 7
0
def delete_expired_items():
    with app.app_context():
        rows_deleted = Inventory.query.filter(Inventory.is_expired).delete()
        db.session.commit()
        print(rows_deleted)
 def __call__(self, *args, **kwargs):
     with app.app_context():
         return TaskBase.__call__(self, *args, **kwargs)
Exemplo n.º 9
0
from settings import app, db
from CaseApp.models import Inventory
#
# with app.app_context():
#     i = Inventory(user_id=17, item_id=1)
#     db.session.add(i)
#     db.session.commit()

with app.app_context():
    i = Inventory(user_id=17, item_id=1)