Esempio n. 1
0
def register_forms(path):
    app_path = os.path.dirname(os.path.abspath(app.root_path))

    for filename in os.listdir(path):

        if filename[-3:] != ".py":
            continue

        file_path = os.path.join(path, filename)

        name = os.path.splitext(file_path)[0]
        name = os.path.relpath(name, app_path)
        name = name.replace('/', '.')

        module = import_module(name)

        for name in dir(module):
            attribute = getattr(module, name)

            try:
                if not issubclass(attribute, Form):
                    continue
            except TypeError:
                continue

            globals()[name] = attribute
Esempio n. 2
0
def register_views(app, path, extension=''):
    app_path = os.path.dirname(os.path.abspath(app.root_path))

    for filename in os.listdir(path):
        file_path = os.path.join(path, filename)

        # Check if the current file is a module.
        if is_module(file_path):
            # Get the module name from the file path.
            module_name = os.path.splitext(file_path)[0]
            module_name = os.path.relpath(module_name, app_path)
            module_name = module_name.replace('/', '.')

            blueprint = getattr(import_module(module_name), 'blueprint', None)

            if blueprint:
                print(('{0} has been imported.'.format(module_name)))
                app.register_blueprint(blueprint)