mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Fixed code smell 'String literals should not be duplicated'.
This commit is contained in:
committed by
Akshay Joshi
parent
e226b2fa75
commit
3984544bdb
@@ -30,7 +30,8 @@ from pgadmin.utils.exception import CryptKeyMissing
|
||||
from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry
|
||||
from psycopg2 import Error as psycopg2_Error, OperationalError
|
||||
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):
|
||||
@@ -1224,9 +1225,7 @@ class ServerNode(PGChildNodeView):
|
||||
else:
|
||||
return make_json_response(data={
|
||||
'status': False,
|
||||
'result': gettext(
|
||||
'Not connected to the server or the connection to the'
|
||||
' server has been closed.')})
|
||||
'result': SERVER_CONNECTION_CLOSED})
|
||||
|
||||
def create_restore_point(self, gid, sid):
|
||||
"""
|
||||
|
||||
@@ -208,6 +208,7 @@ class SchemaView(PGChildNodeView):
|
||||
"""
|
||||
node_type = schema_blueprint.node_type
|
||||
_SQL_PREFIX = 'sql/'
|
||||
node_icon = 'icon-%s' % node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
@@ -455,8 +456,6 @@ class SchemaView(PGChildNodeView):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=rset)
|
||||
|
||||
icon = 'icon-{0}'.format(self.node_type)
|
||||
|
||||
if scid is not None:
|
||||
if len(rset['rows']) == 0:
|
||||
return gone(gettext(
|
||||
@@ -468,7 +467,7 @@ class SchemaView(PGChildNodeView):
|
||||
row['oid'],
|
||||
did,
|
||||
row['name'],
|
||||
icon=icon,
|
||||
icon=self.node_icon,
|
||||
can_create=row['can_create'],
|
||||
has_usage=row['has_usage']
|
||||
),
|
||||
@@ -481,7 +480,7 @@ class SchemaView(PGChildNodeView):
|
||||
row['oid'],
|
||||
did,
|
||||
row['name'],
|
||||
icon=icon,
|
||||
icon=self.node_icon,
|
||||
can_create=row['can_create'],
|
||||
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.
|
||||
"""))
|
||||
|
||||
icon = 'icon-{0}'.format(self.node_type)
|
||||
|
||||
for row in rset['rows']:
|
||||
return make_json_response(
|
||||
data=self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
did,
|
||||
row['name'],
|
||||
icon=icon,
|
||||
icon=self.node_icon,
|
||||
can_create=row['can_create'],
|
||||
has_usage=row['has_usage']
|
||||
),
|
||||
@@ -635,14 +632,12 @@ It may have been removed by another user.
|
||||
if not status:
|
||||
return internal_server_error(errormsg=scid)
|
||||
|
||||
icon = 'icon-{0}'.format(self.node_type)
|
||||
|
||||
return jsonify(
|
||||
node=self.blueprint.generate_browser_node(
|
||||
scid,
|
||||
did,
|
||||
data['name'],
|
||||
icon=icon
|
||||
icon=self.node_icon
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
@@ -676,7 +671,7 @@ It may have been removed by another user.
|
||||
scid,
|
||||
did,
|
||||
name,
|
||||
icon="icon-%s" % self.node_type
|
||||
icon=self.node_icon
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
|
||||
@@ -83,6 +83,7 @@ blueprint = PackageModule(__name__)
|
||||
class PackageView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
node_type = blueprint.node_type
|
||||
node_label = "Package"
|
||||
node_icon = "icon-%s" % node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
@@ -223,7 +224,7 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
row['oid'],
|
||||
scid,
|
||||
row['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
icon=self.node_icon
|
||||
)
|
||||
)
|
||||
|
||||
@@ -233,7 +234,7 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
row['oid'],
|
||||
scid,
|
||||
row['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
icon=self.node_icon
|
||||
))
|
||||
|
||||
return make_json_response(
|
||||
@@ -277,7 +278,7 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
row['oid'],
|
||||
scid,
|
||||
row['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
icon=self.node_icon
|
||||
))
|
||||
|
||||
return make_json_response(
|
||||
@@ -409,7 +410,7 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
pkgid,
|
||||
scid,
|
||||
data['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
icon=self.node_icon
|
||||
)
|
||||
)
|
||||
|
||||
@@ -516,7 +517,7 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
pkgid,
|
||||
scid,
|
||||
name,
|
||||
icon="icon-%s" % self.node_type
|
||||
icon=self.node_icon
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -91,6 +91,7 @@ blueprint = SequenceModule(__name__)
|
||||
class SequenceView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
node_type = blueprint.node_type
|
||||
node_label = "Sequence"
|
||||
node_icon = "icon-%s" % node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
@@ -216,7 +217,7 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
row['oid'],
|
||||
scid,
|
||||
row['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
icon=self.node_icon
|
||||
),
|
||||
status=200
|
||||
)
|
||||
@@ -228,7 +229,7 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
row['oid'],
|
||||
scid,
|
||||
row['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
icon=self.node_icon
|
||||
))
|
||||
|
||||
return make_json_response(
|
||||
@@ -437,7 +438,7 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
row['oid'],
|
||||
row['relnamespace'],
|
||||
data['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
icon=self.node_icon
|
||||
)
|
||||
)
|
||||
|
||||
@@ -550,7 +551,7 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
seid,
|
||||
row['schema'],
|
||||
row['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
icon=self.node_icon
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -201,6 +201,8 @@ class IndexConstraintView(PGChildNodeView):
|
||||
|
||||
node_label = _('Index constraint')
|
||||
|
||||
node_icon = "icon-%s" % node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
@@ -287,10 +289,7 @@ class IndexConstraintView(PGChildNodeView):
|
||||
return res
|
||||
|
||||
if len(res) == 0:
|
||||
return gone(_("""Could not find the {} in the table.""").format(
|
||||
_("primary key") if self.constraint_type == "p"
|
||||
else _("unique key")
|
||||
))
|
||||
return gone(self.key_not_found_error_msg())
|
||||
|
||||
result = res
|
||||
if cid:
|
||||
@@ -392,16 +391,13 @@ class IndexConstraintView(PGChildNodeView):
|
||||
return internal_server_error(errormsg=rset)
|
||||
|
||||
if len(rset['rows']) == 0:
|
||||
return gone(_("""Could not find the {} in the table.""").format(
|
||||
_("primary key") if self.constraint_type == "p"
|
||||
else _("unique key")
|
||||
))
|
||||
return gone(self.key_not_found_error_msg())
|
||||
|
||||
res = self.blueprint.generate_browser_node(
|
||||
rset['rows'][0]['oid'],
|
||||
tid,
|
||||
rset['rows'][0]['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
icon=self.node_icon
|
||||
)
|
||||
return make_json_response(
|
||||
data=res,
|
||||
@@ -441,7 +437,7 @@ class IndexConstraintView(PGChildNodeView):
|
||||
row['oid'],
|
||||
tid,
|
||||
row['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
icon=self.node_icon
|
||||
)
|
||||
)
|
||||
return make_json_response(
|
||||
@@ -486,7 +482,7 @@ class IndexConstraintView(PGChildNodeView):
|
||||
row['oid'],
|
||||
tid,
|
||||
row['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
icon=self.node_icon
|
||||
))
|
||||
return res
|
||||
|
||||
@@ -627,7 +623,7 @@ class IndexConstraintView(PGChildNodeView):
|
||||
res['rows'][0]['oid'],
|
||||
tid,
|
||||
data['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
icon=self.node_icon
|
||||
)
|
||||
)
|
||||
|
||||
@@ -688,7 +684,7 @@ class IndexConstraintView(PGChildNodeView):
|
||||
cid,
|
||||
tid,
|
||||
name,
|
||||
icon="icon-%s" % self.node_type
|
||||
icon=self.node_icon
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
@@ -844,10 +840,7 @@ class IndexConstraintView(PGChildNodeView):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
if len(res['rows']) == 0:
|
||||
return gone(_("""Could not find the {} in the table.""").format(
|
||||
_("primary key") if self.constraint_type == "p"
|
||||
else _("unique key")
|
||||
))
|
||||
return gone(self.key_not_found_error_msg())
|
||||
|
||||
data = res['rows'][0]
|
||||
data['schema'] = self.schema
|
||||
@@ -936,12 +929,7 @@ class IndexConstraintView(PGChildNodeView):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
if len(res['rows']) == 0:
|
||||
return gone(
|
||||
_("""Could not find the {} in the table.""").format(
|
||||
_("primary key") if self.constraint_type == "p"
|
||||
else _("unique key")
|
||||
)
|
||||
)
|
||||
return gone(self.key_not_found_error_msg())
|
||||
|
||||
result = res['rows'][0]
|
||||
name = result['name']
|
||||
@@ -1010,6 +998,12 @@ class IndexConstraintView(PGChildNodeView):
|
||||
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):
|
||||
node_type = 'primary_key'
|
||||
|
||||
Reference in New Issue
Block a user