def get_import_export_settings(): settings = get_setting('import_export_setting', None) if settings is None: return make_json_response(success=True, data={}) else: data = json.loads(settings) return make_json_response(success=True, data=data)
def utils(): layout = get_setting('Browser/Layout', default='') snippets = [] prefs = Preferences.module('paths') pg_help_path_pref = prefs.preference('pg_help_path') pg_help_path = pg_help_path_pref.get() edbas_help_path_pref = prefs.preference('edbas_help_path') edbas_help_path = edbas_help_path_pref.get() # Get sqleditor options prefs = Preferences.module('sqleditor') editor_tab_size_pref = prefs.preference('tab_size') editor_tab_size = editor_tab_size_pref.get() editor_use_spaces_pref = prefs.preference('use_spaces') editor_use_spaces = editor_use_spaces_pref.get() editor_wrap_code_pref = prefs.preference('wrap_code') editor_wrap_code = editor_wrap_code_pref.get() brace_matching_pref = prefs.preference('brace_matching') brace_matching = brace_matching_pref.get() insert_pair_brackets_perf = prefs.preference('insert_pair_brackets') insert_pair_brackets = insert_pair_brackets_perf.get() # This will be opposite of use_space option editor_indent_with_tabs = False if editor_use_spaces else True # Try to fetch current libpq version from the driver try: from config import PG_DEFAULT_DRIVER from pgadmin.utils.driver import get_driver driver = get_driver(PG_DEFAULT_DRIVER) pg_libpq_version = driver.libpq_version() except Exception as e: pg_libpq_version = 0 for submodule in current_blueprint.submodules: snippets.extend(submodule.jssnippets) return make_response( render_template('browser/js/utils.js', layout=layout, jssnippets=snippets, pg_help_path=pg_help_path, edbas_help_path=edbas_help_path, editor_tab_size=editor_tab_size, editor_use_spaces=editor_use_spaces, editor_wrap_code=editor_wrap_code, editor_brace_matching=brace_matching, editor_insert_pair_brackets=insert_pair_brackets, editor_indent_with_tabs=editor_indent_with_tabs, app_name=config.APP_NAME, pg_libpq_version=pg_libpq_version, support_ssh_tunnel=config.SUPPORT_SSH_TUNNEL), 200, {'Content-Type': 'application/x-javascript'})
def browser_js(): layout = get_setting('Browser/Layout', default='') snippets = [] for submodule in current_blueprint.submodules: snippets.extend(submodule.jssnippets) return make_response( render_template('browser/js/browser.js', layout=layout, jssnippets=snippets, _=gettext), 200, {'Content-Type': 'application/x-javascript'})
def browser_js(): layout = get_setting('Browser/Layout', default='') snippets = [] for submodule in current_blueprint.submodules: snippets.extend(submodule.jssnippets) return make_response( render_template( 'browser/js/browser.js', layout=layout, jssnippets=snippets), 200, {'Content-Type': 'application/x-javascript'})
def utils(): layout = get_setting('Browser/Layout', default='') snippets = [] prefs = Preferences.module('paths') pg_help_path_pref = prefs.preference('pg_help_path') pg_help_path = pg_help_path_pref.get() edbas_help_path_pref = prefs.preference('edbas_help_path') edbas_help_path = edbas_help_path_pref.get() # Get sqleditor options prefs = Preferences.module('sqleditor') editor_tab_size_pref = prefs.preference('tab_size') editor_tab_size = editor_tab_size_pref.get() editor_use_spaces_pref = prefs.preference('use_spaces') editor_use_spaces = editor_use_spaces_pref.get() editor_wrap_code_pref = prefs.preference('wrap_code') editor_wrap_code = editor_wrap_code_pref.get() brace_matching_pref = prefs.preference('brace_matching') brace_matching = brace_matching_pref.get() insert_pair_brackets_perf = prefs.preference('insert_pair_brackets') insert_pair_brackets = insert_pair_brackets_perf.get() for submodule in current_blueprint.submodules: snippets.extend(submodule.jssnippets) return make_response( render_template( 'browser/js/utils.js', layout=layout, jssnippets=snippets, pg_help_path=pg_help_path, edbas_help_path=edbas_help_path, editor_tab_size=editor_tab_size, editor_use_spaces=editor_use_spaces, editor_wrap_code=editor_wrap_code, editor_brace_matching=brace_matching, editor_insert_pair_brackets=insert_pair_brackets, app_name=config.APP_NAME ), 200, {'Content-Type': 'application/x-javascript'})
def browser_js(): layout = get_setting('Browser/Layout', default='') snippets = [] prefs = Preferences.module('paths') pg_help_path_pref = prefs.preference('pg_help_path') pg_help_path = pg_help_path_pref.get() edbas_help_path_pref = prefs.preference('edbas_help_path') edbas_help_path = edbas_help_path_pref.get() # Get sqleditor options prefs = Preferences.module('sqleditor') editor_tab_size_pref = prefs.preference('tab_size') editor_tab_size = editor_tab_size_pref.get() editor_use_spaces_pref = prefs.preference('use_spaces') editor_use_spaces = editor_use_spaces_pref.get() editor_wrap_code_pref = prefs.preference('wrap_code') editor_wrap_code = editor_wrap_code_pref.get() for submodule in current_blueprint.submodules: snippets.extend(submodule.jssnippets) return make_response( render_template( 'browser/js/browser.js', layout=layout, jssnippets=snippets, pg_help_path=pg_help_path, edbas_help_path=edbas_help_path, editor_tab_size=editor_tab_size, editor_use_spaces=editor_use_spaces, editor_wrap_code=editor_wrap_code, _=gettext ), 200, {'Content-Type': 'application/x-javascript'})
def browser_js(): layout = get_setting('Browser/Layout', default='') snippets = [] prefs = Preferences.module('paths') pg_help_path_pref = prefs.preference('pg_help_path') pg_help_path = pg_help_path_pref.get() edbas_help_path_pref = prefs.preference('edbas_help_path') edbas_help_path = edbas_help_path_pref.get() for submodule in current_blueprint.submodules: snippets.extend(submodule.jssnippets) return make_response( render_template( 'browser/js/browser.js', layout=layout, jssnippets=snippets, pg_help_path=pg_help_path, edbas_help_path=edbas_help_path, _=gettext ), 200, {'Content-Type': 'application/x-javascript'})
def _save_import_export_settings(settings): settings = {key: settings[key] for key in settings if key not in ['icolumns', 'columns', 'database', 'schema', 'table', 'save_btn_icon']} if settings['is_import']: settings['import_file_name'] = settings['filename'] else: settings['export_file_name'] = settings['filename'] # Get existing setting - old_settings = get_setting('import_export_setting') if old_settings and old_settings != 'null': old_settings = json.loads(old_settings) old_settings.update(settings) settings = json.dumps(settings) else: if 'import_file_name' not in settings: settings['import_file_name'] = '' elif 'export_file_name' not in settings: settings['export_file_name'] = '' settings = json.dumps(settings) store_setting('import_export_setting', settings)
def panel(trans_id): """ This method calls index.html to render the data grid. Args: trans_id: unique transaction id """ url_params = None if request.args: url_params = {k: v for k, v in request.args.items()} if request.form: url_params['title'] = request.form['title'] if 'sql_filter' in request.form: url_params['sql_filter'] = request.form['sql_filter'] if 'query_url' in request.form: url_params['query_url'] = request.form['query_url'] # We need client OS information to render correct Keyboard shortcuts user_agent = UserAgent(request.headers.get('User-Agent')) """ Animations and transitions are not automatically GPU accelerated and by default use browser's slow rendering engine. We need to set 'translate3d' value of '-webkit-transform' property in order to use GPU. After applying this property under linux, Webkit calculates wrong position of the elements so panel contents are not visible. To make it work, we need to explicitly set '-webkit-transform' property to 'none' for .ajs-notifier, .ajs-message, .ajs-modal classes. This issue is only with linux runtime application and observed in Query tool and debugger. When we open 'Open File' dialog then whole Query tool panel content is not visible though it contains HTML element in back end. The port number should have already been set by the runtime if we're running in desktop mode. """ is_linux_platform = False from sys import platform as _platform if "linux" in _platform: is_linux_platform = True # Fetch the server details bgcolor = None fgcolor = None s = Server.query.filter_by(id=url_params['sid']).first() if s and s.bgcolor: # If background is set to white means we do not have to change # the title background else change it as per user specified # background if s.bgcolor != '#ffffff': bgcolor = s.bgcolor fgcolor = s.fgcolor or 'black' layout = get_setting('SQLEditor/Layout') return render_template( "datagrid/index.html", _=gettext, uniqueId=trans_id, is_desktop_mode=app.PGADMIN_RUNTIME, is_linux=is_linux_platform, title=underscore_unescape(url_params['title']), url_params=json.dumps(url_params), client_platform=user_agent.platform, bgcolor=bgcolor, fgcolor=fgcolor, layout=layout, )
def index(): """Render and process the main browser window.""" # Register Gravatar module with the app only if required if config.SHOW_GRAVATAR_IMAGE: Gravatar(current_app, size=100, rating='g', default='retro', force_default=False, use_ssl=True, base_url=None) # Check the browser is a supported version # NOTE: If the checks here are updated, make sure the supported versions # at https://www.pgadmin.org/faq/#11 are updated to match! if config.CHECK_SUPPORTED_BROWSER: browser_name, browser_known, version = _get_supported_browser() if browser_name is not None: msg = render_template(MODULE_NAME + "/browser.html", version=version, browser=browser_name, known=browser_known) flash(msg, 'warning') # Get the current version info from the website, and flash a message if # the user is out of date, and the check is enabled. if config.UPGRADE_CHECK_ENABLED: last_check = get_setting('LastUpdateCheck', default='0') today = time.strftime('%Y%m%d') if int(last_check) < int(today): check_browser_upgrade() store_setting('LastUpdateCheck', today) auth_only_internal = False auth_source = [] session['allow_save_password'] = True if config.SERVER_MODE: if len(config.AUTHENTICATION_SOURCES) == 1\ and INTERNAL in config.AUTHENTICATION_SOURCES: auth_only_internal = True auth_source = session['_auth_source_manager_obj'][ 'source_friendly_name'] if session['_auth_source_manager_obj']['current_source'] == KERBEROS: session['allow_save_password'] = False response = Response( render_template(MODULE_NAME + "/index.html", username=current_user.username, auth_source=auth_source, is_admin=current_user.has_role("Administrator"), logout_url=_get_logout_url(), _=gettext, auth_only_internal=auth_only_internal)) # Set the language cookie after login, so next time the user will have that # same option at the login time. misc_preference = Preferences.module('misc') user_languages = misc_preference.preference('user_language') language = 'en' if user_languages: language = user_languages.get() or 'en' domain = dict() if config.COOKIE_DEFAULT_DOMAIN and\ config.COOKIE_DEFAULT_DOMAIN != 'localhost': domain['domain'] = config.COOKIE_DEFAULT_DOMAIN response.set_cookie("PGADMIN_LANGUAGE", value=language, path=config.COOKIE_DEFAULT_PATH, secure=config.SESSION_COOKIE_SECURE, httponly=config.SESSION_COOKIE_HTTPONLY, samesite=config.SESSION_COOKIE_SAMESITE, **domain) return response
def utils(): layout = get_setting('Browser/Layout', default='') snippets = [] prefs = Preferences.module('paths') pg_help_path_pref = prefs.preference('pg_help_path') pg_help_path = pg_help_path_pref.get() # Get sqleditor options prefs = Preferences.module('sqleditor') editor_tab_size_pref = prefs.preference('tab_size') editor_tab_size = editor_tab_size_pref.get() editor_use_spaces_pref = prefs.preference('use_spaces') editor_use_spaces = editor_use_spaces_pref.get() editor_wrap_code_pref = prefs.preference('wrap_code') editor_wrap_code = editor_wrap_code_pref.get() brace_matching_pref = prefs.preference('brace_matching') brace_matching = brace_matching_pref.get() insert_pair_brackets_perf = prefs.preference('insert_pair_brackets') insert_pair_brackets = insert_pair_brackets_perf.get() # This will be opposite of use_space option editor_indent_with_tabs = False if editor_use_spaces else True # Try to fetch current libpq version from the driver try: from config import PG_DEFAULT_DRIVER from pgadmin.utils.driver import get_driver driver = get_driver(PG_DEFAULT_DRIVER) pg_libpq_version = driver.libpq_version() except Exception: pg_libpq_version = 0 for submodule in current_blueprint.submodules: snippets.extend(submodule.jssnippets) return make_response( render_template('browser/js/utils.js', layout=layout, jssnippets=snippets, pg_help_path=pg_help_path, editor_tab_size=editor_tab_size, editor_use_spaces=editor_use_spaces, editor_wrap_code=editor_wrap_code, editor_brace_matching=brace_matching, editor_insert_pair_brackets=insert_pair_brackets, editor_indent_with_tabs=editor_indent_with_tabs, app_name=config.APP_NAME, app_version_int=config.APP_VERSION_INT, pg_libpq_version=pg_libpq_version, support_ssh_tunnel=config.SUPPORT_SSH_TUNNEL, logout_url=get_logout_url(), platform=sys.platform, qt_default_placeholder=QT_DEFAULT_PLACEHOLDER, enable_psql=config.ENABLE_PSQL), 200, {'Content-Type': MIMETYPE_APP_JS})
def utils(): layout = get_setting('Browser/Layout', default='') snippets = [] prefs = Preferences.module('paths') pg_help_path_pref = prefs.preference('pg_help_path') pg_help_path = pg_help_path_pref.get() edbas_help_path_pref = prefs.preference('edbas_help_path') edbas_help_path = edbas_help_path_pref.get() # Get sqleditor options prefs = Preferences.module('sqleditor') editor_tab_size_pref = prefs.preference('tab_size') editor_tab_size = editor_tab_size_pref.get() editor_use_spaces_pref = prefs.preference('use_spaces') editor_use_spaces = editor_use_spaces_pref.get() editor_wrap_code_pref = prefs.preference('wrap_code') editor_wrap_code = editor_wrap_code_pref.get() brace_matching_pref = prefs.preference('brace_matching') brace_matching = brace_matching_pref.get() insert_pair_brackets_perf = prefs.preference('insert_pair_brackets') insert_pair_brackets = insert_pair_brackets_perf.get() # This will be opposite of use_space option editor_indent_with_tabs = False if editor_use_spaces else True # Try to fetch current libpq version from the driver try: from config import PG_DEFAULT_DRIVER from pgadmin.utils.driver import get_driver driver = get_driver(PG_DEFAULT_DRIVER) pg_libpq_version = driver.libpq_version() except Exception as e: pg_libpq_version = 0 for submodule in current_blueprint.submodules: snippets.extend(submodule.jssnippets) return make_response( render_template( 'browser/js/utils.js', layout=layout, jssnippets=snippets, pg_help_path=pg_help_path, edbas_help_path=edbas_help_path, editor_tab_size=editor_tab_size, editor_use_spaces=editor_use_spaces, editor_wrap_code=editor_wrap_code, editor_brace_matching=brace_matching, editor_insert_pair_brackets=insert_pair_brackets, editor_indent_with_tabs=editor_indent_with_tabs, app_name=config.APP_NAME, pg_libpq_version=pg_libpq_version, support_ssh_tunnel=config.SUPPORT_SSH_TUNNEL ), 200, {'Content-Type': 'application/x-javascript'})
def panel(trans_id, is_query_tool, editor_title): """ This method calls index.html to render the data grid. Args: trans_id: unique transaction id is_query_tool: True if panel calls when query tool menu is clicked. editor_title: Title of the editor """ # Let's fetch Script type URL from request if request.args and request.args['query_url'] != '': sURL = request.args['query_url'] else: sURL = None # Fetch server type from request if request.args and request.args['server_type'] != '': server_type = request.args['server_type'] else: server_type = None # If title has slash(es) in it then replace it if request.args and request.args['fslashes'] != '': try: fslashesList = request.args['fslashes'].split(',') for idx in fslashesList: idx = int(idx) editor_title = editor_title[:idx] + '/' + editor_title[idx:] except IndexError as e: app.logger.exception(e) # We need client OS information to render correct Keyboard shortcuts user_agent = UserAgent(request.headers.get('User-Agent')) """ Animations and transitions are not automatically GPU accelerated and by default use browser's slow rendering engine. We need to set 'translate3d' value of '-webkit-transform' property in order to use GPU. After applying this property under linux, Webkit calculates wrong position of the elements so panel contents are not visible. To make it work, we need to explicitly set '-webkit-transform' property to 'none' for .ajs-notifier, .ajs-message, .ajs-modal classes. This issue is only with linux runtime application and observed in Query tool and debugger. When we open 'Open File' dialog then whole Query tool panel content is not visible though it contains HTML element in back end. The port number should have already been set by the runtime if we're running in desktop mode. """ is_linux_platform = False from sys import platform as _platform if "linux" in _platform: is_linux_platform = True # Fetch the server details bgcolor = None fgcolor = None if 'gridData' in session and str(trans_id) in session['gridData']: # Fetch the object for the specified transaction id. # Use pickle.loads function to get the command object session_obj = session['gridData'][str(trans_id)] trans_obj = pickle.loads(session_obj['command_obj']) s = Server.query.filter_by(id=trans_obj.sid).first() if s and s.bgcolor: # If background is set to white means we do not have to change # the title background else change it as per user specified # background if s.bgcolor != '#ffffff': bgcolor = s.bgcolor fgcolor = s.fgcolor or 'black' layout = get_setting('SQLEditor/Layout') url_params = dict() if is_query_tool == 'true': url_params['sgid'] = trans_obj.sgid url_params['sid'] = trans_obj.sid url_params['did'] = trans_obj.did else: url_params['cmd_type'] = trans_obj.cmd_type url_params['obj_type'] = trans_obj.object_type url_params['sgid'] = trans_obj.sgid url_params['sid'] = trans_obj.sid url_params['did'] = trans_obj.did url_params['obj_id'] = trans_obj.obj_id return render_template( "datagrid/index.html", _=gettext, uniqueId=trans_id, is_query_tool=is_query_tool, editor_title=editor_title, script_type_url=sURL, is_desktop_mode=app.PGADMIN_RUNTIME, is_linux=is_linux_platform, server_type=server_type, client_platform=user_agent.platform, bgcolor=bgcolor, fgcolor=fgcolor, url_params=json.dumps(url_params), layout=layout, )