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