예제 #1
0
def init_db(**kwargs):
    kwargs['tables'] = list(IResourceManager.get_models(tables=True))
    is_test = kwargs.pop('is_test', False)
    bind = kwargs.pop('bind', None)

    if kwargs['tables']:
        conn = bind or db.get_engine()
        metadata.create_all(conn, **kwargs)

        # some essential database things
        from inyoka.core.auth.models import User, UserProfile
        anon_name = ctx.cfg['anonymous_name']
        if not User.query.filter_by(username=anon_name).first():
            anon = User(username=anon_name, email=u'', password=u'')
            UserProfile(user=anon)

        admin_credentials = {
            'username': u'admin',
            'email': u'*****@*****.**'
        }
        if is_test and not User.query.filter_by(**admin_credentials).first():
            admin = User(password=u'default', **admin_credentials)
            UserProfile(user=admin)

        db.session.commit()
예제 #2
0
    def get_cls(self, name):
        """Try to find the right class for `name`"""
        cls = None
        models = list(IResourceManager.get_models())
        names = [m.__name__ for m in models]
        if name in names:
            cls = models[names.index(name)]

        # check that the class was found.
        if cls is None:
            raise AttributeError('Model %s not found' % name)

        return cls
예제 #3
0
    def get_cls(self, name):
        """Try to find the right class for `name`"""
        cls = None
        models = list(IResourceManager.get_models())
        names = [m.__name__ for m in models]
        if name in names:
            cls = models[names.index(name)]

        # check that the class was found.
        if cls is None:
            raise AttributeError('Model %s not found' % name)

        return cls
예제 #4
0
def init_db(**kwargs):
    kwargs['tables'] = list(IResourceManager.get_models(tables=True))
    is_test = kwargs.pop('is_test', False)
    bind = kwargs.pop('bind', None)

    if kwargs['tables']:
        conn = bind or db.get_engine()
        metadata.create_all(conn, **kwargs)

        # some essential database things
        from inyoka.core.auth.models import User, UserProfile
        anon_name = ctx.cfg['anonymous_name']
        if not User.query.filter_by(username=anon_name).first():
            anon = User(username=anon_name, email=u'', password=u'')
            UserProfile(user=anon)

        admin_credentials = {'username': u'admin', 'email': u'*****@*****.**'}
        if is_test and not User.query.filter_by(**admin_credentials).first():
            admin = User(password=u'default', **admin_credentials)
            UserProfile(user=admin)

        db.session.commit()