Esempio n. 1
0
    def make_declarative_base(self):
        """ Creates the declarative base.
        """

        base = declarative_base(
            cls=FMModel,
            name='Model',
            metaclass=_BoundDeclarativeMeta)
        base.query = _QueryProperty(self)

        return base
 def make_declarative_base(self, metadata=None):
     """Creates the declarative base."""
     base = fsqla.declarative_base(
         cls=fsqla.Model,
         name='Model',
         metadata=metadata,
         metaclass=TableArgsMeta(
             fsqla._BoundDeclarativeMeta,
             {'mysql_engine': 'InnoDB'} ) )
     base.query = fsqla._QueryProperty(self)
     return base
Esempio n. 3
0
admin = Admin(app, "Auth", index_view=SecuredAdminIndexView())

model_classes = []
if app.config.get("AUTOGENERATE_MODEL_ADMIN", True):
    # We have to hook in to the db.Model metaclass to keep track of any table
    # classes we define
    class _AdminBoundDeclarativeMeta(sqlalchemy._BoundDeclarativeMeta):
        def __init__(self, name, bases, d):
            super(self.__class__, self).__init__(name, bases, d)
            if name != "Model":
                m = re.search(r'\.(.*)\.models', self.__module__)
                categoryName = m.group(1)
                model_classes.append((self, categoryName))

    db.Model = sqlalchemy.declarative_base(cls=sqlalchemy.Model,
        name="Model", mapper=sqlalchemy.signalling_mapper,
        metaclass=_AdminBoundDeclarativeMeta)
    db.Model.query = sqlalchemy._QueryProperty(db)


# Automatically include views, files and APIs
include_files = set(["views.py", "models.py", "api.py"])

for root, dirname, files in os.walk(app.config["BASEDIR"]):
    for filename in files:
        if filename in include_files:
            relative = os.path.relpath(os.path.join(root, filename))[:-3]
            module = ".".join(relative.split(os.sep))
            __import__(module, level=-1)

for cls, categoryName in model_classes:
Esempio n. 4
0
admin = Admin(app, "Auth", index_view=SecuredAdminIndexView())

model_classes = []
if app.config.get("AUTOGENERATE_MODEL_ADMIN", True):
    # We have to hook in to the db.Model metaclass to keep track of any table
    # classes we define
    class _AdminBoundDeclarativeMeta(sqlalchemy._BoundDeclarativeMeta):
        def __init__(self, name, bases, d):
            super(self.__class__, self).__init__(name, bases, d)
            if name != "Model":
                model_classes.append(self)

    db.Model = sqlalchemy.declarative_base(
        cls=sqlalchemy.Model,
        name="Model",
        mapper=sqlalchemy.signalling_mapper,
        metaclass=_AdminBoundDeclarativeMeta)
    db.Model.query = sqlalchemy._QueryProperty(db)

# Automatically include views, files and APIs
include_files = set(["views.py", "models.py", "api.py"])

for root, dirname, files in os.walk(app.config["BASEDIR"]):
    for filename in files:
        if filename in include_files:
            relative = os.path.relpath(os.path.join(root, filename))[:-3]
            module = ".".join(relative.split(os.sep))
            __import__(module, level=-1)

for cls in model_classes:
Esempio n. 5
0
        return current_user.has_role("admin")

admin = Admin(app, app.config["PROJECT_NAME"])

model_classes = []
if app.config.get("AUTOGENERATE_MODEL_ADMIN", True):
    # We have to hook in to the db.Model metaclass to keep track of any table
    # classes we define
    class _AdminBoundDeclarativeMeta(sqlalchemy._BoundDeclarativeMeta):
        def __init__(self, name, bases, d):
            super(self.__class__, self).__init__(name, bases, d)
            if name != "Model":
                model_classes.append(self)

    db.Model = sqlalchemy.declarative_base(cls=sqlalchemy.Model,
        name="Model",
        metaclass=_AdminBoundDeclarativeMeta)
    db.Model.query = sqlalchemy._QueryProperty(db)


# Automatically include views, files and APIs
include_files = set(["views.py", "models.py", "api.py"])

for root, dirname, files in os.walk(app.config["BASEDIR"]):
    for filename in files:
        if filename in include_files:
            relative = os.path.relpath(os.path.join(root, filename))[:-3]
            module = ".".join(relative.split(os.sep))
            __import__(module, level=-1)

for cls in model_classes:
Esempio n. 6
0

admin = Admin(app, app.config["PROJECT_NAME"])

model_classes = []
if app.config.get("AUTOGENERATE_MODEL_ADMIN", True):
    # We have to hook in to the db.Model metaclass to keep track of any table
    # classes we define
    class _AdminBoundDeclarativeMeta(sqlalchemy._BoundDeclarativeMeta):
        def __init__(self, name, bases, d):
            super(self.__class__, self).__init__(name, bases, d)
            if name != "Model":
                model_classes.append(self)

    db.Model = sqlalchemy.declarative_base(
        cls=sqlalchemy.Model,
        name="Model",
        metaclass=_AdminBoundDeclarativeMeta)
    db.Model.query = sqlalchemy._QueryProperty(db)

# Automatically include views, files and APIs
include_files = set(["views.py", "models.py", "api.py"])

for root, dirname, files in os.walk(app.config["BASEDIR"]):
    for filename in files:
        if filename in include_files:
            relative = os.path.relpath(os.path.join(root, filename))[:-3]
            module = ".".join(relative.split(os.sep))
            __import__(module, level=-1)

for cls in model_classes:
    admin.register(cls, session=db.session, admin_class=SecuredModelView)
Esempio n. 7
0
 def make_declarative_base(self):
     """Creates the declarative base."""
     base = declarative_base(cls=Model, name='Model',
                             metaclass=HookModelMeta)
     base.query = _QueryProperty(self)
     return base