mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Fixed code smell 'Define a constant instead of duplicating this literal' reported by SonarQube.
This commit is contained in:
committed by
Akshay Joshi
parent
103b08c9c5
commit
7f3e8596e3
@@ -660,7 +660,7 @@ class ServerNode(PGChildNodeView):
|
||||
return make_json_response(
|
||||
status=410,
|
||||
success=0,
|
||||
errormsg=self.not_found_error_msg
|
||||
errormsg=self.not_found_error_msg()
|
||||
)
|
||||
|
||||
sg = ServerGroup.query.filter_by(
|
||||
@@ -1006,7 +1006,7 @@ class ServerNode(PGChildNodeView):
|
||||
# Fetch Server Details
|
||||
server = Server.query.filter_by(id=sid).first()
|
||||
if server is None:
|
||||
return bad_request(self.not_found_error_msg)
|
||||
return bad_request(self.not_found_error_msg())
|
||||
|
||||
if current_user and hasattr(current_user, 'id'):
|
||||
# Fetch User Details.
|
||||
@@ -1181,7 +1181,7 @@ class ServerNode(PGChildNodeView):
|
||||
|
||||
server = Server.query.filter_by(id=sid).first()
|
||||
if server is None:
|
||||
return bad_request(self.not_found_error_msg)
|
||||
return bad_request(self.not_found_error_msg())
|
||||
|
||||
# Release Connection
|
||||
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
|
||||
@@ -1289,7 +1289,7 @@ class ServerNode(PGChildNodeView):
|
||||
# Fetch Server Details
|
||||
server = Server.query.filter_by(id=sid).first()
|
||||
if server is None:
|
||||
return bad_request(self.not_found_error_msg)
|
||||
return bad_request(self.not_found_error_msg())
|
||||
|
||||
# Fetch User Details.
|
||||
user = User.query.filter_by(id=current_user.id).first()
|
||||
@@ -1409,7 +1409,7 @@ class ServerNode(PGChildNodeView):
|
||||
if server is None:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=self.not_found_error_msg
|
||||
errormsg=self.not_found_error_msg()
|
||||
)
|
||||
|
||||
try:
|
||||
@@ -1493,7 +1493,7 @@ class ServerNode(PGChildNodeView):
|
||||
if server is None:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=self.not_found_error_msg
|
||||
errormsg=self.not_found_error_msg()
|
||||
)
|
||||
|
||||
try:
|
||||
@@ -1568,7 +1568,7 @@ class ServerNode(PGChildNodeView):
|
||||
if server is None:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
info=self.not_found_error_msg
|
||||
info=self.not_found_error_msg()
|
||||
)
|
||||
|
||||
setattr(server, 'password', None)
|
||||
@@ -1607,7 +1607,7 @@ class ServerNode(PGChildNodeView):
|
||||
if server is None:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
info=self.not_found_error_msg
|
||||
info=self.not_found_error_msg()
|
||||
)
|
||||
|
||||
setattr(server, 'tunnel_password', None)
|
||||
|
||||
@@ -39,6 +39,9 @@ class DatabaseModule(CollectionNodeModule):
|
||||
_NODE_TYPE = 'database'
|
||||
_COLLECTION_LABEL = _("Databases")
|
||||
|
||||
_DATABASE_CSS_PATH = 'databases/css'
|
||||
_DATABASE_CSS = "/".join([_DATABASE_CSS_PATH, 'database.css'])
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.min_ver = None
|
||||
self.max_ver = None
|
||||
@@ -67,12 +70,12 @@ class DatabaseModule(CollectionNodeModule):
|
||||
"""
|
||||
snippets = [
|
||||
render_template(
|
||||
"browser/css/collection.css",
|
||||
self._COLLECTION_CSS,
|
||||
node_type=self.node_type,
|
||||
_=_
|
||||
),
|
||||
render_template(
|
||||
"databases/css/database.css",
|
||||
self._DATABASE_CSS,
|
||||
node_type=self.node_type,
|
||||
_=_
|
||||
)
|
||||
@@ -381,7 +384,7 @@ class DatabaseView(PGChildNodeView):
|
||||
status=200
|
||||
)
|
||||
|
||||
return gone(errormsg=self.not_found_error_msg)
|
||||
return gone(errormsg=self.not_found_error_msg())
|
||||
|
||||
@check_precondition(action="properties")
|
||||
def properties(self, gid, sid, did):
|
||||
@@ -397,7 +400,7 @@ class DatabaseView(PGChildNodeView):
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return gone(
|
||||
self.not_found_error_msg
|
||||
self.not_found_error_msg()
|
||||
)
|
||||
|
||||
SQL = render_template(
|
||||
@@ -802,7 +805,7 @@ class DatabaseView(PGChildNodeView):
|
||||
|
||||
if len(rset['rows']) == 0:
|
||||
return gone(
|
||||
self.not_found_error_msg
|
||||
self.not_found_error_msg()
|
||||
)
|
||||
|
||||
res = rset['rows'][0]
|
||||
@@ -931,7 +934,7 @@ class DatabaseView(PGChildNodeView):
|
||||
|
||||
if len(rset['rows']) == 0:
|
||||
return gone(
|
||||
self.not_found_error_msg
|
||||
self.not_found_error_msg()
|
||||
)
|
||||
|
||||
data['old_name'] = (rset['rows'][0])['name']
|
||||
@@ -1102,7 +1105,7 @@ class DatabaseView(PGChildNodeView):
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return gone(
|
||||
self.not_found_error_msg
|
||||
self.not_found_error_msg()
|
||||
)
|
||||
|
||||
SQL = render_template(
|
||||
|
||||
@@ -357,7 +357,7 @@ class ForeignServerView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
return False, internal_server_error(errormsg=res)
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return False, gone(self.not_found_error_msg)
|
||||
return False, gone(self.not_found_error_msg())
|
||||
|
||||
res['rows'][0]['is_sys_obj'] = (
|
||||
res['rows'][0]['oid'] <= self.datlastsysoid)
|
||||
@@ -650,7 +650,7 @@ class ForeignServerView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
if len(res['rows']) == 0:
|
||||
return gone(self.not_found_error_msg)
|
||||
return gone(self.not_found_error_msg())
|
||||
|
||||
if res['rows'][0]['fsrvoptions'] is not None:
|
||||
res['rows'][0]['fsrvoptions'] = tokenize_options(
|
||||
@@ -755,7 +755,7 @@ class ForeignServerView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
if len(res['rows']) == 0:
|
||||
return gone(self.not_found_error_msg)
|
||||
return gone(self.not_found_error_msg())
|
||||
|
||||
if fid is None and 'fdwid' in res['rows'][0]:
|
||||
fid = res['rows'][0]['fdwid']
|
||||
|
||||
@@ -375,7 +375,7 @@ class UserMappingView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
return False, internal_server_error(errormsg=res)
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return False, gone(self.not_found_error_msg)
|
||||
return False, gone(self.not_found_error_msg())
|
||||
|
||||
res['rows'][0]['is_sys_obj'] = (
|
||||
res['rows'][0]['oid'] <= self.datlastsysoid)
|
||||
@@ -671,7 +671,7 @@ class UserMappingView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
if len(res['rows']) == 0:
|
||||
return gone(self.not_found_error_msg)
|
||||
return gone(self.not_found_error_msg())
|
||||
|
||||
if res['rows'][0]['umoptions'] is not None:
|
||||
res['rows'][0]['umoptions'] = tokenize_options(
|
||||
@@ -766,7 +766,7 @@ class UserMappingView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
if len(res['rows']) == 0:
|
||||
return gone(self.not_found_error_msg)
|
||||
return gone(self.not_found_error_msg())
|
||||
|
||||
if fsid is None and 'fsid' in res['rows'][0]:
|
||||
fsid = res['rows'][0]['fsid']
|
||||
|
||||
@@ -89,25 +89,25 @@ class TableModule(SchemaChildModule):
|
||||
"""
|
||||
snippets = [
|
||||
render_template(
|
||||
"browser/css/collection.css",
|
||||
self._COLLECTION_CSS,
|
||||
node_type=self.node_type,
|
||||
),
|
||||
render_template(
|
||||
"browser/css/node.css",
|
||||
self._NODE_CSS,
|
||||
node_type=self.node_type,
|
||||
),
|
||||
render_template(
|
||||
"browser/css/node.css",
|
||||
self._NODE_CSS,
|
||||
node_type='table',
|
||||
file_name='table-inherited',
|
||||
),
|
||||
render_template(
|
||||
"browser/css/node.css",
|
||||
self._NODE_CSS,
|
||||
node_type='table',
|
||||
file_name='table-inherits',
|
||||
),
|
||||
render_template(
|
||||
"browser/css/node.css",
|
||||
self._NODE_CSS,
|
||||
node_type='table',
|
||||
file_name='table-multi-inherit',
|
||||
),
|
||||
@@ -594,7 +594,7 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings,
|
||||
if not status:
|
||||
return res
|
||||
if not res['rows']:
|
||||
return gone(gettext("The specified table could not be found."))
|
||||
return gone(gettext(self.not_found_error_msg()))
|
||||
|
||||
return super(TableView, self).properties(
|
||||
gid, sid, did, scid, tid, res=res
|
||||
@@ -636,7 +636,7 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings,
|
||||
|
||||
elif len(res['rows']) == 0:
|
||||
return False, gone(
|
||||
gettext("The specified table could not be found."))
|
||||
gettext(self.not_found_error_msg()))
|
||||
|
||||
# Update autovacuum properties
|
||||
self.update_autovacuum_properties(res['rows'][0])
|
||||
@@ -729,14 +729,16 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings,
|
||||
if data and 'tid' in data:
|
||||
SQL = render_template(
|
||||
"/".join([
|
||||
self.table_template_path, 'get_columns_for_table.sql'
|
||||
self.table_template_path,
|
||||
self._GET_COLUMNS_FOR_TABLE_SQL
|
||||
]),
|
||||
tid=data['tid']
|
||||
)
|
||||
elif data and 'tname' in data:
|
||||
SQL = render_template(
|
||||
"/".join([
|
||||
self.table_template_path, 'get_columns_for_table.sql'
|
||||
self.table_template_path,
|
||||
self._GET_COLUMNS_FOR_TABLE_SQL
|
||||
]),
|
||||
tname=data['tname']
|
||||
)
|
||||
@@ -778,7 +780,7 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings,
|
||||
SQL = render_template(
|
||||
"/".join(
|
||||
[self.table_template_path,
|
||||
'get_columns_for_table.sql']
|
||||
self._GET_COLUMNS_FOR_TABLE_SQL]
|
||||
), tid=row['oid']
|
||||
)
|
||||
|
||||
@@ -1118,7 +1120,7 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings,
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=gettext(
|
||||
'The specified table could not be found.\n'
|
||||
self.not_found_error_msg() + '\n'
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1160,7 +1162,7 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings,
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return gone(gettext("The specified table could not be found."))
|
||||
return gone(gettext(self.not_found_error_msg()))
|
||||
|
||||
return super(TableView, self).truncate(
|
||||
gid, sid, did, scid, tid, res
|
||||
@@ -1265,8 +1267,7 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings,
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return gone(gettext("The specified table could not be found."
|
||||
))
|
||||
return gone(gettext(self.not_found_error_msg()))
|
||||
|
||||
if status:
|
||||
data = res['rows'][0]
|
||||
@@ -1376,7 +1377,7 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings,
|
||||
return res
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return gone(gettext("The specified table could not be found."))
|
||||
return gone(gettext(self.not_found_error_msg()))
|
||||
|
||||
data = res['rows'][0]
|
||||
|
||||
@@ -1408,7 +1409,7 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings,
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return gone(gettext("The specified table could not be found."))
|
||||
return gone(gettext(self.not_found_error_msg()))
|
||||
|
||||
data = res['rows'][0]
|
||||
data = self._formatter(did, scid, tid, data)
|
||||
@@ -1456,7 +1457,7 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings,
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return gone(gettext("The specified table could not be found."))
|
||||
return gone(gettext(self.not_found_error_msg()))
|
||||
|
||||
data = res['rows'][0]
|
||||
data = self._formatter(did, scid, tid, data)
|
||||
@@ -1507,7 +1508,7 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings,
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return gone(gettext("The specified table could not be found."))
|
||||
return gone(gettext(self.not_found_error_msg()))
|
||||
|
||||
data = res['rows'][0]
|
||||
data = self._formatter(did, scid, tid, data)
|
||||
@@ -1560,7 +1561,7 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings,
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return gone(gettext("The specified table could not be found."))
|
||||
return gone(gettext(self.not_found_error_msg()))
|
||||
|
||||
data = res['rows'][0]
|
||||
|
||||
@@ -1609,7 +1610,7 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings,
|
||||
super(TableView, self).get_schema_and_table_name(tid)
|
||||
|
||||
if data['name'] is None:
|
||||
return gone(gettext("The specified table could not be found."))
|
||||
return gone(gettext(self.not_found_error_msg()))
|
||||
|
||||
SQL = render_template(
|
||||
"/".join(
|
||||
|
||||
@@ -398,7 +398,7 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
|
||||
data['schema'] = self.schema
|
||||
data['table'] = self.table
|
||||
if len(data['table']) == 0:
|
||||
return gone(gettext("The specified table could not be found."))
|
||||
return gone(gettext(self.not_found_error_msg('Table')))
|
||||
|
||||
# check type for '[]' in it
|
||||
data['cltype'], data['hasSqrBracket'] = \
|
||||
|
||||
@@ -520,7 +520,7 @@ class CheckConstraintView(PGChildNodeView):
|
||||
data['table'] = self.table
|
||||
# Checking whether the table is deleted via query tool
|
||||
if len(data['table']) == 0:
|
||||
return gone(_("The specified table could not be found."))
|
||||
return gone(_(self.not_found_error_msg('Table')))
|
||||
|
||||
try:
|
||||
if 'name' not in data or data['name'] == "":
|
||||
|
||||
@@ -111,7 +111,7 @@ class ForeignKeyConstraintModule(ConstraintTypeModule):
|
||||
"""
|
||||
snippets = [
|
||||
render_template(
|
||||
"browser/css/collection.css",
|
||||
self._COLLECTION_CSS,
|
||||
node_type=self.node_type,
|
||||
),
|
||||
render_template(
|
||||
|
||||
@@ -602,7 +602,7 @@ class IndexesView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
data['schema'] = self.schema
|
||||
data['table'] = self.table
|
||||
if len(data['table']) == 0:
|
||||
return gone(gettext("The specified table could not be found."))
|
||||
return gone(gettext(self.not_found_error_msg('Table')))
|
||||
|
||||
try:
|
||||
# Start transaction.
|
||||
|
||||
@@ -385,7 +385,7 @@ class PartitionsView(BaseTableView, DataTypeReader, VacuumSettings,
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return False, gone(
|
||||
gettext("The specified table could not be found."))
|
||||
gettext(self.not_found_error_msg()))
|
||||
|
||||
# Update autovacuum properties
|
||||
self.update_autovacuum_properties(res['rows'][0])
|
||||
|
||||
@@ -106,7 +106,7 @@ class RuleModule(CollectionNodeModule):
|
||||
"""
|
||||
snippets = [
|
||||
render_template(
|
||||
"browser/css/collection.css",
|
||||
self._COLLECTION_CSS,
|
||||
node_type=self.node_type,
|
||||
_=gettext
|
||||
),
|
||||
|
||||
@@ -81,6 +81,9 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
|
||||
* reset_statistics(self, scid, tid):
|
||||
- This function will reset statistics of table.
|
||||
"""
|
||||
|
||||
node_label = "Table"
|
||||
|
||||
@staticmethod
|
||||
def check_precondition(f):
|
||||
"""
|
||||
@@ -812,7 +815,7 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
|
||||
schema_name, table_name = self.get_schema_and_table_name(tid)
|
||||
|
||||
if table_name is None:
|
||||
return gone(gettext("The specified table could not be found."))
|
||||
return gone(gettext(self.not_found_error_msg()))
|
||||
|
||||
# table exist
|
||||
try:
|
||||
@@ -1291,7 +1294,7 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
|
||||
schema_name, table_name = self.get_schema_and_table_name(tid)
|
||||
|
||||
if table_name is None:
|
||||
return gone(gettext("The specified table could not be found."))
|
||||
return gone(gettext(self.not_found_error_msg()))
|
||||
|
||||
# table exists
|
||||
try:
|
||||
|
||||
@@ -109,7 +109,7 @@ class ViewModule(SchemaChildModule):
|
||||
"""
|
||||
snippets = [
|
||||
render_template(
|
||||
"browser/css/collection.css",
|
||||
self._COLLECTION_CSS,
|
||||
node_type=self.node_type,
|
||||
_=gettext
|
||||
),
|
||||
|
||||
@@ -90,7 +90,7 @@ SELECT EXISTS(
|
||||
"""
|
||||
snippets = [
|
||||
render_template(
|
||||
"browser/css/collection.css",
|
||||
self._COLLECTION_CSS,
|
||||
node_type=self.node_type,
|
||||
_=_
|
||||
),
|
||||
|
||||
@@ -63,7 +63,7 @@ class RoleModule(CollectionNodeModule):
|
||||
"""
|
||||
snippets = [
|
||||
render_template(
|
||||
"browser/css/collection.css",
|
||||
self._COLLECTION_CSS,
|
||||
node_type=self.node_type
|
||||
),
|
||||
render_template("roles/css/role.css")]
|
||||
|
||||
Reference in New Issue
Block a user