Beispiel #1
0
@login_manager.user_loader
def load_user(user_id):
    """
    load a User by a given user id
    :param user_id: the User's id
    :return: the User or None
    """

    return User.query.get(user_id)


def create_initial_user():
    """
    create an initial User if there is none yet
    """

    # check if there is any user in the db
    if User.query.count() == 0:
        # create a user
        user = User(username="******",
                    password=hashlib.sha256(
                        "admin".encode("utf8")).hexdigest(),
                    email="*****@*****.**")
        user.is_admin = True
        db.session.add(user)
        db.session.commit()


on_application_ready.append(create_initial_user)
Beispiel #2
0
import atexit

from app import on_application_ready, app
from app.modules.mod_process.process_repository import ProcessRepository


def register_jinja2_functions():
    """
    register count_process_* and encoding_active() functions for jinja2
    """
    from app.modules.mod_process.process_repository import ProcessRepository

    app.jinja_env.globals.update(count_processes_active=ProcessRepository.count_processes_active)
    app.jinja_env.globals.update(count_processes_queued=ProcessRepository.count_processes_queued)
    app.jinja_env.globals.update(count_processes_total=ProcessRepository.count_processes_total)
    app.jinja_env.globals.update(encoding_active=lambda: ProcessRepository.encoding_active)


def fail_on_exit():
    """
    on exit cancel all processes
    """
    ProcessRepository.cancel_all_processes()


# run fail method when this Thread is still running and the program quits unexpectedly
atexit.register(fail_on_exit)

# register common jinja2 functions
on_application_ready.append(register_jinja2_functions)
Beispiel #3
0

def register_jinja2_functions():
    """
    register count_process_* and encoding_active() functions for jinja2
    """
    from app.modules.mod_process.process_repository import ProcessRepository

    app.jinja_env.globals.update(
        count_processes_active=ProcessRepository.count_processes_active)
    app.jinja_env.globals.update(
        count_processes_queued=ProcessRepository.count_processes_queued)
    app.jinja_env.globals.update(
        count_processes_total=ProcessRepository.count_processes_total)
    app.jinja_env.globals.update(
        encoding_active=lambda: ProcessRepository.encoding_active)


def fail_on_exit():
    """
    on exit cancel all processes
    """
    ProcessRepository.cancel_all_processes()


# run fail method when this Thread is still running and the program quits unexpectedly
atexit.register(fail_on_exit)

# register common jinja2 functions
on_application_ready.append(register_jinja2_functions)
Beispiel #4
0
login_manager.localize_callback = _


@login_manager.user_loader
def load_user(user_id):
    """
    load a User by a given user id
    :param user_id: the User's id
    :return: the User or None
    """

    return User.query.get(user_id)


def create_initial_user():
    """
    create an initial User if there is none yet
    """

    # check if there is any user in the db
    if User.query.count() == 0:
        # create a user
        user = User(username="******", password=hashlib.sha256("admin".encode("utf8")).hexdigest(),
                    email="*****@*****.**")
        user.is_admin = True
        db.session.add(user)
        db.session.commit()


on_application_ready.append(create_initial_user)