def test_database(self, request): """Check if the database uri is valid.""" database_uri = request.values.get('database_uri') error = None if not database_uri: error = 'You have to provide a database URI.' else: try: db.create_engine(database_uri, self.instance_folder) except Exception, e: error = str(e)
def create_instance( instance_folder=DEFAULT_INSTANCE_FOLDER, database_uri=DEFAULT_DATABASE_URI, admin_username=DEFAULT_ADMIN_USERNAME, admin_password=DEFAULT_ADMIN_PASSWORD, admin_email=DEFAULT_ADMIN_EMAIL, ): """Create a new blog instance. """ if not admin_password: raise ValueError("Must specify admin_password") if not admin_email: raise ValueError("Must specify admin_email") error = None # set up the initial config config_filename = path.join(instance_folder, "rezine.ini") import rezine.application from rezine.config import Configuration if not path.exists(instance_folder): mkdir(instance_folder) cfg = Configuration(config_filename) t = cfg.edit() t.update( maintenance_mode=1, secret_key=gen_secret_key(), database_uri=database_uri, iid=new_iid(), # load one plugin by default for a better theme plugins="vessel_theme", theme="vessel", ) cfg._comments["[rezine]"] = CONFIG_HEADER t.commit() from rezine.api import db from rezine.database import init_database try: e = db.create_engine(database_uri, instance_folder) init_database(e) except Exception, error: error = str(error).decode("utf-8", "ignore")