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'.
Create a constant.py file which contains the common Constants.
This commit is contained in:
parent
4b56962c1b
commit
cc5a7ea334
@ -47,6 +47,7 @@ from pgadmin.utils.master_password import validate_master_password, \
|
||||
set_masterpass_check_text, cleanup_master_password, get_crypt_key, \
|
||||
set_crypt_key, process_masterpass_disabled
|
||||
from pgadmin.model import User
|
||||
from pgadmin.utils.constants import APP_JS, PGADMIN_NODE
|
||||
|
||||
try:
|
||||
from flask_security.views import default_render_json
|
||||
@ -57,6 +58,17 @@ except ImportError as e:
|
||||
from flask_security.views import _render_json as default_render_json
|
||||
|
||||
MODULE_NAME = 'browser'
|
||||
BROWSER_STATIC = 'browser.static'
|
||||
JQUERY_ACIPLUGIN = 'jquery.aciplugin'
|
||||
BROWSER_INDEX = 'browser.index'
|
||||
PGADMIN_BROWSER = 'pgAdmin.Browser'
|
||||
PASS_ERROR_MSG = u'Your password has not been changed.'
|
||||
SMTP_SOCKET_ERROR = u'SMTP Socket error: {error}\n {pass_error}'.format(
|
||||
error={}, pass_error=PASS_ERROR_MSG)
|
||||
SMTP_ERROR = u'SMTP error: {error}\n {pass_error}'.format(
|
||||
error={}, pass_error=PASS_ERROR_MSG)
|
||||
PASS_ERROR = u'Error: {error}\n {pass_error}'.format(
|
||||
error={}, pass_error=PASS_ERROR_MSG)
|
||||
|
||||
|
||||
class BrowserModule(PgAdminModule):
|
||||
@ -77,7 +89,7 @@ class BrowserModule(PgAdminModule):
|
||||
('static', 'vendor/codemirror/addon/dialog/dialog.css'),
|
||||
('static', context_menu_file),
|
||||
('static', wcdocker_file),
|
||||
('browser.static', 'vendor/aciTree/css/aciTree.css')
|
||||
(BROWSER_STATIC, 'vendor/aciTree/css/aciTree.css')
|
||||
]:
|
||||
stylesheets.append(url_for(endpoint, filename=filename))
|
||||
return stylesheets
|
||||
@ -119,9 +131,9 @@ class BrowserModule(PgAdminModule):
|
||||
'preloaded': True
|
||||
})
|
||||
scripts.append({
|
||||
'name': 'jquery.aciplugin',
|
||||
'name': JQUERY_ACIPLUGIN,
|
||||
'path': url_for(
|
||||
'browser.static',
|
||||
BROWSER_STATIC,
|
||||
filename='vendor/aciTree/jquery.aciPlugin.min'
|
||||
),
|
||||
'deps': ['jquery'],
|
||||
@ -131,21 +143,21 @@ class BrowserModule(PgAdminModule):
|
||||
scripts.append({
|
||||
'name': 'jquery.acitree',
|
||||
'path': url_for(
|
||||
'browser.static',
|
||||
BROWSER_STATIC,
|
||||
filename='vendor/aciTree/jquery.aciTree' if
|
||||
current_app.debug else 'vendor/aciTree/jquery.aciTree.min'
|
||||
),
|
||||
'deps': ['jquery', 'jquery.aciplugin'],
|
||||
'deps': ['jquery', JQUERY_ACIPLUGIN],
|
||||
'exports': 'aciPluginClass.plugins.aciTree',
|
||||
'preloaded': True
|
||||
})
|
||||
scripts.append({
|
||||
'name': 'jquery.acisortable',
|
||||
'path': url_for(
|
||||
'browser.static',
|
||||
BROWSER_STATIC,
|
||||
filename='vendor/aciTree/jquery.aciSortable.min'
|
||||
),
|
||||
'deps': ['jquery', 'jquery.aciplugin'],
|
||||
'deps': ['jquery', JQUERY_ACIPLUGIN],
|
||||
'exports': 'aciPluginClass.plugins.aciSortable',
|
||||
'when': None,
|
||||
'preloaded': True
|
||||
@ -153,10 +165,10 @@ class BrowserModule(PgAdminModule):
|
||||
scripts.append({
|
||||
'name': 'jquery.acifragment',
|
||||
'path': url_for(
|
||||
'browser.static',
|
||||
BROWSER_STATIC,
|
||||
filename='vendor/aciTree/jquery.aciFragment.min'
|
||||
),
|
||||
'deps': ['jquery', 'jquery.aciplugin'],
|
||||
'deps': ['jquery', JQUERY_ACIPLUGIN],
|
||||
'exports': 'aciPluginClass.plugins.aciFragment',
|
||||
'when': None,
|
||||
'preloaded': True
|
||||
@ -175,18 +187,18 @@ class BrowserModule(PgAdminModule):
|
||||
|
||||
scripts.append({
|
||||
'name': 'pgadmin.browser.datamodel',
|
||||
'path': url_for('browser.static', filename='js/datamodel'),
|
||||
'path': url_for(BROWSER_STATIC, filename='js/datamodel'),
|
||||
'preloaded': True
|
||||
})
|
||||
|
||||
for name, script in [
|
||||
['pgadmin.browser', 'js/browser'],
|
||||
[PGADMIN_BROWSER, 'js/browser'],
|
||||
['pgadmin.browser.endpoints', 'js/endpoints'],
|
||||
['pgadmin.browser.error', 'js/error']
|
||||
]:
|
||||
scripts.append({
|
||||
'name': name,
|
||||
'path': url_for('browser.index') + script,
|
||||
'path': url_for(BROWSER_INDEX) + script,
|
||||
'preloaded': True
|
||||
})
|
||||
|
||||
@ -197,7 +209,7 @@ class BrowserModule(PgAdminModule):
|
||||
]:
|
||||
scripts.append({
|
||||
'name': name,
|
||||
'path': url_for('browser.index') + script,
|
||||
'path': url_for(BROWSER_INDEX) + script,
|
||||
'preloaded': True,
|
||||
'deps': ['pgadmin.browser.datamodel']
|
||||
})
|
||||
@ -208,12 +220,12 @@ class BrowserModule(PgAdminModule):
|
||||
['pgadmin.browser.frame', 'js/frame']
|
||||
]:
|
||||
scripts.append({
|
||||
'name': name, 'path': url_for('browser.static', filename=end),
|
||||
'name': name, 'path': url_for(BROWSER_STATIC, filename=end),
|
||||
'preloaded': True})
|
||||
|
||||
scripts.append({
|
||||
'name': 'pgadmin.browser.node.ui',
|
||||
'path': url_for('browser.static', filename='js/node.ui'),
|
||||
'path': url_for(BROWSER_STATIC, filename='js/node.ui'),
|
||||
'when': 'server_group'
|
||||
})
|
||||
|
||||
@ -226,26 +238,26 @@ class BrowserModule(PgAdminModule):
|
||||
'file_items': [
|
||||
MenuItem(
|
||||
name='mnu_locklayout',
|
||||
module='pgAdmin.Browser',
|
||||
module=PGADMIN_BROWSER,
|
||||
label=gettext('Lock Layout'),
|
||||
priority=999,
|
||||
menu_items=[MenuItem(
|
||||
name='mnu_lock_none',
|
||||
module='pgAdmin.Browser',
|
||||
module=PGADMIN_BROWSER,
|
||||
callback='mnu_lock_none',
|
||||
priority=0,
|
||||
label=gettext('None'),
|
||||
checked=True
|
||||
), MenuItem(
|
||||
name='mnu_lock_docking',
|
||||
module='pgAdmin.Browser',
|
||||
module=PGADMIN_BROWSER,
|
||||
callback='mnu_lock_docking',
|
||||
priority=1,
|
||||
label=gettext('Prevent Docking'),
|
||||
checked=False
|
||||
), MenuItem(
|
||||
name='mnu_lock_full',
|
||||
module='pgAdmin.Browser',
|
||||
module=PGADMIN_BROWSER,
|
||||
callback='mnu_lock_full',
|
||||
priority=2,
|
||||
label=gettext('Full Lock'),
|
||||
@ -263,7 +275,7 @@ class BrowserModule(PgAdminModule):
|
||||
Returns:
|
||||
list: a list of url endpoints exposed to the client.
|
||||
"""
|
||||
return ['browser.index', 'browser.nodes',
|
||||
return [BROWSER_INDEX, 'browser.nodes',
|
||||
'browser.check_master_password',
|
||||
'browser.set_master_password',
|
||||
'browser.reset_master_password',
|
||||
@ -358,15 +370,15 @@ class BrowserPluginModule(PgAdminModule):
|
||||
|
||||
if self.module_use_template_javascript:
|
||||
scripts.extend([{
|
||||
'name': 'pgadmin.node.%s' % self.node_type,
|
||||
'path': url_for('browser.index') +
|
||||
'%s/module' % self.node_type,
|
||||
'name': PGADMIN_NODE % self.node_type,
|
||||
'path': url_for(BROWSER_INDEX
|
||||
) + '%s/module' % self.node_type,
|
||||
'when': self.script_load,
|
||||
'is_template': True
|
||||
}])
|
||||
else:
|
||||
scripts.extend([{
|
||||
'name': 'pgadmin.node.%s' % self.node_type,
|
||||
'name': PGADMIN_NODE % self.node_type,
|
||||
'path': url_for(
|
||||
'%s.static' % self.name,
|
||||
filename=('js/%s' % self.node_type)
|
||||
@ -412,7 +424,7 @@ class BrowserPluginModule(PgAdminModule):
|
||||
"_type": node_type,
|
||||
"_id": node_id,
|
||||
"_pid": parent_id,
|
||||
"module": 'pgadmin.node.%s' % node_type
|
||||
"module": PGADMIN_NODE % node_type
|
||||
}
|
||||
for key in kwargs:
|
||||
obj.setdefault(key, kwargs[key])
|
||||
@ -527,7 +539,7 @@ class BrowserPluginModule(PgAdminModule):
|
||||
|
||||
def _get_logout_url():
|
||||
return '{0}?next={1}'.format(
|
||||
url_for('security.logout'), url_for('browser.index'))
|
||||
url_for('security.logout'), url_for(BROWSER_INDEX))
|
||||
|
||||
|
||||
@blueprint.route("/")
|
||||
@ -737,7 +749,7 @@ def utils():
|
||||
support_ssh_tunnel=config.SUPPORT_SSH_TUNNEL,
|
||||
logout_url=_get_logout_url()
|
||||
),
|
||||
200, {'Content-Type': 'application/javascript'})
|
||||
200, {'Content-Type': APP_JS})
|
||||
|
||||
|
||||
@blueprint.route("/js/endpoints.js")
|
||||
@ -745,7 +757,7 @@ def utils():
|
||||
def exposed_urls():
|
||||
return make_response(
|
||||
render_template('browser/js/endpoints.js'),
|
||||
200, {'Content-Type': 'application/javascript'}
|
||||
200, {'Content-Type': APP_JS}
|
||||
)
|
||||
|
||||
|
||||
@ -755,7 +767,7 @@ def exposed_urls():
|
||||
def error_js():
|
||||
return make_response(
|
||||
render_template('browser/js/error.js', _=gettext),
|
||||
200, {'Content-Type': 'application/javascript'})
|
||||
200, {'Content-Type': APP_JS})
|
||||
|
||||
|
||||
@blueprint.route("/js/messages.js")
|
||||
@ -763,7 +775,7 @@ def error_js():
|
||||
def messages_js():
|
||||
return make_response(
|
||||
render_template('browser/js/messages.js', _=gettext),
|
||||
200, {'Content-Type': 'application/javascript'})
|
||||
200, {'Content-Type': APP_JS})
|
||||
|
||||
|
||||
@blueprint.route("/browser.css")
|
||||
@ -969,9 +981,7 @@ if hasattr(config, 'SECURITY_CHANGEABLE') and config.SECURITY_CHANGEABLE:
|
||||
except SOCKETErrorException as e:
|
||||
# Handle socket errors which are not covered by SMTPExceptions.
|
||||
logging.exception(str(e), exc_info=True)
|
||||
flash(gettext(u'SMTP Socket error: {}\n'
|
||||
u'Your password has not been changed.'
|
||||
).format(e),
|
||||
flash(gettext(SMTP_SOCKET_ERROR).format(e),
|
||||
'danger')
|
||||
has_error = True
|
||||
except (SMTPConnectError, SMTPResponseException,
|
||||
@ -980,19 +990,14 @@ if hasattr(config, 'SECURITY_CHANGEABLE') and config.SECURITY_CHANGEABLE:
|
||||
SMTPRecipientsRefused) as e:
|
||||
# Handle smtp specific exceptions.
|
||||
logging.exception(str(e), exc_info=True)
|
||||
flash(gettext(u'SMTP error: {}\n'
|
||||
u'Your password has not been changed.'
|
||||
).format(e),
|
||||
flash(gettext(SMTP_ERROR).format(e),
|
||||
'danger')
|
||||
has_error = True
|
||||
except Exception as e:
|
||||
# Handle other exceptions.
|
||||
logging.exception(str(e), exc_info=True)
|
||||
flash(
|
||||
gettext(
|
||||
u'Error: {}\n'
|
||||
u'Your password has not been changed.'
|
||||
).format(e),
|
||||
gettext(PASS_ERROR).format(e),
|
||||
'danger'
|
||||
)
|
||||
has_error = True
|
||||
@ -1078,9 +1083,7 @@ if hasattr(config, 'SECURITY_RECOVERABLE') and config.SECURITY_RECOVERABLE:
|
||||
# Handle socket errors which are not
|
||||
# covered by SMTPExceptions.
|
||||
logging.exception(str(e), exc_info=True)
|
||||
flash(gettext(u'SMTP Socket error: {}\n'
|
||||
u'Your password has not been changed.'
|
||||
).format(e),
|
||||
flash(gettext(SMTP_SOCKET_ERROR).format(e),
|
||||
'danger')
|
||||
has_error = True
|
||||
except (SMTPConnectError, SMTPResponseException,
|
||||
@ -1090,17 +1093,13 @@ if hasattr(config, 'SECURITY_RECOVERABLE') and config.SECURITY_RECOVERABLE:
|
||||
|
||||
# Handle smtp specific exceptions.
|
||||
logging.exception(str(e), exc_info=True)
|
||||
flash(gettext(u'SMTP error: {}\n'
|
||||
u'Your password has not been changed.'
|
||||
).format(e),
|
||||
flash(gettext(SMTP_ERROR).format(e),
|
||||
'danger')
|
||||
has_error = True
|
||||
except Exception as e:
|
||||
# Handle other exceptions.
|
||||
logging.exception(str(e), exc_info=True)
|
||||
flash(gettext(u'Error: {}\n'
|
||||
u'Your password has not been changed.'
|
||||
).format(e),
|
||||
flash(gettext(PASS_ERROR).format(e),
|
||||
'danger')
|
||||
has_error = True
|
||||
|
||||
@ -1149,9 +1148,7 @@ if hasattr(config, 'SECURITY_RECOVERABLE') and config.SECURITY_RECOVERABLE:
|
||||
except SOCKETErrorException as e:
|
||||
# Handle socket errors which are not covered by SMTPExceptions.
|
||||
logging.exception(str(e), exc_info=True)
|
||||
flash(gettext(u'SMTP Socket error: {}\n'
|
||||
u'Your password has not been changed.'
|
||||
).format(e),
|
||||
flash(gettext(SMTP_SOCKET_ERROR).format(e),
|
||||
'danger')
|
||||
has_error = True
|
||||
except (SMTPConnectError, SMTPResponseException,
|
||||
@ -1161,17 +1158,13 @@ if hasattr(config, 'SECURITY_RECOVERABLE') and config.SECURITY_RECOVERABLE:
|
||||
|
||||
# Handle smtp specific exceptions.
|
||||
logging.exception(str(e), exc_info=True)
|
||||
flash(gettext(u'SMTP error: {}\n'
|
||||
u'Your password has not been changed.'
|
||||
).format(e),
|
||||
flash(gettext(SMTP_ERROR).format(e),
|
||||
'danger')
|
||||
has_error = True
|
||||
except Exception as e:
|
||||
# Handle other exceptions.
|
||||
logging.exception(str(e), exc_info=True)
|
||||
flash(gettext(u'Error: {}\n'
|
||||
u'Your password has not been changed.'
|
||||
).format(e),
|
||||
flash(gettext(PASS_ERROR).format(e),
|
||||
'danger')
|
||||
has_error = True
|
||||
|
||||
|
@ -16,6 +16,7 @@ from pgadmin.browser import BrowserPluginModule
|
||||
from pgadmin.browser.utils import PGChildModule
|
||||
from pgadmin.utils import PgAdminModule
|
||||
from pgadmin.utils.preferences import Preferences
|
||||
from pgadmin.utils.constants import PGADMIN_NODE
|
||||
|
||||
|
||||
@six.add_metaclass(ABCMeta)
|
||||
@ -58,15 +59,15 @@ class CollectionNodeModule(PgAdminModule, PGChildModule):
|
||||
|
||||
if self.module_use_template_javascript:
|
||||
scripts.extend([{
|
||||
'name': 'pgadmin.node.%s' % self.node_type,
|
||||
'path': url_for('browser.index') +
|
||||
'%s/module' % self.node_type,
|
||||
'name': PGADMIN_NODE % self.node_type,
|
||||
'path': url_for('browser.index'
|
||||
) + '%s/module' % self.node_type,
|
||||
'when': self.script_load,
|
||||
'is_template': True
|
||||
}])
|
||||
else:
|
||||
scripts.extend([{
|
||||
'name': 'pgadmin.node.%s' % self.node_type,
|
||||
'name': PGADMIN_NODE % self.node_type,
|
||||
'path': url_for(
|
||||
'%s.static' % self.name,
|
||||
filename=('js/%s' % self.node_type)
|
||||
@ -93,7 +94,7 @@ class CollectionNodeModule(PgAdminModule, PGChildModule):
|
||||
"_type": self.node_type,
|
||||
"_id": node_id,
|
||||
"_pid": parent_id,
|
||||
"module": 'pgadmin.node.%s' % self.node_type
|
||||
"module": PGADMIN_NODE % self.node_type
|
||||
}
|
||||
for key in kwargs:
|
||||
obj.setdefault(key, kwargs[key])
|
||||
@ -108,7 +109,7 @@ class CollectionNodeModule(PgAdminModule, PGChildModule):
|
||||
"_type": 'coll-%s' % (self.node_type),
|
||||
"_id": parent_id,
|
||||
"_pid": parent_id,
|
||||
"module": 'pgadmin.node.%s' % self.node_type,
|
||||
"module": PGADMIN_NODE % self.node_type,
|
||||
"nodes": [self.node_type]
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#
|
||||
##########################################################################
|
||||
from flask_babelex import gettext
|
||||
from pgadmin.utils.constants import KEYBOARD_SHORTCUTS
|
||||
|
||||
LOCK_LAYOUT_LEVEL = {
|
||||
'PREVENT_DOCKING': 'docking',
|
||||
@ -125,7 +126,7 @@ def register_browser_preferences(self):
|
||||
'control': False,
|
||||
'key': {'key_code': 66, 'char': 'b'}
|
||||
},
|
||||
category_label=gettext('Keyboard shortcuts'),
|
||||
category_label=gettext(KEYBOARD_SHORTCUTS),
|
||||
fields=fields
|
||||
)
|
||||
|
||||
@ -140,7 +141,7 @@ def register_browser_preferences(self):
|
||||
'control': False,
|
||||
'key': {'key_code': 91, 'char': '['}
|
||||
},
|
||||
category_label=gettext('Keyboard shortcuts'),
|
||||
category_label=gettext(KEYBOARD_SHORTCUTS),
|
||||
fields=fields
|
||||
)
|
||||
|
||||
@ -155,7 +156,7 @@ def register_browser_preferences(self):
|
||||
'control': False,
|
||||
'key': {'key_code': 93, 'char': ']'}
|
||||
},
|
||||
category_label=gettext('Keyboard shortcuts'),
|
||||
category_label=gettext(KEYBOARD_SHORTCUTS),
|
||||
fields=fields
|
||||
)
|
||||
|
||||
@ -170,7 +171,7 @@ def register_browser_preferences(self):
|
||||
'control': False,
|
||||
'key': {'key_code': 70, 'char': 'f'}
|
||||
},
|
||||
category_label=gettext('Keyboard shortcuts'),
|
||||
category_label=gettext(KEYBOARD_SHORTCUTS),
|
||||
fields=fields
|
||||
)
|
||||
|
||||
@ -185,7 +186,7 @@ def register_browser_preferences(self):
|
||||
'control': False,
|
||||
'key': {'key_code': 79, 'char': 'o'}
|
||||
},
|
||||
category_label=gettext('Keyboard shortcuts'),
|
||||
category_label=gettext(KEYBOARD_SHORTCUTS),
|
||||
fields=fields
|
||||
)
|
||||
|
||||
@ -200,7 +201,7 @@ def register_browser_preferences(self):
|
||||
'control': False,
|
||||
'key': {'key_code': 76, 'char': 'l'}
|
||||
},
|
||||
category_label=gettext('Keyboard shortcuts'),
|
||||
category_label=gettext(KEYBOARD_SHORTCUTS),
|
||||
fields=fields
|
||||
)
|
||||
|
||||
@ -215,7 +216,7 @@ def register_browser_preferences(self):
|
||||
'control': False,
|
||||
'key': {'key_code': 72, 'char': 'h'}
|
||||
},
|
||||
category_label=gettext('Keyboard shortcuts'),
|
||||
category_label=gettext(KEYBOARD_SHORTCUTS),
|
||||
fields=fields
|
||||
)
|
||||
|
||||
@ -230,7 +231,7 @@ def register_browser_preferences(self):
|
||||
'control': False,
|
||||
'key': {'key_code': 81, 'char': 'q'}
|
||||
},
|
||||
category_label=gettext('Keyboard shortcuts'),
|
||||
category_label=gettext(KEYBOARD_SHORTCUTS),
|
||||
fields=fields
|
||||
)
|
||||
|
||||
@ -245,7 +246,7 @@ def register_browser_preferences(self):
|
||||
'control': False,
|
||||
'key': {'key_code': 86, 'char': 'v'}
|
||||
},
|
||||
category_label=gettext('Keyboard shortcuts'),
|
||||
category_label=gettext(KEYBOARD_SHORTCUTS),
|
||||
fields=fields
|
||||
)
|
||||
|
||||
@ -260,7 +261,7 @@ def register_browser_preferences(self):
|
||||
'control': False,
|
||||
'key': {'key_code': 83, 'char': 's'}
|
||||
},
|
||||
category_label=gettext('Keyboard shortcuts'),
|
||||
category_label=gettext(KEYBOARD_SHORTCUTS),
|
||||
fields=fields
|
||||
)
|
||||
|
||||
@ -275,7 +276,7 @@ def register_browser_preferences(self):
|
||||
'control': False,
|
||||
'key': {'key_code': 78, 'char': 'n'}
|
||||
},
|
||||
category_label=gettext('Keyboard shortcuts'),
|
||||
category_label=gettext(KEYBOARD_SHORTCUTS),
|
||||
fields=fields
|
||||
)
|
||||
|
||||
@ -290,7 +291,7 @@ def register_browser_preferences(self):
|
||||
'control': False,
|
||||
'key': {'key_code': 69, 'char': 'e'}
|
||||
},
|
||||
category_label=gettext('Keyboard shortcuts'),
|
||||
category_label=gettext(KEYBOARD_SHORTCUTS),
|
||||
fields=fields
|
||||
)
|
||||
|
||||
@ -305,7 +306,7 @@ def register_browser_preferences(self):
|
||||
'control': False,
|
||||
'key': {'key_code': 68, 'char': 'd'}
|
||||
},
|
||||
category_label=gettext('Keyboard shortcuts'),
|
||||
category_label=gettext(KEYBOARD_SHORTCUTS),
|
||||
fields=fields
|
||||
)
|
||||
|
||||
@ -320,7 +321,7 @@ def register_browser_preferences(self):
|
||||
'control': False,
|
||||
'key': {'key_code': 77, 'char': 'm'}
|
||||
},
|
||||
category_label=gettext('Keyboard shortcuts'),
|
||||
category_label=gettext(KEYBOARD_SHORTCUTS),
|
||||
fields=fields
|
||||
)
|
||||
|
||||
@ -335,7 +336,7 @@ def register_browser_preferences(self):
|
||||
'control': False,
|
||||
'key': {'key_code': 85, 'char': 'u'}
|
||||
},
|
||||
category_label=gettext('Keyboard shortcuts'),
|
||||
category_label=gettext(KEYBOARD_SHORTCUTS),
|
||||
fields=fields
|
||||
)
|
||||
|
||||
@ -350,7 +351,7 @@ def register_browser_preferences(self):
|
||||
'control': False,
|
||||
'key': {'key_code': 67, 'char': 'c'}
|
||||
},
|
||||
category_label=gettext('Keyboard shortcuts'),
|
||||
category_label=gettext(KEYBOARD_SHORTCUTS),
|
||||
fields=fields
|
||||
)
|
||||
|
||||
@ -365,7 +366,7 @@ def register_browser_preferences(self):
|
||||
'control': False,
|
||||
'key': {'key_code': 71, 'char': 'g'}
|
||||
},
|
||||
category_label=gettext('Keyboard shortcuts'),
|
||||
category_label=gettext(KEYBOARD_SHORTCUTS),
|
||||
fields=fields
|
||||
)
|
||||
|
||||
@ -380,7 +381,7 @@ def register_browser_preferences(self):
|
||||
'control': True,
|
||||
'key': {'key_code': 93, 'char': ']'}
|
||||
},
|
||||
category_label=gettext('Keyboard shortcuts'),
|
||||
category_label=gettext(KEYBOARD_SHORTCUTS),
|
||||
fields=fields
|
||||
)
|
||||
|
||||
@ -395,7 +396,7 @@ def register_browser_preferences(self):
|
||||
'control': True,
|
||||
'key': {'key_code': 91, 'char': '['}
|
||||
},
|
||||
category_label=gettext('Keyboard shortcuts'),
|
||||
category_label=gettext(KEYBOARD_SHORTCUTS),
|
||||
fields=fields
|
||||
)
|
||||
|
||||
@ -410,7 +411,7 @@ def register_browser_preferences(self):
|
||||
'control': False,
|
||||
'key': {'key_code': 116, 'char': 'F5'}
|
||||
},
|
||||
category_label=gettext('Keyboard shortcuts'),
|
||||
category_label=gettext(KEYBOARD_SHORTCUTS),
|
||||
fields=fields
|
||||
)
|
||||
|
||||
@ -425,6 +426,6 @@ def register_browser_preferences(self):
|
||||
'control': True,
|
||||
'key': {'key_code': 65, 'char': 'a'}
|
||||
},
|
||||
category_label=gettext('Keyboard shortcuts'),
|
||||
category_label=gettext(KEYBOARD_SHORTCUTS),
|
||||
fields=fields
|
||||
)
|
||||
|
@ -24,9 +24,12 @@ from pgadmin.utils.menu import MenuItem
|
||||
from sqlalchemy import exc
|
||||
from pgadmin.model import db, ServerGroup
|
||||
|
||||
SG_NOT_FOUND_ERROR = 'The specified server group could not be found.'
|
||||
|
||||
|
||||
class ServerGroupModule(BrowserPluginModule):
|
||||
_NODE_TYPE = "server_group"
|
||||
node_icon = "icon-%s" % _NODE_TYPE
|
||||
|
||||
def get_nodes(self, *arg, **kwargs):
|
||||
"""Return a JSON document listing the server groups for the user"""
|
||||
@ -37,7 +40,7 @@ class ServerGroupModule(BrowserPluginModule):
|
||||
yield self.generate_browser_node(
|
||||
"%d" % (group.id), None,
|
||||
group.name,
|
||||
"icon-%s" % self.node_type,
|
||||
self.node_icon,
|
||||
True,
|
||||
self.node_type,
|
||||
can_delete=True if idx > 0 else False
|
||||
@ -92,6 +95,9 @@ blueprint = ServerGroupModule(__name__)
|
||||
|
||||
class ServerGroupView(NodeView):
|
||||
node_type = ServerGroupModule._NODE_TYPE
|
||||
node_icon = ServerGroupModule.node_icon
|
||||
node_label = "Server Group"
|
||||
|
||||
parent_ids = []
|
||||
ids = [{'type': 'int', 'id': 'gid'}]
|
||||
|
||||
@ -136,9 +142,7 @@ class ServerGroupView(NodeView):
|
||||
return make_json_response(
|
||||
status=410,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'The specified server group could not be found.'
|
||||
)
|
||||
errormsg=gettext(SG_NOT_FOUND_ERROR)
|
||||
)
|
||||
else:
|
||||
try:
|
||||
@ -169,9 +173,7 @@ class ServerGroupView(NodeView):
|
||||
return make_json_response(
|
||||
status=417,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'The specified server group could not be found.'
|
||||
)
|
||||
errormsg=gettext(SG_NOT_FOUND_ERROR)
|
||||
)
|
||||
else:
|
||||
try:
|
||||
@ -194,7 +196,7 @@ class ServerGroupView(NodeView):
|
||||
gid,
|
||||
None,
|
||||
servergroup.name,
|
||||
"icon-%s" % self.node_type,
|
||||
self.node_icon,
|
||||
True,
|
||||
self.node_type,
|
||||
can_delete=True # This is user created hence can deleted
|
||||
@ -214,9 +216,7 @@ class ServerGroupView(NodeView):
|
||||
return make_json_response(
|
||||
status=410,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'The specified server group could not be found.'
|
||||
)
|
||||
errormsg=gettext(SG_NOT_FOUND_ERROR)
|
||||
)
|
||||
else:
|
||||
return ajax_response(
|
||||
@ -246,7 +246,7 @@ class ServerGroupView(NodeView):
|
||||
"%d" % sg.id,
|
||||
None,
|
||||
sg.name,
|
||||
"icon-%s" % self.node_type,
|
||||
self.node_icon,
|
||||
True,
|
||||
self.node_type,
|
||||
# This is user created hence can deleted
|
||||
@ -306,7 +306,7 @@ class ServerGroupView(NodeView):
|
||||
"%d" % group.id,
|
||||
None,
|
||||
group.name,
|
||||
"icon-%s" % self.node_type,
|
||||
self.node_icon,
|
||||
True,
|
||||
self.node_type
|
||||
)
|
||||
@ -322,7 +322,7 @@ class ServerGroupView(NodeView):
|
||||
nodes = self.blueprint.generate_browser_node(
|
||||
"%d" % (group.id), None,
|
||||
group.name,
|
||||
"icon-%s" % self.node_type,
|
||||
self.node_icon,
|
||||
True,
|
||||
self.node_type
|
||||
)
|
||||
|
@ -30,6 +30,7 @@ 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
|
||||
|
||||
|
||||
def has_any(data, keys):
|
||||
@ -240,6 +241,7 @@ blueprint = ServerModule(__name__)
|
||||
|
||||
class ServerNode(PGChildNodeView):
|
||||
node_type = ServerModule._NODE_TYPE
|
||||
node_label = "Server"
|
||||
|
||||
parent_ids = [{'type': 'int', 'id': 'gid'}]
|
||||
ids = [{'type': 'int', 'id': 'sid'}]
|
||||
@ -658,7 +660,7 @@ class ServerNode(PGChildNodeView):
|
||||
return make_json_response(
|
||||
status=410,
|
||||
success=0,
|
||||
errormsg=gettext("Could not find the required server.")
|
||||
errormsg=self.not_found_error_msg
|
||||
)
|
||||
|
||||
sg = ServerGroup.query.filter_by(
|
||||
@ -1004,15 +1006,15 @@ class ServerNode(PGChildNodeView):
|
||||
# Fetch Server Details
|
||||
server = Server.query.filter_by(id=sid).first()
|
||||
if server is None:
|
||||
return bad_request(gettext("Server not found."))
|
||||
return bad_request(self.not_found_error_msg)
|
||||
|
||||
if current_user and hasattr(current_user, 'id'):
|
||||
# Fetch User Details.
|
||||
user = User.query.filter_by(id=current_user.id).first()
|
||||
if user is None:
|
||||
return unauthorized(gettext("Unauthorized request."))
|
||||
return unauthorized(gettext(UNAUTH_REQ))
|
||||
else:
|
||||
return unauthorized(gettext("Unauthorized request."))
|
||||
return unauthorized(gettext(UNAUTH_REQ))
|
||||
|
||||
data = {}
|
||||
if request.form:
|
||||
@ -1179,7 +1181,7 @@ class ServerNode(PGChildNodeView):
|
||||
|
||||
server = Server.query.filter_by(id=sid).first()
|
||||
if server is None:
|
||||
return bad_request(gettext("Server not found."))
|
||||
return bad_request(self.not_found_error_msg)
|
||||
|
||||
# Release Connection
|
||||
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
|
||||
@ -1287,12 +1289,12 @@ class ServerNode(PGChildNodeView):
|
||||
# Fetch Server Details
|
||||
server = Server.query.filter_by(id=sid).first()
|
||||
if server is None:
|
||||
return bad_request(gettext("Server not found."))
|
||||
return bad_request(self.not_found_error_msg)
|
||||
|
||||
# Fetch User Details.
|
||||
user = User.query.filter_by(id=current_user.id).first()
|
||||
if user is None:
|
||||
return unauthorized(gettext("Unauthorized request."))
|
||||
return unauthorized(gettext(UNAUTH_REQ))
|
||||
|
||||
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
|
||||
conn = manager.connection()
|
||||
@ -1407,7 +1409,7 @@ class ServerNode(PGChildNodeView):
|
||||
if server is None:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext("Could not find the required server.")
|
||||
errormsg=self.not_found_error_msg
|
||||
)
|
||||
|
||||
try:
|
||||
@ -1491,7 +1493,7 @@ class ServerNode(PGChildNodeView):
|
||||
if server is None:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext("Could not find the required server.")
|
||||
errormsg=self.not_found_error_msg
|
||||
)
|
||||
|
||||
try:
|
||||
@ -1566,7 +1568,7 @@ class ServerNode(PGChildNodeView):
|
||||
if server is None:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
info=gettext("Could not find the required server.")
|
||||
info=self.not_found_error_msg
|
||||
)
|
||||
|
||||
setattr(server, 'password', None)
|
||||
@ -1605,7 +1607,7 @@ class ServerNode(PGChildNodeView):
|
||||
if server is None:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
info=gettext("Could not find the required server.")
|
||||
info=self.not_found_error_msg
|
||||
)
|
||||
|
||||
setattr(server, 'tunnel_password', None)
|
||||
|
@ -97,6 +97,7 @@ blueprint = DatabaseModule(__name__)
|
||||
|
||||
class DatabaseView(PGChildNodeView):
|
||||
node_type = blueprint.node_type
|
||||
node_label = "Database"
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
@ -380,7 +381,7 @@ class DatabaseView(PGChildNodeView):
|
||||
status=200
|
||||
)
|
||||
|
||||
return gone(errormsg=_("Could not find the database on the server."))
|
||||
return gone(errormsg=self.not_found_error_msg)
|
||||
|
||||
@check_precondition(action="properties")
|
||||
def properties(self, gid, sid, did):
|
||||
@ -396,7 +397,7 @@ class DatabaseView(PGChildNodeView):
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return gone(
|
||||
_("Could not find the database on the server.")
|
||||
self.not_found_error_msg
|
||||
)
|
||||
|
||||
SQL = render_template(
|
||||
@ -801,7 +802,7 @@ class DatabaseView(PGChildNodeView):
|
||||
|
||||
if len(rset['rows']) == 0:
|
||||
return gone(
|
||||
_("Could not find the database on the server.")
|
||||
self.not_found_error_msg
|
||||
)
|
||||
|
||||
res = rset['rows'][0]
|
||||
@ -930,7 +931,7 @@ class DatabaseView(PGChildNodeView):
|
||||
|
||||
if len(rset['rows']) == 0:
|
||||
return gone(
|
||||
_("Could not find the database on the server.")
|
||||
self.not_found_error_msg
|
||||
)
|
||||
|
||||
data['old_name'] = (rset['rows'][0])['name']
|
||||
@ -1101,7 +1102,7 @@ class DatabaseView(PGChildNodeView):
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return gone(
|
||||
_("Could not find the database on the server.")
|
||||
self.not_found_error_msg
|
||||
)
|
||||
|
||||
SQL = render_template(
|
||||
|
@ -149,6 +149,7 @@ class EventTriggerView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
"""
|
||||
|
||||
node_type = blueprint.node_type
|
||||
node_icon = "icon-%s" % blueprint.node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
@ -258,7 +259,7 @@ class EventTriggerView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
row['oid'],
|
||||
did,
|
||||
row['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
self.node_icon
|
||||
))
|
||||
|
||||
return make_json_response(
|
||||
@ -292,7 +293,7 @@ class EventTriggerView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
row['oid'],
|
||||
did,
|
||||
row['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
self.node_icon
|
||||
),
|
||||
status=200
|
||||
)
|
||||
@ -431,7 +432,7 @@ class EventTriggerView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
etid,
|
||||
did,
|
||||
data['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
self.node_icon
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
@ -478,7 +479,7 @@ class EventTriggerView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
etid,
|
||||
did,
|
||||
data['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
self.node_icon
|
||||
)
|
||||
)
|
||||
else:
|
||||
|
@ -163,6 +163,7 @@ class ForeignServerView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
"""
|
||||
|
||||
node_type = blueprint.node_type
|
||||
node_label = "Foreign Server"
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
@ -356,9 +357,7 @@ class ForeignServerView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
return False, internal_server_error(errormsg=res)
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return False, gone(
|
||||
gettext("Could not find the foreign server information.")
|
||||
)
|
||||
return False, gone(self.not_found_error_msg)
|
||||
|
||||
res['rows'][0]['is_sys_obj'] = (
|
||||
res['rows'][0]['oid'] <= self.datlastsysoid)
|
||||
@ -651,9 +650,7 @@ class ForeignServerView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
if len(res['rows']) == 0:
|
||||
return gone(
|
||||
gettext("Could not find the foreign server information.")
|
||||
)
|
||||
return gone(self.not_found_error_msg)
|
||||
|
||||
if res['rows'][0]['fsrvoptions'] is not None:
|
||||
res['rows'][0]['fsrvoptions'] = tokenize_options(
|
||||
@ -758,9 +755,7 @@ class ForeignServerView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
if len(res['rows']) == 0:
|
||||
return gone(
|
||||
gettext("Could not find the foreign server information.")
|
||||
)
|
||||
return gone(self.not_found_error_msg)
|
||||
|
||||
if fid is None and 'fdwid' in res['rows'][0]:
|
||||
fid = res['rows'][0]['fdwid']
|
||||
|
@ -179,6 +179,7 @@ class UserMappingView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
"""
|
||||
|
||||
node_type = blueprint.node_type
|
||||
node_label = "User Mapping"
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
@ -374,9 +375,7 @@ class UserMappingView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
return False, internal_server_error(errormsg=res)
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return False, gone(
|
||||
gettext("Could not find the user mapping information.")
|
||||
)
|
||||
return False, gone(self.not_found_error_msg)
|
||||
|
||||
res['rows'][0]['is_sys_obj'] = (
|
||||
res['rows'][0]['oid'] <= self.datlastsysoid)
|
||||
@ -672,9 +671,7 @@ class UserMappingView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
if len(res['rows']) == 0:
|
||||
return gone(
|
||||
gettext("Could not find the user mapping information.")
|
||||
)
|
||||
return gone(self.not_found_error_msg)
|
||||
|
||||
if res['rows'][0]['umoptions'] is not None:
|
||||
res['rows'][0]['umoptions'] = tokenize_options(
|
||||
@ -769,9 +766,7 @@ class UserMappingView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
if len(res['rows']) == 0:
|
||||
return gone(
|
||||
gettext("Could not find the user mapping information.")
|
||||
)
|
||||
return gone(self.not_found_error_msg)
|
||||
|
||||
if fsid is None and 'fsid' in res['rows'][0]:
|
||||
fsid = res['rows'][0]['fsid']
|
||||
|
@ -221,6 +221,8 @@ class NodeView(with_metaclass(MethodViewType, View)):
|
||||
|
||||
# Inherited class needs to modify these parameters
|
||||
node_type = None
|
||||
# Inherited class needs to modify these parameters
|
||||
node_label = None
|
||||
# This must be an array object with attributes (type and id)
|
||||
parent_ids = []
|
||||
# This must be an array object with attributes (type and id)
|
||||
@ -707,3 +709,8 @@ class PGChildNodeView(NodeView):
|
||||
)
|
||||
|
||||
return dependency
|
||||
|
||||
@property
|
||||
def not_found_error_msg(self):
|
||||
return gettext("Could not find the specified {}.".format(
|
||||
self.node_label).lower())
|
||||
|
15
web/pgadmin/utils/constants.py
Normal file
15
web/pgadmin/utils/constants.py
Normal file
@ -0,0 +1,15 @@
|
||||
##########################################################################
|
||||
#
|
||||
# pgAdmin 4 - PostgreSQL Tools
|
||||
#
|
||||
# Copyright (C) 2013 - 2020, The pgAdmin Development Team
|
||||
# This software is released under the PostgreSQL Licence
|
||||
#
|
||||
##########################################################################
|
||||
|
||||
"""Application wide constants."""
|
||||
|
||||
APP_JS = 'application/javascript'
|
||||
PGADMIN_NODE = 'pgadmin.node.%s'
|
||||
KEYBOARD_SHORTCUTS = 'Keyboard shortcuts'
|
||||
UNAUTH_REQ = "Unauthorized request."
|
Loading…
Reference in New Issue
Block a user