Beispiel #1
0
    def setUp(self):
        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()
Beispiel #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()
Beispiel #3
0
    def setUp(self):
        """
        Initialize app and setup admin user ('admin', 'admin'), a SiteConfig and
        a Page.
        """
        self.create_app()
        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()