Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def save_db_settings_to_file(form):
- path_to_store_settings = os.path.join(settings.BASE_DIR, 'SystemProyect')
- for fname in os.listdir(path_to_store_settings):
- if fname=='conexion.cfg':
- full_path = os.path.join(path_to_store_settings, fname)
- remove(full_path)
- database_id = 'db_app2' # just something unique
- newDatabase = {}
- newDatabase["id"] = database_id
- newDatabase['ENGINE'] = 'sql_server.pyodbc'
- newDatabase['NAME'] = form.data['database']
- newDatabase['USER'] = form.data['usuario_sql']
- newDatabase['PASSWORD'] = form.data['password_sql']
- newDatabase['HOST'] = form.data['servidor_sql']
- newDatabase['PORT'] = ''
- settings.DATABASES[database_id] = newDatabase
- newDbString = """DATABASES={'%(id)s':{
- 'ENGINE': '%(ENGINE)s', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
- 'NAME': '%(NAME)s', # Or path to database file if using sqlite3.
- 'USER': '%(USER)s', # Not used with sqlite3.
- 'PASSWORD': '%(PASSWORD)s', # Not used with sqlite3.
- 'HOST': '%(HOST)s', # Set to empty string for localhost. Not used with sqlite3.
- 'PORT': '', # Set to empty string for default. Not used with sqlite3.
- 'OPTIONS':"{'driver': 'SQL Server Native Client 10.0',}"
- } }
- """% newDatabase
- file_to_store_settings = os.path.join(path_to_store_settings, 'conexion' + ".py")
- salvar=open(file_to_store_settings,'w')
- salvar.write(newDbString)
- salvar.close()
- import os
- path_to_store_settings = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'SystemProyect')
- for fname in os.listdir(path_to_store_settings):
- if fname == 'conexion.py':
- full_path = os.path.join(path_to_store_settings, fname)
- with open(full_path) as fobj:
- archivo_inicio = fobj.read()
- exec(archivo_inicio)
- DATABASES = {
- 'versat': {
- 'ENGINE': 'sql_server.pyodbc', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
- 'NAME': 'eicma', # Or path to database file if using sqlite3.
- 'USER': 'tony', # Not used with sqlite3.
- 'PASSWORD': 'tony', # Not used with sqlite3.
- 'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3.
- 'PORT': '', # Set to empty string for default. Not used with sqlite3.
- 'OPTIONS': "{'driver': 'SQL Server Native Client 10.0',}"
- }
- }
Add Comment
Please, Sign In to add comment