Fixed code smell 'String literals should not be duplicated'.

This commit is contained in:
Yogesh Mahajan 2020-08-28 18:17:27 +05:30 committed by Akshay Joshi
parent e226b2fa75
commit 3984544bdb
13 changed files with 88 additions and 164 deletions

View File

@ -30,7 +30,8 @@ from pgadmin.utils.exception import CryptKeyMissing
from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry
from psycopg2 import Error as psycopg2_Error, OperationalError from psycopg2 import Error as psycopg2_Error, OperationalError
from pgadmin.browser.server_groups.servers.utils import is_valid_ipaddress from pgadmin.browser.server_groups.servers.utils import is_valid_ipaddress
from pgadmin.utils.constants import UNAUTH_REQ, MIMETYPE_APP_JS from pgadmin.utils.constants import UNAUTH_REQ, MIMETYPE_APP_JS, \
SERVER_CONNECTION_CLOSED
def has_any(data, keys): def has_any(data, keys):
@ -1224,9 +1225,7 @@ class ServerNode(PGChildNodeView):
else: else:
return make_json_response(data={ return make_json_response(data={
'status': False, 'status': False,
'result': gettext( 'result': SERVER_CONNECTION_CLOSED})
'Not connected to the server or the connection to the'
' server has been closed.')})
def create_restore_point(self, gid, sid): def create_restore_point(self, gid, sid):
""" """

View File

@ -208,6 +208,7 @@ class SchemaView(PGChildNodeView):
""" """
node_type = schema_blueprint.node_type node_type = schema_blueprint.node_type
_SQL_PREFIX = 'sql/' _SQL_PREFIX = 'sql/'
node_icon = 'icon-%s' % node_type
parent_ids = [ parent_ids = [
{'type': 'int', 'id': 'gid'}, {'type': 'int', 'id': 'gid'},
@ -455,8 +456,6 @@ class SchemaView(PGChildNodeView):
if not status: if not status:
return internal_server_error(errormsg=rset) return internal_server_error(errormsg=rset)
icon = 'icon-{0}'.format(self.node_type)
if scid is not None: if scid is not None:
if len(rset['rows']) == 0: if len(rset['rows']) == 0:
return gone(gettext( return gone(gettext(
@ -468,7 +467,7 @@ class SchemaView(PGChildNodeView):
row['oid'], row['oid'],
did, did,
row['name'], row['name'],
icon=icon, icon=self.node_icon,
can_create=row['can_create'], can_create=row['can_create'],
has_usage=row['has_usage'] has_usage=row['has_usage']
), ),
@ -481,7 +480,7 @@ class SchemaView(PGChildNodeView):
row['oid'], row['oid'],
did, did,
row['name'], row['name'],
icon=icon, icon=self.node_icon,
can_create=row['can_create'], can_create=row['can_create'],
has_usage=row['has_usage'] has_usage=row['has_usage']
) )
@ -523,15 +522,13 @@ Could not find the schema in the database.
It may have been removed by another user. It may have been removed by another user.
""")) """))
icon = 'icon-{0}'.format(self.node_type)
for row in rset['rows']: for row in rset['rows']:
return make_json_response( return make_json_response(
data=self.blueprint.generate_browser_node( data=self.blueprint.generate_browser_node(
row['oid'], row['oid'],
did, did,
row['name'], row['name'],
icon=icon, icon=self.node_icon,
can_create=row['can_create'], can_create=row['can_create'],
has_usage=row['has_usage'] has_usage=row['has_usage']
), ),
@ -635,14 +632,12 @@ It may have been removed by another user.
if not status: if not status:
return internal_server_error(errormsg=scid) return internal_server_error(errormsg=scid)
icon = 'icon-{0}'.format(self.node_type)
return jsonify( return jsonify(
node=self.blueprint.generate_browser_node( node=self.blueprint.generate_browser_node(
scid, scid,
did, did,
data['name'], data['name'],
icon=icon icon=self.node_icon
) )
) )
except Exception as e: except Exception as e:
@ -676,7 +671,7 @@ It may have been removed by another user.
scid, scid,
did, did,
name, name,
icon="icon-%s" % self.node_type icon=self.node_icon
) )
) )
except Exception as e: except Exception as e:

View File

@ -83,6 +83,7 @@ blueprint = PackageModule(__name__)
class PackageView(PGChildNodeView, SchemaDiffObjectCompare): class PackageView(PGChildNodeView, SchemaDiffObjectCompare):
node_type = blueprint.node_type node_type = blueprint.node_type
node_label = "Package" node_label = "Package"
node_icon = "icon-%s" % node_type
parent_ids = [ parent_ids = [
{'type': 'int', 'id': 'gid'}, {'type': 'int', 'id': 'gid'},
@ -223,7 +224,7 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare):
row['oid'], row['oid'],
scid, scid,
row['name'], row['name'],
icon="icon-%s" % self.node_type icon=self.node_icon
) )
) )
@ -233,7 +234,7 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare):
row['oid'], row['oid'],
scid, scid,
row['name'], row['name'],
icon="icon-%s" % self.node_type icon=self.node_icon
)) ))
return make_json_response( return make_json_response(
@ -277,7 +278,7 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare):
row['oid'], row['oid'],
scid, scid,
row['name'], row['name'],
icon="icon-%s" % self.node_type icon=self.node_icon
)) ))
return make_json_response( return make_json_response(
@ -409,7 +410,7 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare):
pkgid, pkgid,
scid, scid,
data['name'], data['name'],
icon="icon-%s" % self.node_type icon=self.node_icon
) )
) )
@ -516,7 +517,7 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare):
pkgid, pkgid,
scid, scid,
name, name,
icon="icon-%s" % self.node_type icon=self.node_icon
) )
) )

View File

@ -91,6 +91,7 @@ blueprint = SequenceModule(__name__)
class SequenceView(PGChildNodeView, SchemaDiffObjectCompare): class SequenceView(PGChildNodeView, SchemaDiffObjectCompare):
node_type = blueprint.node_type node_type = blueprint.node_type
node_label = "Sequence" node_label = "Sequence"
node_icon = "icon-%s" % node_type
parent_ids = [ parent_ids = [
{'type': 'int', 'id': 'gid'}, {'type': 'int', 'id': 'gid'},
@ -216,7 +217,7 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare):
row['oid'], row['oid'],
scid, scid,
row['name'], row['name'],
icon="icon-%s" % self.node_type icon=self.node_icon
), ),
status=200 status=200
) )
@ -228,7 +229,7 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare):
row['oid'], row['oid'],
scid, scid,
row['name'], row['name'],
icon="icon-%s" % self.node_type icon=self.node_icon
)) ))
return make_json_response( return make_json_response(
@ -437,7 +438,7 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare):
row['oid'], row['oid'],
row['relnamespace'], row['relnamespace'],
data['name'], data['name'],
icon="icon-%s" % self.node_type icon=self.node_icon
) )
) )
@ -550,7 +551,7 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare):
seid, seid,
row['schema'], row['schema'],
row['name'], row['name'],
icon="icon-%s" % self.node_type icon=self.node_icon
) )
) )

View File

@ -201,6 +201,8 @@ class IndexConstraintView(PGChildNodeView):
node_label = _('Index constraint') node_label = _('Index constraint')
node_icon = "icon-%s" % node_type
parent_ids = [ parent_ids = [
{'type': 'int', 'id': 'gid'}, {'type': 'int', 'id': 'gid'},
{'type': 'int', 'id': 'sid'}, {'type': 'int', 'id': 'sid'},
@ -287,10 +289,7 @@ class IndexConstraintView(PGChildNodeView):
return res return res
if len(res) == 0: if len(res) == 0:
return gone(_("""Could not find the {} in the table.""").format( return gone(self.key_not_found_error_msg())
_("primary key") if self.constraint_type == "p"
else _("unique key")
))
result = res result = res
if cid: if cid:
@ -392,16 +391,13 @@ class IndexConstraintView(PGChildNodeView):
return internal_server_error(errormsg=rset) return internal_server_error(errormsg=rset)
if len(rset['rows']) == 0: if len(rset['rows']) == 0:
return gone(_("""Could not find the {} in the table.""").format( return gone(self.key_not_found_error_msg())
_("primary key") if self.constraint_type == "p"
else _("unique key")
))
res = self.blueprint.generate_browser_node( res = self.blueprint.generate_browser_node(
rset['rows'][0]['oid'], rset['rows'][0]['oid'],
tid, tid,
rset['rows'][0]['name'], rset['rows'][0]['name'],
icon="icon-%s" % self.node_type icon=self.node_icon
) )
return make_json_response( return make_json_response(
data=res, data=res,
@ -441,7 +437,7 @@ class IndexConstraintView(PGChildNodeView):
row['oid'], row['oid'],
tid, tid,
row['name'], row['name'],
icon="icon-%s" % self.node_type icon=self.node_icon
) )
) )
return make_json_response( return make_json_response(
@ -486,7 +482,7 @@ class IndexConstraintView(PGChildNodeView):
row['oid'], row['oid'],
tid, tid,
row['name'], row['name'],
icon="icon-%s" % self.node_type icon=self.node_icon
)) ))
return res return res
@ -627,7 +623,7 @@ class IndexConstraintView(PGChildNodeView):
res['rows'][0]['oid'], res['rows'][0]['oid'],
tid, tid,
data['name'], data['name'],
icon="icon-%s" % self.node_type icon=self.node_icon
) )
) )
@ -688,7 +684,7 @@ class IndexConstraintView(PGChildNodeView):
cid, cid,
tid, tid,
name, name,
icon="icon-%s" % self.node_type icon=self.node_icon
) )
) )
except Exception as e: except Exception as e:
@ -844,10 +840,7 @@ class IndexConstraintView(PGChildNodeView):
if not status: if not status:
return internal_server_error(errormsg=res) return internal_server_error(errormsg=res)
if len(res['rows']) == 0: if len(res['rows']) == 0:
return gone(_("""Could not find the {} in the table.""").format( return gone(self.key_not_found_error_msg())
_("primary key") if self.constraint_type == "p"
else _("unique key")
))
data = res['rows'][0] data = res['rows'][0]
data['schema'] = self.schema data['schema'] = self.schema
@ -936,12 +929,7 @@ class IndexConstraintView(PGChildNodeView):
if not status: if not status:
return internal_server_error(errormsg=res) return internal_server_error(errormsg=res)
if len(res['rows']) == 0: if len(res['rows']) == 0:
return gone( return gone(self.key_not_found_error_msg())
_("""Could not find the {} in the table.""").format(
_("primary key") if self.constraint_type == "p"
else _("unique key")
)
)
result = res['rows'][0] result = res['rows'][0]
name = result['name'] name = result['name']
@ -1010,6 +998,12 @@ class IndexConstraintView(PGChildNodeView):
status=200 status=200
) )
def key_not_found_error_msg(self):
return _("""Could not find the {} in the table.""").format(
_("primary key") if self.constraint_type == "p"
else _("unique key")
)
class PrimaryKeyConstraintView(IndexConstraintView): class PrimaryKeyConstraintView(IndexConstraintView):
node_type = 'primary_key' node_type = 'primary_key'

View File

@ -34,7 +34,7 @@ from pgadmin.tools.debugger.utils.debugger_instance import DebuggerInstance
from pgadmin.browser.server_groups.servers.databases.extensions.utils \ from pgadmin.browser.server_groups.servers.databases.extensions.utils \
import get_extension_details import get_extension_details
from pgadmin.utils.constants import PREF_LABEL_DISPLAY, \ from pgadmin.utils.constants import PREF_LABEL_DISPLAY, \
PREF_LABEL_KEYBOARD_SHORTCUTS, MIMETYPE_APP_JS PREF_LABEL_KEYBOARD_SHORTCUTS, MIMETYPE_APP_JS, SERVER_CONNECTION_CLOSED
MODULE_NAME = 'debugger' MODULE_NAME = 'debugger'
@ -870,10 +870,7 @@ def restart_debugging(trans_id):
return make_json_response( return make_json_response(
data={ data={
'status': False, 'status': False,
'result': gettext( 'result': SERVER_CONNECTION_CLOSED
'Not connected to server or connection with the server '
'has been closed.'
)
} }
) )
@ -913,10 +910,7 @@ def restart_debugging(trans_id):
) )
else: else:
status = False status = False
result = gettext( result = SERVER_CONNECTION_CLOSED
'Not connected to server or connection with the server has '
'been closed.'
)
return make_json_response(data={'status': status, 'result': result}) return make_json_response(data={'status': status, 'result': result})
@ -942,10 +936,7 @@ def start_debugger_listener(trans_id):
return make_json_response( return make_json_response(
data={ data={
'status': False, 'status': False,
'result': gettext( 'result': SERVER_CONNECTION_CLOSED
'Not connected to server or connection with the server '
'has been closed.'
)
} }
) )
@ -1140,19 +1131,13 @@ def start_debugger_listener(trans_id):
) )
else: else:
status = False status = False
result = gettext( result = SERVER_CONNECTION_CLOSED
'Not connected to server or connection with the server '
'has been closed.'
)
return make_json_response( return make_json_response(
data={'status': status, 'result': result} data={'status': status, 'result': result}
) )
else: else:
status = False status = False
result = gettext( result = SERVER_CONNECTION_CLOSED
'Not connected to server or connection with the server has '
'been closed.'
)
return make_json_response(data={'status': status, 'result': result}) return make_json_response(data={'status': status, 'result': result})
@ -1185,10 +1170,7 @@ def execute_debugger_query(trans_id, query_type):
return make_json_response( return make_json_response(
data={ data={
'status': False, 'status': False,
'result': gettext( 'result': SERVER_CONNECTION_CLOSED
'Not connected to server or connection with the server '
'has been closed.'
)
} }
) )
@ -1204,8 +1186,7 @@ def execute_debugger_query(trans_id, query_type):
else DEBUGGER_SQL_V3_PATH else DEBUGGER_SQL_V3_PATH
if not conn.connected(): if not conn.connected():
result = gettext('Not connected to server or connection ' result = SERVER_CONNECTION_CLOSED
'with the server has been closed.')
return internal_server_error(errormsg=result) return internal_server_error(errormsg=result)
sql = render_template( sql = render_template(
@ -1264,10 +1245,7 @@ def messages(trans_id):
return make_json_response( return make_json_response(
data={ data={
'status': 'NotConnected', 'status': 'NotConnected',
'result': gettext( 'result': SERVER_CONNECTION_CLOSED
'Not connected to server or connection with the server '
'has been closed.'
)
} }
) )
@ -1302,10 +1280,7 @@ def messages(trans_id):
data={'status': status, 'result': port_number} data={'status': status, 'result': port_number}
) )
else: else:
result = gettext( result = SERVER_CONNECTION_CLOSED
'Not connected to server or connection with the '
'server has been closed.'
)
return internal_server_error(errormsg=str(result)) return internal_server_error(errormsg=str(result))
@ -1334,10 +1309,7 @@ def start_execution(trans_id, port_num):
return make_json_response( return make_json_response(
data={ data={
'status': 'NotConnected', 'status': 'NotConnected',
'result': gettext( 'result': SERVER_CONNECTION_CLOSED
'Not connected to server or connection with the server '
'has been closed.'
)
} }
) )
@ -1414,10 +1386,7 @@ def set_clear_breakpoint(trans_id, line_no, set_type):
return make_json_response( return make_json_response(
data={ data={
'status': False, 'status': False,
'result': gettext( 'result': SERVER_CONNECTION_CLOSED
'Not connected to server or connection with the server '
'has been closed.'
)
} }
) )
@ -1473,10 +1442,7 @@ def set_clear_breakpoint(trans_id, line_no, set_type):
return internal_server_error(errormsg=result) return internal_server_error(errormsg=result)
else: else:
status = False status = False
result = gettext( result = SERVER_CONNECTION_CLOSED
'Not connected to server or connection with the server '
'has been closed.'
)
return make_json_response( return make_json_response(
data={'status': status, 'result': result['rows']} data={'status': status, 'result': result['rows']}
@ -1504,10 +1470,7 @@ def clear_all_breakpoint(trans_id):
return make_json_response( return make_json_response(
data={ data={
'status': False, 'status': False,
'result': gettext( 'result': SERVER_CONNECTION_CLOSED
'Not connected to server or connection '
'with the server has been closed.'
)
} }
) )
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(
@ -1543,9 +1506,7 @@ def clear_all_breakpoint(trans_id):
return make_json_response(data={'status': False}) return make_json_response(data={'status': False})
else: else:
status = False status = False
result = gettext( result = SERVER_CONNECTION_CLOSED
'Not connected to server or connection with the server has '
'been closed.')
return make_json_response( return make_json_response(
data={'status': status, 'result': result['rows']} data={'status': status, 'result': result['rows']}
@ -1573,8 +1534,7 @@ def deposit_parameter_value(trans_id):
return make_json_response( return make_json_response(
data={ data={
'status': False, 'status': False,
'result': gettext('Not connected to server or connection ' 'result': SERVER_CONNECTION_CLOSED
'with the server has been closed.')
} }
) )
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(
@ -1622,10 +1582,7 @@ def deposit_parameter_value(trans_id):
) )
else: else:
status = False status = False
result = gettext( result = SERVER_CONNECTION_CLOSED
'Not connected to server or connection with the server has '
'been closed.'
)
return make_json_response(data={'status': status, 'result': result}) return make_json_response(data={'status': status, 'result': result})
@ -1652,10 +1609,7 @@ def select_frame(trans_id, frame_id):
return make_json_response( return make_json_response(
data={ data={
'status': False, 'status': False,
'result': gettext( 'result': SERVER_CONNECTION_CLOSED
'Not connected to server or connection '
'with the server has been closed.'
)
} }
) )
@ -1688,10 +1642,7 @@ def select_frame(trans_id, frame_id):
return internal_server_error(errormsg=result) return internal_server_error(errormsg=result)
else: else:
status = False status = False
result = gettext( result = SERVER_CONNECTION_CLOSED
'Not connected to server or connection with the server '
'has been closed.'
)
return make_json_response( return make_json_response(
data={'status': status, 'result': result['rows']} data={'status': status, 'result': result['rows']}
@ -1969,9 +1920,7 @@ def poll_end_execution_result(trans_id):
if de_inst.debugger_data is None: if de_inst.debugger_data is None:
return make_json_response( return make_json_response(
data={'status': 'NotConnected', data={'status': 'NotConnected',
'result': gettext( 'result': SERVER_CONNECTION_CLOSED
'Not connected to server or connection with the '
'server has been closed.')
} }
) )
@ -2070,8 +2019,7 @@ def poll_end_execution_result(trans_id):
) )
else: else:
status = 'NotConnected' status = 'NotConnected'
result = gettext('Not connected to server or connection with the ' result = SERVER_CONNECTION_CLOSED
'server has been closed.')
return make_json_response(data={'status': status, 'result': result}) return make_json_response(data={'status': status, 'result': result})
@ -2097,8 +2045,7 @@ def poll_result(trans_id):
return make_json_response( return make_json_response(
data={ data={
'status': 'NotConnected', 'status': 'NotConnected',
'result': gettext('Not connected to server or connection ' 'result': SERVER_CONNECTION_CLOSED
'with the server has been closed.')
} }
) )
@ -2119,10 +2066,7 @@ def poll_result(trans_id):
status = 'Busy' status = 'Busy'
else: else:
status = 'NotConnected' status = 'NotConnected'
result = gettext( result = SERVER_CONNECTION_CLOSED
'Not connected to server or connection with the server '
'has been closed.'
)
return make_json_response( return make_json_response(
data={ data={

View File

@ -184,6 +184,10 @@ def properties(sid, did, node_id, node_type):
"""It fetches the properties of object types """It fetches the properties of object types
and render into selection page of wizard and render into selection page of wizard
""" """
function_sql_url = '/sql/function.sql'
get_schema_sql_url = '/sql/get_schemas.sql'
# unquote encoded url parameter # unquote encoded url parameter
node_type = unquote(node_type) node_type = unquote(node_type)
@ -201,7 +205,7 @@ def properties(sid, did, node_id, node_type):
# Get sys_obj_values and get list of schemas # Get sys_obj_values and get list of schemas
ntype = 'schema' ntype = 'schema'
sql = render_template("/".join( sql = render_template("/".join(
[server_prop['template_path'], '/sql/get_schemas.sql']), [server_prop['template_path'], get_schema_sql_url]),
show_sysobj=show_sysobj) show_sysobj=show_sysobj)
status, res = conn.execute_dict(sql) status, res = conn.execute_dict(sql)
@ -210,7 +214,7 @@ def properties(sid, did, node_id, node_type):
node_types = res['rows'] node_types = res['rows']
else: else:
sql = render_template("/".join( sql = render_template("/".join(
[server_prop['template_path'], '/sql/get_schemas.sql']), [server_prop['template_path'], get_schema_sql_url]),
nspid=node_id, show_sysobj=False) nspid=node_id, show_sysobj=False)
status, res = conn.execute_dict(sql) status, res = conn.execute_dict(sql)
@ -226,7 +230,7 @@ def properties(sid, did, node_id, node_type):
# Fetch functions against schema # Fetch functions against schema
if ntype in ['schema', 'function']: if ntype in ['schema', 'function']:
sql = render_template("/".join( sql = render_template("/".join(
[server_prop['template_path'], '/sql/function.sql']), [server_prop['template_path'], function_sql_url]),
node_id=node_id, type='function') node_id=node_id, type='function')
status, res = conn.execute_dict(sql) status, res = conn.execute_dict(sql)
@ -243,7 +247,7 @@ def properties(sid, did, node_id, node_type):
server_prop['version'] >= 11000)) and server_prop['version'] >= 11000)) and
ntype in ['schema', 'procedure']): ntype in ['schema', 'procedure']):
sql = render_template("/".join( sql = render_template("/".join(
[server_prop['template_path'], '/sql/function.sql']), [server_prop['template_path'], function_sql_url]),
node_id=node_id, type='procedure') node_id=node_id, type='procedure')
status, res = conn.execute_dict(sql) status, res = conn.execute_dict(sql)
@ -257,7 +261,7 @@ def properties(sid, did, node_id, node_type):
# Fetch trigger functions # Fetch trigger functions
if ntype in ['schema', 'trigger_function']: if ntype in ['schema', 'trigger_function']:
sql = render_template("/".join( sql = render_template("/".join(
[server_prop['template_path'], '/sql/function.sql']), [server_prop['template_path'], function_sql_url]),
node_id=node_id, type='trigger_function') node_id=node_id, type='trigger_function')
status, res = conn.execute_dict(sql) status, res = conn.execute_dict(sql)

View File

@ -44,7 +44,7 @@ from pgadmin.tools.sqleditor.utils.query_tool_fs_utils import \
read_file_generator read_file_generator
from pgadmin.tools.sqleditor.utils.filter_dialog import FilterDialog from pgadmin.tools.sqleditor.utils.filter_dialog import FilterDialog
from pgadmin.tools.sqleditor.utils.query_history import QueryHistory from pgadmin.tools.sqleditor.utils.query_history import QueryHistory
from pgadmin.utils.constants import MIMETYPE_APP_JS from pgadmin.utils.constants import MIMETYPE_APP_JS, SERVER_CONNECTION_CLOSED
MODULE_NAME = 'sqleditor' MODULE_NAME = 'sqleditor'
@ -964,10 +964,7 @@ def _check_and_cancel_transaction(trans_obj, delete_connection, conn, manager):
manager.release(did=trans_obj.did) manager.release(did=trans_obj.did)
else: else:
status = False status = False
result = gettext( result = SERVER_CONNECTION_CLOSED
'Not connected to server or connection with the server has '
'been closed.'
)
return status, result return status, result

View File

@ -23,7 +23,7 @@ from pgadmin.tools.sqleditor.utils.save_changed_data import save_changed_data
from pgadmin.tools.sqleditor.utils.get_column_types import get_columns_types from pgadmin.tools.sqleditor.utils.get_column_types import get_columns_types
from pgadmin.utils.preferences import Preferences from pgadmin.utils.preferences import Preferences
from pgadmin.utils.exception import ObjectGone, ExecuteError from pgadmin.utils.exception import ObjectGone, ExecuteError
from pgadmin.utils.constants import SERVER_CONNECTION_CLOSED
from config import PG_DEFAULT_DRIVER from config import PG_DEFAULT_DRIVER
VIEW_FIRST_100_ROWS = 1 VIEW_FIRST_100_ROWS = 1
@ -196,10 +196,7 @@ class SQLFilter(object):
self.nsp_name = result['rows'][0]['nspname'] self.nsp_name = result['rows'][0]['nspname']
self.object_name = result['rows'][0]['relname'] self.object_name = result['rows'][0]['relname']
else: else:
raise InternalServerError(gettext( raise InternalServerError(SERVER_CONNECTION_CLOSED)
'Not connected to server or connection with the server '
'has been closed.')
)
def get_filter(self): def get_filter(self):
""" """
@ -407,10 +404,8 @@ class GridCommand(BaseCommand, SQLFilter, FetchedRowTracker):
for row in result['rows']: for row in result['rows']:
all_columns.append(row['attname']) all_columns.append(row['attname'])
else: else:
raise InternalServerError( raise InternalServerError(SERVER_CONNECTION_CLOSED)
gettext('Not connected to server or connection with the '
'server has been closed.')
)
# If user has custom data sorting then pass as it as it is # If user has custom data sorting then pass as it as it is
if data_sorting and len(data_sorting) > 0: if data_sorting and len(data_sorting) > 0:
all_sorted_columns = data_sorting all_sorted_columns = data_sorting
@ -553,10 +548,7 @@ class TableCommand(GridCommand):
# Remove last character from the string # Remove last character from the string
pk_names = pk_names[:-1] pk_names = pk_names[:-1]
else: else:
raise InternalServerError( raise InternalServerError(SERVER_CONNECTION_CLOSED)
gettext('Not connected to server or connection with the '
'server has been closed.')
)
return pk_names, primary_keys return pk_names, primary_keys
@ -650,10 +642,7 @@ class TableCommand(GridCommand):
raise ExecuteError(has_oids) raise ExecuteError(has_oids)
else: else:
raise InternalServerError( raise InternalServerError(SERVER_CONNECTION_CLOSED)
gettext('Not connected to server or connection with the '
'server has been closed.')
)
return has_oids return has_oids
@ -1002,7 +991,4 @@ class QueryToolCommand(BaseCommand, FetchedRowTracker):
self.nsp_name = result['rows'][0]['nspname'] self.nsp_name = result['rows'][0]['nspname']
self.object_name = result['rows'][0]['relname'] self.object_name = result['rows'][0]['relname']
else: else:
raise InternalServerError(gettext( raise InternalServerError(SERVER_CONNECTION_CLOSED)
'Not connected to server or connection with the server '
'has been closed.')
)

View File

@ -28,6 +28,7 @@ from werkzeug.exceptions import InternalServerError
from pgadmin.tools.sqleditor.utils.get_column_types import get_columns_types from pgadmin.tools.sqleditor.utils.get_column_types import get_columns_types
from pgadmin.utils.exception import ExecuteError from pgadmin.utils.exception import ExecuteError
from pgadmin.utils.constants import SERVER_CONNECTION_CLOSED
def is_query_resultset_updatable(conn, sql_path): def is_query_resultset_updatable(conn, sql_path):
@ -86,10 +87,7 @@ def is_query_resultset_updatable(conn, sql_path):
_set_all_columns_not_editable(columns_info=columns_info) _set_all_columns_not_editable(columns_info=columns_info)
return return_not_updatable() return return_not_updatable()
else: else:
raise InternalServerError( raise InternalServerError(SERVER_CONNECTION_CLOSED)
gettext('Not connected to server or connection with the '
'server has been closed.')
)
def _check_single_table(columns_info): def _check_single_table(columns_info):

View File

@ -27,3 +27,5 @@ PREF_LABEL_SQL_FORMATTING = gettext('SQL formatting')
PGADMIN_NODE = 'pgadmin.node.%s' PGADMIN_NODE = 'pgadmin.node.%s'
UNAUTH_REQ = "Unauthorized request." UNAUTH_REQ = "Unauthorized request."
SERVER_CONNECTION_CLOSED = gettext(
'Not connected to server or connection with the server has been closed.')

View File

@ -103,6 +103,9 @@ class NavMenuLocators:
"//*[contains(@class,'wcTabTop')]//*[contains(@class,'wcPanelTab') " \ "//*[contains(@class,'wcTabTop')]//*[contains(@class,'wcPanelTab') " \
"and contains(.,'{}')]" "and contains(.,'{}')]"
process_watcher_error_close_xpath = \
".btn.btn-sm-sq.btn-primary.pg-bg-close > i"
class QueryToolLocators: class QueryToolLocators:
btn_save_file = "#btn-save-file" btn_save_file = "#btn-save-file"

View File

@ -20,7 +20,7 @@ def close_bgprocess_popup(tester):
".ajs-message.ajs-bg-bgprocess.ajs-visible")) ".ajs-message.ajs-bg-bgprocess.ajs-visible"))
except Exception: except Exception:
tester.driver.find_element_by_css_selector( tester.driver.find_element_by_css_selector(
".btn.btn-sm-sq.btn-primary.pg-bg-close > i").click() NavMenuLocators.process_watcher_error_close_xpath).click()
# In cases where restore div is not closed (sometime due to some error) # In cases where restore div is not closed (sometime due to some error)
try: try:
@ -30,7 +30,7 @@ def close_bgprocess_popup(tester):
"[contains(text(), 'Restoring backup')]")) "[contains(text(), 'Restoring backup')]"))
except Exception: except Exception:
tester.driver.find_element_by_css_selector( tester.driver.find_element_by_css_selector(
".btn.btn-sm-sq.btn-primary.pg-bg-close > i").click() NavMenuLocators.process_watcher_error_close_xpath).click()
# In cases where maintenance window is not closed (sometime due to some # In cases where maintenance window is not closed (sometime due to some
# error) # error)
@ -41,7 +41,7 @@ def close_bgprocess_popup(tester):
"[contains(text(), 'Maintenance')]")) "[contains(text(), 'Maintenance')]"))
except Exception: except Exception:
tester.driver.find_element_by_css_selector( tester.driver.find_element_by_css_selector(
".btn.btn-sm-sq.btn-primary.pg-bg-close > i").click() NavMenuLocators.process_watcher_error_close_xpath).click()
def close_process_watcher(tester): def close_process_watcher(tester):