Ejemplo n.º 1
0
def setup_app(settings):
    # Init CouchDB model.
    print "initializing model"
    init_model(settings)

    # Add design docs to CouchDB.
    path = sys.path[0] + '/_design'
    print "loading views at %s" % path
    loader = FileSystemDocsLoader(path)
    loader.sync(Session.auth)

    # Add a user, group, and permission to CouchDB.
    user_name = 'admin'
    user_password = '******'
    group_name = 'administrators'
    perm_name = 'superpowers'

    if len(User.view('whatcouch/user_list', key=user_name)) > 0:
        raise Exception('User already exists.')
    if len(Group.view('whatcouch/group_list', key=group_name)) > 0:
        raise Exception('Group already exists.')
    if len(Permission.view('whatcouch/permission_list', key=perm_name)) > 0:
        raise Exception('Permission already exists.')

    print "loading data"
    perm = Permission(name=perm_name)
    perm.save()
    group = Group(name=group_name)
    group.permissions.append(perm)
    group.save()
    user = User.create(user_name, user_password)
    user.groups.append(group)
    user.save()
Ejemplo n.º 2
0
def setup_app(command, conf, vars):
    """Place any commands to setup whatcouch_pylons here"""
    # Don't reload the app if it was loaded under the testing environment
    if not pylons.test.pylonsapp:
        load_environment(conf.global_conf, conf.local_conf)

    # Add design docs to CouchDB.
    loader = FileSystemDocsLoader(sys.path[0] + '/whatcouch_pylons/_design')
    loader.sync(Session.auth)

    # Add a user, group, and permission to CouchDB.
    user_name = 'admin'
    user_password = '******'
    group_name = 'administrators'
    perm_name = 'superpowers'

    if len(User.view('whatcouch/user_list', key=user_name)) > 0:
        raise Exception('User already exists.')
    if len(Group.view('whatcouch/group_list', key=group_name)) > 0:
        raise Exception('Group already exists.')
    if len(Permission.view('whatcouch/permission_list', key=perm_name)) > 0:
        raise Exception('Permission already exists.')

    perm = Permission(name=perm_name)
    perm.save()
    group = Group(name=group_name)
    group.permissions.append(perm)
    group.save()
    user = User.create(user_name, user_password)
    user.groups.append(group)
    user.save()