From d9f6baac72d94570f1ae8d7792f9735397dd0d99 Mon Sep 17 00:00:00 2001 From: Ashesh Vashi Date: Wed, 8 Apr 2020 14:14:25 +0530 Subject: [PATCH] Various misc fixes: - Using the 'gettext' as oppose to '_', which is not defined - Define missing variables - Fixed escape character in string with double quote - Removed some dead code in a test case - Removed unnecessary self assignment Includes some fixes for Accessibility improvements - Use semantic markup to mark emphasized or special text - Added hidden legend in
for better screen reader support --- .../browser/server_groups/servers/__init__.py | 2 +- .../databases/schemas/packages/__init__.py | 3 +- .../servers/resource_groups/__init__.py | 4 +-- .../servers/roles/tests/utils.py | 31 +------------------ .../servers/tablespaces/__init__.py | 4 +-- web/pgadmin/misc/file_manager/__init__.py | 3 -- web/pgadmin/settings/__init__.py | 2 +- .../templates/security/change_password.html | 3 +- .../templates/security/forgot_password.html | 1 + web/pgadmin/templates/security/panel.html | 2 +- .../templates/security/reset_password.html | 1 + .../debugger/templates/debugger/direct.html | 12 +++---- web/pgadmin/tools/schema_diff/__init__.py | 12 +++---- web/pgadmin/tools/search_objects/__init__.py | 2 +- web/pgadmin/tools/sqleditor/__init__.py | 5 +-- 15 files changed, 28 insertions(+), 59 deletions(-) diff --git a/web/pgadmin/browser/server_groups/servers/__init__.py b/web/pgadmin/browser/server_groups/servers/__init__.py index c4db10fa4..5d7895652 100644 --- a/web/pgadmin/browser/server_groups/servers/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/__init__.py @@ -1506,7 +1506,7 @@ class ServerNode(PGChildNodeView): conn = manager.connection() if not conn.connected(): return gone( - errormsg=_('Please connect the server.') + errormsg=gettext('Please connect the server.') ) if not server.password or not manager.password: diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/__init__.py index ef18d1d30..e26de7c82 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/__init__.py @@ -259,6 +259,7 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare): Returns: """ + res = [] SQL = render_template( "/".join([self.template_path, 'properties.sql']), scid=scid, pkgid=pkgid @@ -778,7 +779,7 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare): if sql is None: return None start = 0 - start_position = re.search("\s+[is|as]+\s+", sql, flags=re.I) + start_position = re.search("\\s+[is|as]+\\s+", sql, flags=re.I) if start_position: start = start_position.start() + 4 diff --git a/web/pgadmin/browser/server_groups/servers/resource_groups/__init__.py b/web/pgadmin/browser/server_groups/servers/resource_groups/__init__.py index b65f6d9b6..337e55cc4 100644 --- a/web/pgadmin/browser/server_groups/servers/resource_groups/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/resource_groups/__init__.py @@ -588,7 +588,7 @@ class ResourceGroupView(NodeView): if len(res['rows']) == 0: return gone( - _("The specified resource group could not be found.") + gettext("The specified resource group could not be found.") ) old_data = res['rows'][0] for arg in required_args: @@ -655,7 +655,7 @@ class ResourceGroupView(NodeView): return internal_server_error(errormsg=res) if len(res['rows']) == 0: return gone( - _("The specified resource group could not be found.") + gettext("The specified resource group could not be found.") ) # Making copy of output for future use diff --git a/web/pgadmin/browser/server_groups/servers/roles/tests/utils.py b/web/pgadmin/browser/server_groups/servers/roles/tests/utils.py index 4bd627b46..2c37fc7bc 100644 --- a/web/pgadmin/browser/server_groups/servers/roles/tests/utils.py +++ b/web/pgadmin/browser/server_groups/servers/roles/tests/utils.py @@ -60,13 +60,12 @@ def test_getrole(tester): server_ids = all_id["sid"] role_ids_dict = all_id["lrid"][0] - server_group = config_data['server_group'] role_response_data = [] for server_id in server_ids: role_id = role_ids_dict[int(server_id)] role_response_data.append( - verify_role(tester, server_group, server_id, role_id)) + verify_role(server_id, role_id)) return role_response_data @@ -122,34 +121,6 @@ def create_role(server, role_name): print(exception, file=sys.stderr) -def write_role_id(response_data): - """ - - :param response_data: - :return: - """ - - lr_id = response_data['node']['_id'] - server_id = response_data['node']['_pid'] - pickle_id_dict = utils.get_pickle_id_dict() - # TODO: modify logic to write in file / file exists or create new check - # old file - if os.path.isfile(pickle_path): - existing_server_id = open(pickle_path, 'rb') - tol_server_id = pickle.load(existing_server_id) - pickle_id_dict = tol_server_id - if 'lrid' in pickle_id_dict: - if pickle_id_dict['lrid']: - # Add the db_id as value in dict - pickle_id_dict["lrid"][0].update({server_id: lr_id}) - else: - # Create new dict with server_id and db_id - pickle_id_dict["lrid"].append({server_id: lr_id}) - db_output = open(pickle_path, 'wb') - pickle.dump(pickle_id_dict, db_output) - db_output.close() - - def delete_role(connection, role_names): """ This function use to delete the existing roles in the servers diff --git a/web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py b/web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py index fe227d7ab..62436aa88 100644 --- a/web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py @@ -485,7 +485,7 @@ class TablespaceView(PGChildNodeView): if len(res['rows']) == 0: return gone( - _("Could not find the tablespace on the server.") + gettext("Could not find the tablespace on the server.") ) # Making copy of output for further processing @@ -550,7 +550,7 @@ class TablespaceView(PGChildNodeView): if len(res['rows']) == 0: return gone( - _("Could not find the tablespace on the server.") + gettext("Could not find the tablespace on the server.") ) # Making copy of output for future use old_data = dict(res['rows'][0]) diff --git a/web/pgadmin/misc/file_manager/__init__.py b/web/pgadmin/misc/file_manager/__init__.py index c3bd72b4d..0be67e465 100644 --- a/web/pgadmin/misc/file_manager/__init__.py +++ b/web/pgadmin/misc/file_manager/__init__.py @@ -365,7 +365,6 @@ class Filemanager(object): if 'supported_types' in params else [] if fm_type == 'select_file': capabilities = ['select_file', 'rename', 'upload', 'create'] - supp_types = supp_types files_only = True folders_only = False title = "Select File" @@ -376,14 +375,12 @@ class Filemanager(object): title = "Select Folder" elif fm_type == 'create_file': capabilities = ['select_file', 'rename', 'create'] - supp_types = supp_types files_only = True folders_only = False title = "Create File" elif fm_type == 'storage_dialog': capabilities = ['select_folder', 'select_file', 'download', 'rename', 'delete', 'upload', 'create'] - supp_types = supp_types files_only = True folders_only = False title = "Storage Manager" diff --git a/web/pgadmin/settings/__init__.py b/web/pgadmin/settings/__init__.py index b987d264a..69f037bc5 100644 --- a/web/pgadmin/settings/__init__.py +++ b/web/pgadmin/settings/__init__.py @@ -86,7 +86,7 @@ def get_setting(setting, default=''): @blueprint.route("/") @login_required def index(): - return bad_request(errormsg=_("This URL cannot be called directly.")) + return bad_request(errormsg=gettext("This URL cannot be called directly.")) @blueprint.route("/settings.js") diff --git a/web/pgadmin/templates/security/change_password.html b/web/pgadmin/templates/security/change_password.html index 2de189bc1..0420e9059 100644 --- a/web/pgadmin/templates/security/change_password.html +++ b/web/pgadmin/templates/security/change_password.html @@ -6,13 +6,14 @@
-
{{ _('%(appname)s', appname=config.APP_NAME) }}
+
{{ _('%(appname)s', appname=config.APP_NAME) }}
{{ _('Password Change') }}
{% if config.SERVER_MODE %}
{{ change_password_form.hidden_tag() }}
+ {{ _('Change Password Form') }} {{ render_field_with_errors(change_password_form.password, "password") }} {{ render_field_with_errors(change_password_form.new_password, "password") }} {{ render_field_with_errors(change_password_form.new_password_confirm, "password") }} diff --git a/web/pgadmin/templates/security/forgot_password.html b/web/pgadmin/templates/security/forgot_password.html index c43b633a4..8098f3db6 100644 --- a/web/pgadmin/templates/security/forgot_password.html +++ b/web/pgadmin/templates/security/forgot_password.html @@ -11,6 +11,7 @@ {{ forgot_password_form.hidden_tag() }}
+ {{ _('Forget Password Form') }} {{ render_field_with_errors(forgot_password_form.email, "text") }} diff --git a/web/pgadmin/templates/security/panel.html b/web/pgadmin/templates/security/panel.html index 1452de8ca..b93e2914f 100644 --- a/web/pgadmin/templates/security/panel.html +++ b/web/pgadmin/templates/security/panel.html @@ -11,7 +11,7 @@
{% block panel_image %}{% endblock %}
-
{{ _('%(appname)s', appname=config.APP_NAME) }}
+
{{ _('%(appname)s', appname=config.APP_NAME) }}
{% block panel_title %}{% endblock %}
{% block panel_body %} diff --git a/web/pgadmin/templates/security/reset_password.html b/web/pgadmin/templates/security/reset_password.html index 2713a163f..2023eb351 100644 --- a/web/pgadmin/templates/security/reset_password.html +++ b/web/pgadmin/templates/security/reset_password.html @@ -6,6 +6,7 @@ name="reset_password_form"> {{ reset_password_form.hidden_tag() }}
+ {{ _('Reset Password Form') }} {{ render_field_with_errors(reset_password_form.password, "password") }} {{ render_field_with_errors(reset_password_form.password_confirm, "password") }} - +
@@ -84,7 +84,7 @@ try { tabindex="0" aria-label="{{ gettext('Toggle breakpoint') }}" disabled> - +
@@ -102,7 +102,7 @@ try { tabindex="0" aria-label="{{ gettext('Stop') }}" disabled> - +
diff --git a/web/pgadmin/tools/schema_diff/__init__.py b/web/pgadmin/tools/schema_diff/__init__.py index 1d1ff369a..a0ebacbaf 100644 --- a/web/pgadmin/tools/schema_diff/__init__.py +++ b/web/pgadmin/tools/schema_diff/__init__.py @@ -8,9 +8,6 @@ ########################################################################## """A blueprint module implementing the schema_diff frame.""" - -MODULE_NAME = 'schema_diff' - import simplejson as json import pickle import random @@ -28,6 +25,8 @@ from pgadmin.tools.schema_diff.model import SchemaDiffModel from config import PG_DEFAULT_DRIVER from pgadmin.utils.driver import get_driver +MODULE_NAME = 'schema_diff' + class SchemaDiffModule(PgAdminModule): """ @@ -567,15 +566,16 @@ def check_version_compatibility(sid, tid): tar_server = Server.query.filter_by(id=tid).first() tar_manager = driver.connection_manager(tar_server.id) + target_conn = src_manager.connection() + + if not (src_conn.connected() and target.connected()): + return False, gettext('Server(s) disconnected.') if src_manager.server_type != tar_manager.server_type: return False, gettext('Schema diff does not support the comparison ' 'between Postgres Server and EDB Postgres ' 'Advanced Server.') - if not (src_conn.connected() or src_conn.connected()): - return False, gettext('Server(s) disconnected.') - def get_round_val(x): if x < 10000: return x if x % 100 == 0 else x + 100 - x % 100 diff --git a/web/pgadmin/tools/search_objects/__init__.py b/web/pgadmin/tools/search_objects/__init__.py index e8bd59141..3dafd6292 100644 --- a/web/pgadmin/tools/search_objects/__init__.py +++ b/web/pgadmin/tools/search_objects/__init__.py @@ -56,7 +56,7 @@ blueprint = SearchObjectsModule( @blueprint.route("/", endpoint='index') @login_required def index(): - return bad_request(errormsg=_("This URL cannot be called directly.")) + return bad_request(errormsg=gettext("This URL cannot be called directly.")) @blueprint.route("types//", endpoint='types') diff --git a/web/pgadmin/tools/sqleditor/__init__.py b/web/pgadmin/tools/sqleditor/__init__.py index 2ea5dc780..7ecbb4845 100644 --- a/web/pgadmin/tools/sqleditor/__init__.py +++ b/web/pgadmin/tools/sqleditor/__init__.py @@ -1296,10 +1296,7 @@ def save_file(): else: output_file.write(file_content) except IOError as e: - if e.strerror == 'Permission denied': - err_msg = "Error: {0}".format(e.strerror) - else: - err_msg = "Error: {0}".format(e.strerror) + err_msg = "Error: {0}".format(e.strerror) return internal_server_error(errormsg=err_msg) except Exception as e: err_msg = "Error: {0}".format(e.strerror)