def after_db_init():
    """ Create models for module in dB """
    with app_instance.app_context():
        # Creates any models that have been imported
        db.create_all()

        # Init security for the application
        from .security import user_datastore

        # Create the Admin user
        if not UserModel.find(1):
            user_datastore.create_role(name='_permissions | admin')
            user_datastore.create_role(name='_permissions | manager')
            user_datastore.create_role(name='_permissions | agent')
            user_datastore.create_user(
                username='******',
                email='*****@*****.**',
                password='******',
                first_name='Super',
                last_name='Admin',
                roles=['_permissions | admin']
            )
            db.session.commit()

        # Register the admin views to the extension
        admin.add_view(
            UsersView(
                UserModel, db.session, name='Manage Users', category='User Admin'
            )
        )
        admin.add_view(RolesView(RolesModel, db.session, name='Manage Privileges', category='User Admin'))
Esempio n. 2
0
def send_async_email_task(subject, sender, recipients, text_body, html_body):
    # print(sender)
    # print(recipients)

    msg = Message(subject, sender=sender, recipients=recipients)
    msg.body = text_body
    msg.html = html_body
    with app_instance.app_context():
        mail_instance.send(msg)
Esempio n. 3
0
# security/__init__.py
from flask import Blueprint
from flask_restful import Api

from app import app_instance, admin, db
from app.server import build_routes
from .tasks import register_tasks
from .views import (SLAReportView, ClientView, CallDataView, EventDataView,
                    TablesLoadedView, ClientManagerView, SLASummaryReportView)

sla_report_bp = Blueprint('sla_report_bp', __name__)
sla_report_api = Api(sla_report_bp)
""" Create models for module in dB """
with app_instance.app_context():
    from app.report.models import (SlaReportModel, TablesLoadedModel,
                                   ClientManager, CallTableModel,
                                   EventTableModel, ClientModel,
                                   SummarySLAReportModel)

    # Init task scheduling
    register_tasks(app_instance)

    # Creates any models that have been imported
    db.create_all()

    # Report Views: All
    admin.add_view(
        SLAReportView(SlaReportModel,
                      db.session,
                      name='SLA Reports',
                      category="SLA Admin"))
 def __call__(self, *args, **kwargs):
     with app_instance.app_context():
         return super().__call__(self, *args, **kwargs)