Example #1
0
    def create_app(self):
        self.app = create_app("silverflask.settings.TestConfig", env="dev")
        db.init_app(self.app)

        with self.app.app_context():
            db.create_all()

        return self.app
Example #2
0
def createdb():
    """
    Creates a database with the defined models
    and also adds the default records that are needed for the CMS:
    Admin User, Admin Role, Default first page, and stuff
    """

    db.create_all()
    from silverflask.models import User
    from silverflask.models.User import Role
    if not len(Role.query.all()):
        admin_role = Role("admin", "Admin has all privileges")
        db.session.add(admin_role)
        db.session.commit()

    if not len(User.query.all()):
        # create standard user
        u = User("admin", "admin")
        u.firstname = "Default"
        u.lastname = "Admin"
        u.email = "admin"
        db.session.add(u)
        admin_role = Role.query.filter(Role.name == "admin").first()
        u.roles.append(admin_role)
        db.session.commit()

    from silverflask.models import SiteConfig
    if not len(SiteConfig.query.all()):
        sc = SiteConfig()
        sc.title = "Your SilverFlask Website"
        sc.tagline = "This is a default installation"
        db.session.add(sc)
        db.session.commit()

    if not len(Page.query.all()):
        page = Page()
        page.content = "<p>Please proceed to the admin interface at <a href='/admin'>admin</a>!</p>"
        page.name = "home"
        page.urlsegment = "home"
        db.session.add(page)
        db.session.commit()
        page.mark_as_published()
        db.session.commit()
Example #3
0
def createdb():
    """ Creates a database with all of the tables defined in
        your Alchemy models
    """

    db.create_all()
    from silverflask.models import User
    from silverflask.models.User import Role
    if not len(Role.query.all()):
        admin_role = Role("admin", "Admin has all privileges")
        db.session.add(admin_role)
        db.session.commit()
    if not len(User.query.all()):
        # create standard user
        u = User("admin", "admin")
        u.email = "admin"
        db.session.add(u)
        admin_role = Role.query.filter(Role.name == "admin").first()
        u.roles.append(admin_role)
        db.session.commit()

    from silverflask.models import SiteConfig
    if not len(SiteConfig.query.all()):
        sc = SiteConfig()
        db.session.add(sc)
        db.session.commit()

    if not len(Page.query.all()):
        page = Page()
        page.content = "<p>Please proceed to the admin interface at <a href='/admin'>admin</a>!</p>"
        page.name = "home"
        page.urlsegment = "home"
        db.session.add(page)
        db.session.commit()
        page.mark_as_published()
        db.session.commit()