mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Code tidy.
This commit is contained in:
@@ -8,9 +8,9 @@
|
||||
##########################################################################
|
||||
|
||||
import json
|
||||
import six
|
||||
from abc import ABCMeta, abstractmethod, abstractproperty
|
||||
|
||||
import six
|
||||
from flask import current_app, render_template, url_for, make_response, flash
|
||||
from flask.ext.babel import gettext
|
||||
from flask.ext.login import current_user
|
||||
@@ -33,21 +33,20 @@ MODULE_NAME = 'browser'
|
||||
|
||||
|
||||
class BrowserModule(PgAdminModule):
|
||||
|
||||
LABEL = gettext('Browser')
|
||||
|
||||
def get_own_stylesheets(self):
|
||||
stylesheets = []
|
||||
# Add browser stylesheets
|
||||
for (endpoint, filename) in [
|
||||
('static', 'css/codemirror/codemirror.css'),
|
||||
('static', 'css/jQuery-contextMenu/jquery.contextMenu.css' if current_app.debug
|
||||
else 'css/jQuery-contextMenu/jquery.contextMenu.min.css'),
|
||||
('static', 'css/wcDocker/wcDocker.css' if current_app.debug
|
||||
else 'css/wcDocker/wcDocker.min.css'),
|
||||
('browser.static', 'css/browser.css'),
|
||||
('browser.static', 'css/aciTree/css/aciTree.css')
|
||||
]:
|
||||
('static', 'css/codemirror/codemirror.css'),
|
||||
('static', 'css/jQuery-contextMenu/jquery.contextMenu.css' if current_app.debug
|
||||
else 'css/jQuery-contextMenu/jquery.contextMenu.min.css'),
|
||||
('static', 'css/wcDocker/wcDocker.css' if current_app.debug
|
||||
else 'css/wcDocker/wcDocker.min.css'),
|
||||
('browser.static', 'css/browser.css'),
|
||||
('browser.static', 'css/aciTree/css/aciTree.css')
|
||||
]:
|
||||
stylesheets.append(url_for(endpoint, filename=filename))
|
||||
stylesheets.append(url_for('browser.browser_css'))
|
||||
return stylesheets
|
||||
@@ -57,122 +56,122 @@ class BrowserModule(PgAdminModule):
|
||||
scripts.append({
|
||||
'name': 'alertify',
|
||||
'path': url_for(
|
||||
'static',
|
||||
filename='js/alertifyjs/alertify' if current_app.debug
|
||||
else 'js/alertifyjs/alertify.min'
|
||||
),
|
||||
'static',
|
||||
filename='js/alertifyjs/alertify' if current_app.debug
|
||||
else 'js/alertifyjs/alertify.min'
|
||||
),
|
||||
'exports': 'alertify',
|
||||
'preloaded': True
|
||||
})
|
||||
})
|
||||
scripts.append({
|
||||
'name': 'jqueryui.position',
|
||||
'path': url_for(
|
||||
'static',
|
||||
filename='js/jQuery-contextMenu/jquery.ui.position' if \
|
||||
current_app.debug else \
|
||||
'js/jQuery-contextMenu/jquery.ui.position.min'
|
||||
),
|
||||
current_app.debug else \
|
||||
'js/jQuery-contextMenu/jquery.ui.position.min'
|
||||
),
|
||||
'deps': ['jquery'],
|
||||
'exports': 'jQuery.ui.position',
|
||||
'preloaded': True
|
||||
})
|
||||
})
|
||||
scripts.append({
|
||||
'name': 'jquery.contextmenu',
|
||||
'path': url_for(
|
||||
'static',
|
||||
filename='js/jQuery-contextMenu/jquery.contextMenu' if \
|
||||
current_app.debug else \
|
||||
'js/jQuery-contextMenu/jquery.contextMenu.min'
|
||||
),
|
||||
current_app.debug else \
|
||||
'js/jQuery-contextMenu/jquery.contextMenu.min'
|
||||
),
|
||||
'deps': ['jquery', 'jqueryui.position'],
|
||||
'exports': 'jQuery.contextMenu',
|
||||
'preloaded': True
|
||||
})
|
||||
})
|
||||
scripts.append({
|
||||
'name': 'jquery.aciplugin',
|
||||
'path': url_for(
|
||||
'browser.static',
|
||||
filename='js/aciTree/jquery.aciPlugin.min'
|
||||
),
|
||||
'browser.static',
|
||||
filename='js/aciTree/jquery.aciPlugin.min'
|
||||
),
|
||||
'deps': ['jquery'],
|
||||
'exports': 'aciPluginClass',
|
||||
'preloaded': True
|
||||
})
|
||||
})
|
||||
scripts.append({
|
||||
'name': 'jquery.acitree',
|
||||
'path': url_for(
|
||||
'browser.static',
|
||||
filename='js/aciTree/jquery.aciTree' if
|
||||
current_app.debug else 'js/aciTree/jquery.aciTree.min'
|
||||
),
|
||||
'browser.static',
|
||||
filename='js/aciTree/jquery.aciTree' if
|
||||
current_app.debug else 'js/aciTree/jquery.aciTree.min'
|
||||
),
|
||||
'deps': ['jquery', 'jquery.aciplugin'],
|
||||
'exports': 'aciPluginClass.plugins.aciTree',
|
||||
'preloaded': True
|
||||
})
|
||||
})
|
||||
scripts.append({
|
||||
'name': 'jquery.acisortable',
|
||||
'path': url_for(
|
||||
'browser.static',
|
||||
filename='js/aciTree/jquery.aciSortable.min'
|
||||
),
|
||||
'browser.static',
|
||||
filename='js/aciTree/jquery.aciSortable.min'
|
||||
),
|
||||
'deps': ['jquery', 'jquery.aciplugin'],
|
||||
'exports': 'aciPluginClass.plugins.aciSortable',
|
||||
'when': None,
|
||||
'preloaded': True
|
||||
})
|
||||
})
|
||||
scripts.append({
|
||||
'name': 'jquery.acifragment',
|
||||
'path': url_for(
|
||||
'browser.static',
|
||||
filename='js/aciTree/jquery.aciFragment.min'
|
||||
),
|
||||
'browser.static',
|
||||
filename='js/aciTree/jquery.aciFragment.min'
|
||||
),
|
||||
'deps': ['jquery', 'jquery.aciplugin'],
|
||||
'exports': 'aciPluginClass.plugins.aciFragment',
|
||||
'when': None,
|
||||
'preloaded': True
|
||||
})
|
||||
})
|
||||
scripts.append({
|
||||
'name': 'wcdocker',
|
||||
'path': url_for(
|
||||
'static',
|
||||
filename='js/wcDocker/wcDocker' if current_app.debug
|
||||
else 'js/wcDocker/wcDocker.min'
|
||||
),
|
||||
'static',
|
||||
filename='js/wcDocker/wcDocker' if current_app.debug
|
||||
else 'js/wcDocker/wcDocker.min'
|
||||
),
|
||||
'deps': ['jquery.contextmenu'],
|
||||
'exports': '',
|
||||
'preloaded': True
|
||||
})
|
||||
})
|
||||
|
||||
scripts.append({
|
||||
'name': 'pgadmin.browser.datamodel',
|
||||
'path': url_for('browser.static', filename='js/datamodel'),
|
||||
'preloaded': True
|
||||
})
|
||||
})
|
||||
|
||||
for name, script in [
|
||||
['pgadmin.browser', 'js/browser'],
|
||||
['pgadmin.browser.error', 'js/error']]:
|
||||
['pgadmin.browser', 'js/browser'],
|
||||
['pgadmin.browser.error', 'js/error']]:
|
||||
scripts.append({
|
||||
'name': name,
|
||||
'path': url_for('browser.index') + script,
|
||||
'preloaded': True
|
||||
})
|
||||
})
|
||||
|
||||
for name, script in [
|
||||
['pgadmin.browser.node', 'js/node'],
|
||||
['pgadmin.browser.messages', 'js/messages'],
|
||||
['pgadmin.browser.collection', 'js/collection']]:
|
||||
['pgadmin.browser.node', 'js/node'],
|
||||
['pgadmin.browser.messages', 'js/messages'],
|
||||
['pgadmin.browser.collection', 'js/collection']]:
|
||||
scripts.append({
|
||||
'name': name,
|
||||
'path': url_for('browser.index') + script,
|
||||
'preloaded': True,
|
||||
'deps': ['pgadmin.browser.datamodel']
|
||||
})
|
||||
})
|
||||
|
||||
for name, end in [
|
||||
['pgadmin.browser.menu', 'js/menu'],
|
||||
['pgadmin.browser.panel', 'js/panel'],
|
||||
['pgadmin.browser.frame', 'js/frame']]:
|
||||
['pgadmin.browser.menu', 'js/menu'],
|
||||
['pgadmin.browser.panel', 'js/panel'],
|
||||
['pgadmin.browser.frame', 'js/frame']]:
|
||||
scripts.append({
|
||||
'name': name, 'path': url_for('browser.static', filename=end),
|
||||
'preloaded': True})
|
||||
@@ -181,7 +180,7 @@ class BrowserModule(PgAdminModule):
|
||||
'name': 'pgadmin.browser.node.ui',
|
||||
'path': url_for('browser.static', filename='js/node.ui'),
|
||||
'when': 'server-group'
|
||||
})
|
||||
})
|
||||
|
||||
for module in self.submodules:
|
||||
scripts.extend(module.get_own_javascripts())
|
||||
@@ -192,7 +191,8 @@ class BrowserModule(PgAdminModule):
|
||||
'display', 'show_system_objects',
|
||||
gettext("Show system objects"), 'boolean', False,
|
||||
category_label=gettext('Display')
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
blueprint = BrowserModule(MODULE_NAME, __name__)
|
||||
|
||||
@@ -238,10 +238,10 @@ class BrowserPluginModule(PgAdminModule):
|
||||
self.pref_show_node = None
|
||||
|
||||
super(BrowserPluginModule, self).__init__(
|
||||
"NODE-%s" % self.node_type,
|
||||
import_name,
|
||||
**kwargs
|
||||
)
|
||||
"NODE-%s" % self.node_type,
|
||||
import_name,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
@property
|
||||
def jssnippets(self):
|
||||
@@ -275,7 +275,7 @@ class BrowserPluginModule(PgAdminModule):
|
||||
'name': 'pgadmin.node.%s' % self.node_type,
|
||||
'path': url_for('browser.index') + '%s/module' % self.node_type,
|
||||
'when': self.script_load
|
||||
}])
|
||||
}])
|
||||
|
||||
for module in self.submodules:
|
||||
scripts.extend(module.get_own_javascripts())
|
||||
@@ -283,7 +283,7 @@ class BrowserPluginModule(PgAdminModule):
|
||||
|
||||
def generate_browser_node(
|
||||
self, node_id, parent_id, label, icon, inode, node_type, **kwargs
|
||||
):
|
||||
):
|
||||
"""
|
||||
Helper function to create a browser node for this particular subnode.
|
||||
|
||||
@@ -306,31 +306,30 @@ class BrowserPluginModule(PgAdminModule):
|
||||
browser tree.
|
||||
"""
|
||||
obj = {
|
||||
"id": "%s/%s" % (node_type, node_id),
|
||||
"label": label,
|
||||
"icon": icon,
|
||||
"inode": inode,
|
||||
"_type": node_type,
|
||||
"_id": node_id,
|
||||
"_pid": parent_id,
|
||||
"module": 'pgadmin.node.%s' % node_type
|
||||
}
|
||||
"id": "%s/%s" % (node_type, node_id),
|
||||
"label": label,
|
||||
"icon": icon,
|
||||
"inode": inode,
|
||||
"_type": node_type,
|
||||
"_id": node_id,
|
||||
"_pid": parent_id,
|
||||
"module": 'pgadmin.node.%s' % node_type
|
||||
}
|
||||
for key in kwargs:
|
||||
obj.setdefault(key, kwargs[key])
|
||||
return obj
|
||||
|
||||
|
||||
@property
|
||||
def csssnippets(self):
|
||||
"""
|
||||
Returns a snippet of css to include in the page
|
||||
"""
|
||||
snippets = [
|
||||
render_template(
|
||||
"browser/css/node.css",
|
||||
node_type=self.node_type,
|
||||
_=gettext
|
||||
)]
|
||||
render_template(
|
||||
"browser/css/node.css",
|
||||
node_type=self.node_type,
|
||||
_=gettext
|
||||
)]
|
||||
|
||||
for submodule in self.submodules:
|
||||
snippets.extend(submodule.csssnippets)
|
||||
@@ -417,11 +416,11 @@ class BrowserPluginModule(PgAdminModule):
|
||||
self.browser_preference = blueprint.preference
|
||||
self.pref_show_system_objects = blueprint.preference.preference(
|
||||
'display', 'show_system_objects'
|
||||
)
|
||||
)
|
||||
self.pref_show_node = self.browser_preference.preference(
|
||||
'node', 'show_node_' + self.node_type,
|
||||
self.label, 'boolean', self.SHOW_ON_BROWSER, category_label=gettext('Nodes')
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@blueprint.route("/")
|
||||
@@ -475,11 +474,11 @@ def index():
|
||||
flash(msg, 'warning')
|
||||
|
||||
return render_template(
|
||||
MODULE_NAME + "/index.html",
|
||||
username=current_user.email,
|
||||
is_admin=current_user.has_role("Administrator"),
|
||||
_=gettext
|
||||
)
|
||||
MODULE_NAME + "/index.html",
|
||||
username=current_user.email,
|
||||
is_admin=current_user.has_role("Administrator"),
|
||||
_=gettext
|
||||
)
|
||||
|
||||
|
||||
@blueprint.route("/js/browser.js")
|
||||
@@ -499,23 +498,23 @@ def browser_js():
|
||||
for submodule in current_blueprint.submodules:
|
||||
snippets.extend(submodule.jssnippets)
|
||||
return make_response(
|
||||
render_template(
|
||||
'browser/js/browser.js',
|
||||
layout=layout,
|
||||
jssnippets=snippets,
|
||||
pg_help_path=pg_help_path,
|
||||
edbas_help_path=edbas_help_path,
|
||||
_=gettext
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'})
|
||||
render_template(
|
||||
'browser/js/browser.js',
|
||||
layout=layout,
|
||||
jssnippets=snippets,
|
||||
pg_help_path=pg_help_path,
|
||||
edbas_help_path=edbas_help_path,
|
||||
_=gettext
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'})
|
||||
|
||||
|
||||
@blueprint.route("/js/error.js")
|
||||
@login_required
|
||||
def error_js():
|
||||
return make_response(
|
||||
render_template('browser/js/error.js', _=gettext),
|
||||
200, {'Content-Type': 'application/x-javascript'})
|
||||
render_template('browser/js/error.js', _=gettext),
|
||||
200, {'Content-Type': 'application/x-javascript'})
|
||||
|
||||
|
||||
@blueprint.route("/js/node.js")
|
||||
@@ -530,26 +529,27 @@ def node_js():
|
||||
edbas_help_path = edbas_help_path_pref.get()
|
||||
|
||||
return make_response(
|
||||
render_template('browser/js/node.js',
|
||||
pg_help_path=pg_help_path,
|
||||
edbas_help_path=edbas_help_path,
|
||||
_=gettext
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'})
|
||||
render_template('browser/js/node.js',
|
||||
pg_help_path=pg_help_path,
|
||||
edbas_help_path=edbas_help_path,
|
||||
_=gettext
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'})
|
||||
|
||||
|
||||
@blueprint.route("/js/messages.js")
|
||||
def messages_js():
|
||||
return make_response(
|
||||
render_template('browser/js/messages.js', _=gettext),
|
||||
200, {'Content-Type': 'application/x-javascript'})
|
||||
render_template('browser/js/messages.js', _=gettext),
|
||||
200, {'Content-Type': 'application/x-javascript'})
|
||||
|
||||
|
||||
@blueprint.route("/js/collection.js")
|
||||
@login_required
|
||||
def collection_js():
|
||||
return make_response(
|
||||
render_template('browser/js/collection.js', _=gettext),
|
||||
200, {'Content-Type': 'application/x-javascript'})
|
||||
render_template('browser/js/collection.js', _=gettext),
|
||||
200, {'Content-Type': 'application/x-javascript'})
|
||||
|
||||
|
||||
@blueprint.route("/browser.css")
|
||||
@@ -560,10 +560,10 @@ def browser_css():
|
||||
for submodule in blueprint.submodules:
|
||||
snippets.extend(submodule.csssnippets)
|
||||
return make_response(
|
||||
render_template(
|
||||
'browser/css/browser.css', snippets=snippets, _=gettext
|
||||
),
|
||||
200, {'Content-Type': 'text/css'})
|
||||
render_template(
|
||||
'browser/css/browser.css', snippets=snippets, _=gettext
|
||||
),
|
||||
200, {'Content-Type': 'text/css'})
|
||||
|
||||
|
||||
@blueprint.route("/nodes/")
|
||||
|
||||
@@ -35,7 +35,7 @@ class CollectionNodeModule(PgAdminModule, PGChildModule):
|
||||
"NODE-%s" % self.node_type,
|
||||
import_name,
|
||||
**kwargs
|
||||
)
|
||||
)
|
||||
PGChildModule.__init__(self)
|
||||
|
||||
@property
|
||||
@@ -52,7 +52,7 @@ class CollectionNodeModule(PgAdminModule, PGChildModule):
|
||||
'name': 'pgadmin.node.%s' % self.node_type,
|
||||
'path': url_for('browser.index') + '%s/module' % self.node_type,
|
||||
'when': self.script_load
|
||||
}])
|
||||
}])
|
||||
|
||||
for module in self.submodules:
|
||||
scripts.extend(module.get_own_javascripts())
|
||||
@@ -61,32 +61,32 @@ class CollectionNodeModule(PgAdminModule, PGChildModule):
|
||||
|
||||
def generate_browser_node(
|
||||
self, node_id, parent_id, label, icon, **kwargs
|
||||
):
|
||||
):
|
||||
obj = {
|
||||
"id": "%s/%s" % (self.node_type, node_id),
|
||||
"label": label,
|
||||
"icon": self.node_icon if not icon else icon,
|
||||
"inode": self.node_inode,
|
||||
"_type": self.node_type,
|
||||
"_id": node_id,
|
||||
"_pid": parent_id,
|
||||
"module": 'pgadmin.node.%s' % self.node_type
|
||||
}
|
||||
"id": "%s/%s" % (self.node_type, node_id),
|
||||
"label": label,
|
||||
"icon": self.node_icon if not icon else icon,
|
||||
"inode": self.node_inode,
|
||||
"_type": self.node_type,
|
||||
"_id": node_id,
|
||||
"_pid": parent_id,
|
||||
"module": 'pgadmin.node.%s' % self.node_type
|
||||
}
|
||||
for key in kwargs:
|
||||
obj.setdefault(key, kwargs[key])
|
||||
return obj
|
||||
|
||||
def generate_browser_collection_node(self, parent_id, **kwargs):
|
||||
obj = {
|
||||
"id": "coll-%s/%d" % (self.node_type, parent_id),
|
||||
"label": self.collection_label,
|
||||
"icon": self.collection_icon,
|
||||
"inode": True,
|
||||
"_type": 'coll-%s' % (self.node_type),
|
||||
"_id": parent_id,
|
||||
"_pid": parent_id,
|
||||
"module": 'pgadmin.node.%s' % self.node_type
|
||||
}
|
||||
"id": "coll-%s/%d" % (self.node_type, parent_id),
|
||||
"label": self.collection_label,
|
||||
"icon": self.collection_icon,
|
||||
"inode": True,
|
||||
"_type": 'coll-%s' % (self.node_type),
|
||||
"_id": parent_id,
|
||||
"_pid": parent_id,
|
||||
"module": 'pgadmin.node.%s' % self.node_type
|
||||
}
|
||||
|
||||
for key in kwargs:
|
||||
obj.setdefault(key, kwargs[key])
|
||||
@@ -103,16 +103,16 @@ class CollectionNodeModule(PgAdminModule, PGChildModule):
|
||||
Returns a snippet of css to include in the page
|
||||
"""
|
||||
snippets = [
|
||||
render_template(
|
||||
"browser/css/collection.css",
|
||||
node_type=self.node_type
|
||||
),
|
||||
render_template(
|
||||
"browser/css/node.css",
|
||||
node_type=self.node_type,
|
||||
_=gettext
|
||||
)
|
||||
]
|
||||
render_template(
|
||||
"browser/css/collection.css",
|
||||
node_type=self.node_type
|
||||
),
|
||||
render_template(
|
||||
"browser/css/node.css",
|
||||
node_type=self.node_type,
|
||||
_=gettext
|
||||
)
|
||||
]
|
||||
|
||||
for submodule in self.submodules:
|
||||
snippets.extend(submodule.csssnippets)
|
||||
@@ -136,14 +136,14 @@ class CollectionNodeModule(PgAdminModule, PGChildModule):
|
||||
"""
|
||||
icon to be displayed for the browser collection node
|
||||
"""
|
||||
return 'icon-coll-%s' % (self.node_type)
|
||||
return 'icon-coll-%s' % (self.node_type)
|
||||
|
||||
@property
|
||||
def node_icon(self):
|
||||
"""
|
||||
icon to be displayed for the browser nodes
|
||||
"""
|
||||
return 'icon-%s' % (self.node_type)
|
||||
return 'icon-%s' % (self.node_type)
|
||||
|
||||
@property
|
||||
def node_inode(self):
|
||||
@@ -218,10 +218,10 @@ class CollectionNodeModule(PgAdminModule, PGChildModule):
|
||||
# Add the node informaton for browser, not in respective node preferences
|
||||
self.browser_preference = Preferences.module('browser')
|
||||
self.pref_show_system_objects = self.browser_preference.preference(
|
||||
'show_system_objects'
|
||||
)
|
||||
'show_system_objects'
|
||||
)
|
||||
self.pref_show_node = self.browser_preference.register(
|
||||
'node', 'show_node_' + self.node_type,
|
||||
self.collection_label, 'node', self.SHOW_ON_BROWSER,
|
||||
category_label=gettext('Nodes')
|
||||
)
|
||||
'node', 'show_node_' + self.node_type,
|
||||
self.collection_label, 'node', self.SHOW_ON_BROWSER,
|
||||
category_label=gettext('Nodes')
|
||||
)
|
||||
|
||||
@@ -25,7 +25,6 @@ from pgadmin.model import db, ServerGroup
|
||||
|
||||
|
||||
class ServerGroupModule(BrowserPluginModule):
|
||||
|
||||
NODE_TYPE = "server-group"
|
||||
|
||||
def get_nodes(self, *arg, **kwargs):
|
||||
@@ -35,13 +34,13 @@ class ServerGroupModule(BrowserPluginModule):
|
||||
).order_by("id")
|
||||
for idx, group in enumerate(groups):
|
||||
yield self.generate_browser_node(
|
||||
"%d" % (group.id), None,
|
||||
group.name,
|
||||
"icon-%s" % self.node_type,
|
||||
True,
|
||||
self.node_type,
|
||||
can_delete=True if idx > 0 else False
|
||||
)
|
||||
"%d" % (group.id), None,
|
||||
group.name,
|
||||
"icon-%s" % self.node_type,
|
||||
True,
|
||||
self.node_type,
|
||||
can_delete=True if idx > 0 else False
|
||||
)
|
||||
|
||||
@property
|
||||
def node_type(self):
|
||||
@@ -71,18 +70,17 @@ class ServerGroupModule(BrowserPluginModule):
|
||||
|
||||
|
||||
class ServerGroupMenuItem(MenuItem):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
kwargs.setdefault("type", ServerGroupModule.NODE_TYPE)
|
||||
super(ServerGroupMenuItem, self).__init__(**kwargs)
|
||||
|
||||
|
||||
@six.add_metaclass(ABCMeta)
|
||||
class ServerGroupPluginModule(BrowserPluginModule):
|
||||
"""
|
||||
Base class for server group plugins.
|
||||
"""
|
||||
|
||||
|
||||
@abstractmethod
|
||||
def get_nodes(self, *arg, **kwargs):
|
||||
pass
|
||||
@@ -92,7 +90,6 @@ blueprint = ServerGroupModule(__name__, static_url_path='')
|
||||
|
||||
|
||||
class ServerGroupView(NodeView):
|
||||
|
||||
node_type = ServerGroupModule.NODE_TYPE
|
||||
parent_ids = []
|
||||
ids = [{'type': 'int', 'id': 'gid'}]
|
||||
@@ -102,11 +99,11 @@ class ServerGroupView(NodeView):
|
||||
|
||||
for sg in ServerGroup.query.filter_by(
|
||||
user_id=current_user.id
|
||||
).order_by('name'):
|
||||
).order_by('name'):
|
||||
res.append({
|
||||
'id': sg.id,
|
||||
'name': sg.name
|
||||
})
|
||||
})
|
||||
|
||||
return ajax_response(response=res, status=200)
|
||||
|
||||
@@ -122,32 +119,32 @@ class ServerGroupView(NodeView):
|
||||
|
||||
if sg.id == gid:
|
||||
return make_json_response(
|
||||
status=417,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'The specified server group cannot be deleted.'
|
||||
)
|
||||
)
|
||||
status=417,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'The specified server group cannot be deleted.'
|
||||
)
|
||||
)
|
||||
|
||||
# There can be only one record at most
|
||||
sg = groups.filter_by(id=gid).first()
|
||||
|
||||
if sg is None:
|
||||
return make_json_response(
|
||||
status=417,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'The specified server group could not be found.'
|
||||
)
|
||||
)
|
||||
status=417,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'The specified server group could not be found.'
|
||||
)
|
||||
)
|
||||
else:
|
||||
try:
|
||||
db.session.delete(sg)
|
||||
db.session.commit()
|
||||
except Exception as e:
|
||||
return make_json_response(
|
||||
status=410, success=0, errormsg=e.message
|
||||
)
|
||||
status=410, success=0, errormsg=e.message
|
||||
)
|
||||
|
||||
return make_json_response(result=request.form)
|
||||
|
||||
@@ -156,19 +153,19 @@ class ServerGroupView(NodeView):
|
||||
|
||||
# There can be only one record at most
|
||||
servergroup = ServerGroup.query.filter_by(
|
||||
user_id=current_user.id,
|
||||
id=gid).first()
|
||||
user_id=current_user.id,
|
||||
id=gid).first()
|
||||
|
||||
data = request.form if request.form else json.loads(request.data.decode())
|
||||
|
||||
if servergroup is None:
|
||||
return make_json_response(
|
||||
status=417,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'The specified server group could not be found.'
|
||||
)
|
||||
)
|
||||
status=417,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'The specified server group could not be found.'
|
||||
)
|
||||
)
|
||||
else:
|
||||
try:
|
||||
if u'name' in data:
|
||||
@@ -176,8 +173,8 @@ class ServerGroupView(NodeView):
|
||||
db.session.commit()
|
||||
except Exception as e:
|
||||
return make_json_response(
|
||||
status=410, success=0, errormsg=e.message
|
||||
)
|
||||
status=410, success=0, errormsg=e.message
|
||||
)
|
||||
|
||||
return make_json_response(result=request.form)
|
||||
|
||||
@@ -186,22 +183,22 @@ class ServerGroupView(NodeView):
|
||||
|
||||
# There can be only one record at most
|
||||
sg = ServerGroup.query.filter_by(
|
||||
user_id=current_user.id,
|
||||
id=gid).first()
|
||||
user_id=current_user.id,
|
||||
id=gid).first()
|
||||
|
||||
if sg is None:
|
||||
return make_json_response(
|
||||
status=417,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'The specified server group could not be found.'
|
||||
)
|
||||
)
|
||||
status=417,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'The specified server group could not be found.'
|
||||
)
|
||||
)
|
||||
else:
|
||||
return ajax_response(
|
||||
response={'id': sg.id, 'name': sg.name},
|
||||
status=200
|
||||
)
|
||||
response={'id': sg.id, 'name': sg.name},
|
||||
status=200
|
||||
)
|
||||
|
||||
def create(self):
|
||||
data = request.form if request.form else json.loads(request.data.decode())
|
||||
@@ -229,26 +226,26 @@ class ServerGroupView(NodeView):
|
||||
data[u'name'] = sg.name
|
||||
|
||||
return jsonify(
|
||||
node=self.blueprint.generate_browser_node(
|
||||
"%d" % (sg.id), None,
|
||||
sg.name,
|
||||
"icon-%s" % self.node_type,
|
||||
True,
|
||||
self.node_type,
|
||||
can_delete=True # This is user created hence can deleted
|
||||
)
|
||||
)
|
||||
node=self.blueprint.generate_browser_node(
|
||||
"%d" % (sg.id), None,
|
||||
sg.name,
|
||||
"icon-%s" % self.node_type,
|
||||
True,
|
||||
self.node_type,
|
||||
can_delete=True # This is user created hence can deleted
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
return make_json_response(
|
||||
status=410,
|
||||
success=0,
|
||||
errormsg=e.message)
|
||||
status=410,
|
||||
success=0,
|
||||
errormsg=e.message)
|
||||
|
||||
else:
|
||||
return make_json_response(
|
||||
status=417,
|
||||
success=0,
|
||||
errormsg=gettext('No server group name was specified'))
|
||||
status=417,
|
||||
success=0,
|
||||
errormsg=gettext('No server group name was specified'))
|
||||
|
||||
def sql(self, gid):
|
||||
return make_json_response(status=422)
|
||||
@@ -271,9 +268,9 @@ class ServerGroupView(NodeView):
|
||||
Override this property for your own logic.
|
||||
"""
|
||||
return make_response(
|
||||
render_template("server_groups/server_groups.js"),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
render_template("server_groups/server_groups.js"),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
|
||||
def nodes(self, gid=None):
|
||||
"""Return a JSON document listing the server groups for the user"""
|
||||
@@ -283,18 +280,18 @@ class ServerGroupView(NodeView):
|
||||
groups = ServerGroup.query.filter_by(user_id=current_user.id)
|
||||
else:
|
||||
groups = ServerGroup.query.filter_by(user_id=current_user.id,
|
||||
id=gid).first()
|
||||
id=gid).first()
|
||||
|
||||
for group in groups:
|
||||
nodes.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
"%d" % (group.id), None,
|
||||
group.name,
|
||||
"icon-%s" % self.node_type,
|
||||
True,
|
||||
self.node_type
|
||||
)
|
||||
)
|
||||
self.blueprint.generate_browser_node(
|
||||
"%d" % (group.id), None,
|
||||
group.name,
|
||||
"icon-%s" % self.node_type,
|
||||
True,
|
||||
self.node_type
|
||||
)
|
||||
)
|
||||
|
||||
return make_json_response(data=nodes)
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import traceback
|
||||
|
||||
import pgadmin.browser.server_groups as sg
|
||||
from flask import render_template, request, make_response, jsonify, \
|
||||
current_app, url_for
|
||||
current_app, url_for
|
||||
from flask.ext.babel import gettext
|
||||
from flask.ext.security import current_user
|
||||
from pgadmin.browser.server_groups.servers.types import ServerType
|
||||
@@ -91,21 +91,21 @@ class ServerModule(sg.ServerGroupPluginModule):
|
||||
wal_paused = None
|
||||
|
||||
yield self.generate_browser_node(
|
||||
"%d" % (server.id),
|
||||
gid,
|
||||
server.name,
|
||||
"icon-server-not-connected" if not connected else
|
||||
"icon-{0}".format(manager.server_type),
|
||||
True,
|
||||
self.NODE_TYPE,
|
||||
connected=connected,
|
||||
server_type=manager.server_type if connected else "pg",
|
||||
version=manager.version,
|
||||
db=manager.db,
|
||||
user=manager.user_info if connected else None,
|
||||
in_recovery=in_recovery,
|
||||
wal_pause=wal_paused
|
||||
)
|
||||
"%d" % (server.id),
|
||||
gid,
|
||||
server.name,
|
||||
"icon-server-not-connected" if not connected else
|
||||
"icon-{0}".format(manager.server_type),
|
||||
True,
|
||||
self.NODE_TYPE,
|
||||
connected=connected,
|
||||
server_type=manager.server_type if connected else "pg",
|
||||
version=manager.version,
|
||||
db=manager.db,
|
||||
user=manager.user_info if connected else None,
|
||||
in_recovery=in_recovery,
|
||||
wal_pause=wal_paused
|
||||
)
|
||||
|
||||
@property
|
||||
def jssnippets(self):
|
||||
@@ -133,17 +133,17 @@ class ServerModule(sg.ServerGroupPluginModule):
|
||||
'name': 'pgadmin.node.server',
|
||||
'path': url_for('browser.index') + '%s/module' % self.node_type,
|
||||
'when': self.script_load
|
||||
},
|
||||
{
|
||||
'name': 'pgadmin.browser.server.privilege',
|
||||
'path': url_for('browser.index') + 'server/static/js/privilege',
|
||||
'when': self.node_type,
|
||||
'deps': ['pgadmin.browser.node.ui']
|
||||
},
|
||||
{
|
||||
'name': 'pgadmin.browser.server.privilege',
|
||||
'path': url_for('browser.index') + 'server/static/js/privilege',
|
||||
'when': self.node_type,
|
||||
'deps': ['pgadmin.browser.node.ui']
|
||||
},
|
||||
{
|
||||
'name': 'pgadmin.browser.server.variable',
|
||||
'path': url_for('browser.index') + 'server/static/js/variable',
|
||||
'when': self.node_type
|
||||
'name': 'pgadmin.browser.server.variable',
|
||||
'path': url_for('browser.index') + 'server/static/js/variable',
|
||||
'when': self.node_type
|
||||
}])
|
||||
|
||||
for module in self.submodules:
|
||||
@@ -175,6 +175,7 @@ class ServerModule(sg.ServerGroupPluginModule):
|
||||
"""
|
||||
ServerType.register_preferences()
|
||||
|
||||
|
||||
class ServerMenuItem(MenuItem):
|
||||
def __init__(self, **kwargs):
|
||||
kwargs.setdefault("type", ServerModule.NODE_TYPE)
|
||||
@@ -183,6 +184,7 @@ class ServerMenuItem(MenuItem):
|
||||
|
||||
blueprint = ServerModule(__name__)
|
||||
|
||||
|
||||
class ServerNode(PGChildNodeView):
|
||||
node_type = ServerModule.NODE_TYPE
|
||||
|
||||
@@ -207,7 +209,7 @@ class ServerNode(PGChildNodeView):
|
||||
[{'post': 'create_restore_point'}],
|
||||
'connect': [{
|
||||
'get': 'connect_status', 'post': 'connect', 'delete': 'disconnect'
|
||||
}],
|
||||
}],
|
||||
'change_password': [{'post': 'change_password'}],
|
||||
'wal_replay': [{
|
||||
'delete': 'pause_wal_replay', 'put': 'resume_wal_replay'
|
||||
@@ -265,26 +267,26 @@ class ServerNode(PGChildNodeView):
|
||||
user=manager.user_info if connected else None,
|
||||
in_recovery=in_recovery,
|
||||
wal_pause=wal_paused
|
||||
)
|
||||
)
|
||||
)
|
||||
return make_json_response(result=res)
|
||||
|
||||
def node(self, gid, sid):
|
||||
"""Return a JSON document listing the server groups for the user"""
|
||||
server = Server.query.filter_by(user_id=current_user.id,
|
||||
servergroup_id=gid,
|
||||
id=sid).first()
|
||||
servergroup_id=gid,
|
||||
id=sid).first()
|
||||
|
||||
if server is None:
|
||||
return make_json_response(
|
||||
status=410,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
gettext(
|
||||
"Couldn't find the server with id# %s!"
|
||||
).format(sid)
|
||||
)
|
||||
status=410,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
gettext(
|
||||
"Couldn't find the server with id# %s!"
|
||||
).format(sid)
|
||||
)
|
||||
)
|
||||
|
||||
from pgadmin.utils.driver import get_driver
|
||||
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(server.id)
|
||||
@@ -310,23 +312,23 @@ class ServerNode(PGChildNodeView):
|
||||
wal_paused = None
|
||||
|
||||
return make_json_response(
|
||||
result=self.blueprint.generate_browser_node(
|
||||
"%d" % (server.id),
|
||||
gid,
|
||||
server.name,
|
||||
"icon-server-not-connected" if not connected else
|
||||
"icon-{0}".format(manager.server_type),
|
||||
True,
|
||||
self.node_type,
|
||||
connected=connected,
|
||||
server_type=manager.server_type if connected else 'pg',
|
||||
version=manager.version,
|
||||
db=manager.db,
|
||||
user=manager.user_info if connected else None,
|
||||
in_recovery=in_recovery,
|
||||
wal_pause=wal_paused
|
||||
)
|
||||
)
|
||||
result=self.blueprint.generate_browser_node(
|
||||
"%d" % (server.id),
|
||||
gid,
|
||||
server.name,
|
||||
"icon-server-not-connected" if not connected else
|
||||
"icon-{0}".format(manager.server_type),
|
||||
True,
|
||||
self.node_type,
|
||||
connected=connected,
|
||||
server_type=manager.server_type if connected else 'pg',
|
||||
version=manager.version,
|
||||
db=manager.db,
|
||||
user=manager.user_info if connected else None,
|
||||
in_recovery=in_recovery,
|
||||
wal_pause=wal_paused
|
||||
)
|
||||
)
|
||||
|
||||
def delete(self, gid, sid):
|
||||
"""Delete a server node in the settings database."""
|
||||
@@ -365,7 +367,7 @@ class ServerNode(PGChildNodeView):
|
||||
def update(self, gid, sid):
|
||||
"""Update the server settings"""
|
||||
server = Server.query.filter_by(
|
||||
user_id=current_user.id, id=sid).first()
|
||||
user_id=current_user.id, id=sid).first()
|
||||
|
||||
if server is None:
|
||||
return make_json_response(
|
||||
@@ -384,7 +386,7 @@ class ServerNode(PGChildNodeView):
|
||||
'gid': 'servergroup_id',
|
||||
'comment': 'comment',
|
||||
'role': 'role'
|
||||
}
|
||||
}
|
||||
|
||||
disp_lbl = {
|
||||
'name': gettext('name'),
|
||||
@@ -408,13 +410,13 @@ class ServerNode(PGChildNodeView):
|
||||
if connected:
|
||||
for arg in (
|
||||
'host', 'port', 'db', 'username', 'sslmode', 'role'
|
||||
):
|
||||
):
|
||||
if arg in data:
|
||||
return forbidden(
|
||||
errormsg=gettext(
|
||||
"'{0}' is not allowed to modify, when server is connected."
|
||||
).format(disp_lbl[arg])
|
||||
)
|
||||
errormsg=gettext(
|
||||
"'{0}' is not allowed to modify, when server is connected."
|
||||
).format(disp_lbl[arg])
|
||||
)
|
||||
|
||||
for arg in config_param_map:
|
||||
if arg in data:
|
||||
@@ -461,12 +463,12 @@ class ServerNode(PGChildNodeView):
|
||||
Return list of attributes of all servers.
|
||||
"""
|
||||
servers = Server.query.filter_by(
|
||||
user_id=current_user.id,
|
||||
servergroup_id=gid).order_by(Server.name)
|
||||
user_id=current_user.id,
|
||||
servergroup_id=gid).order_by(Server.name)
|
||||
sg = ServerGroup.query.filter_by(
|
||||
user_id=current_user.id,
|
||||
id=gid
|
||||
).first()
|
||||
user_id=current_user.id,
|
||||
id=gid
|
||||
).first()
|
||||
res = []
|
||||
|
||||
from pgadmin.utils.driver import get_driver
|
||||
@@ -491,10 +493,10 @@ class ServerNode(PGChildNodeView):
|
||||
'connected': connected,
|
||||
'version': manager.ver,
|
||||
'server_type': manager.server_type if connected else 'pg'
|
||||
})
|
||||
})
|
||||
|
||||
return ajax_response(
|
||||
response=res
|
||||
response=res
|
||||
)
|
||||
|
||||
def properties(self, gid, sid):
|
||||
@@ -599,9 +601,9 @@ class ServerNode(PGChildNodeView):
|
||||
password = None
|
||||
|
||||
status, errmsg = conn.connect(
|
||||
password=password,
|
||||
server_types=ServerType.types()
|
||||
)
|
||||
password=password,
|
||||
server_types=ServerType.types()
|
||||
)
|
||||
|
||||
if not status:
|
||||
db.session.delete(server)
|
||||
@@ -617,17 +619,17 @@ class ServerNode(PGChildNodeView):
|
||||
icon = "icon-pg"
|
||||
|
||||
return jsonify(
|
||||
node=self.blueprint.generate_browser_node(
|
||||
"%d" % server.id, server.servergroup_id,
|
||||
server.name,
|
||||
icon,
|
||||
True,
|
||||
self.node_type,
|
||||
user=user,
|
||||
connected=connected,
|
||||
server_type='pg' # Default server type
|
||||
)
|
||||
)
|
||||
node=self.blueprint.generate_browser_node(
|
||||
"%d" % server.id, server.servergroup_id,
|
||||
server.name,
|
||||
icon,
|
||||
True,
|
||||
self.node_type,
|
||||
user=user,
|
||||
connected=connected,
|
||||
server_type='pg' # Default server type
|
||||
)
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
if server:
|
||||
@@ -659,10 +661,10 @@ class ServerNode(PGChildNodeView):
|
||||
'servers/sql',
|
||||
'9.2_plus' if manager.version >= 90200 else '9.1_plus',
|
||||
'stats.sql'
|
||||
]),
|
||||
]),
|
||||
conn=conn, _=gettext
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -672,8 +674,8 @@ class ServerNode(PGChildNodeView):
|
||||
return make_json_response(
|
||||
info=gettext(
|
||||
"Server has no active connection for generating statistics."
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def dependencies(self, gid, sid):
|
||||
return make_json_response(data='')
|
||||
@@ -691,14 +693,14 @@ class ServerNode(PGChildNodeView):
|
||||
username = current_user.email.split('@')[0]
|
||||
|
||||
return make_response(
|
||||
render_template(
|
||||
"servers/servers.js",
|
||||
server_types=ServerType.types(),
|
||||
_=gettext,
|
||||
username=username,
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
render_template(
|
||||
"servers/servers.js",
|
||||
server_types=ServerType.types(),
|
||||
_=gettext,
|
||||
username=username,
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
|
||||
def connect_status(self, gid, sid):
|
||||
"""Check and return the connection status."""
|
||||
@@ -725,8 +727,8 @@ class ServerNode(PGChildNodeView):
|
||||
store the password.
|
||||
"""
|
||||
current_app.logger.info(
|
||||
'Connection Request for server#{0}'.format(sid)
|
||||
)
|
||||
'Connection Request for server#{0}'.format(sid)
|
||||
)
|
||||
|
||||
# Fetch Server Details
|
||||
server = Server.query.filter_by(id=sid).first()
|
||||
@@ -749,25 +751,25 @@ class ServerNode(PGChildNodeView):
|
||||
# Return the password template in case password is not
|
||||
# provided, or password has not been saved earlier.
|
||||
return make_json_response(
|
||||
success=0,
|
||||
status=428,
|
||||
result=render_template(
|
||||
'servers/password.html',
|
||||
server_label=server.name,
|
||||
username=server.username,
|
||||
_=gettext
|
||||
)
|
||||
)
|
||||
success=0,
|
||||
status=428,
|
||||
result=render_template(
|
||||
'servers/password.html',
|
||||
server_label=server.name,
|
||||
username=server.username,
|
||||
_=gettext
|
||||
)
|
||||
)
|
||||
else:
|
||||
password = data['password'] if 'password' in data else None
|
||||
save_password = \
|
||||
data['save_password'] if password and \
|
||||
'save_password' in data else False
|
||||
'save_password' in data else False
|
||||
|
||||
# Encrypt the password before saving with user's login password key.
|
||||
try:
|
||||
password = encrypt(password, user.password) \
|
||||
if password is not None else server.password
|
||||
if password is not None else server.password
|
||||
except Exception as e:
|
||||
current_app.logger.exception(e)
|
||||
return internal_server_error(errormsg=e.message)
|
||||
@@ -779,9 +781,9 @@ class ServerNode(PGChildNodeView):
|
||||
|
||||
try:
|
||||
status, errmsg = conn.connect(
|
||||
password=password,
|
||||
server_types=ServerType.types()
|
||||
)
|
||||
password=password,
|
||||
server_types=ServerType.types()
|
||||
)
|
||||
except Exception as e:
|
||||
current_app.logger.exception(e)
|
||||
# TODO::
|
||||
@@ -795,21 +797,21 @@ class ServerNode(PGChildNodeView):
|
||||
if not status:
|
||||
current_app.logger.error(
|
||||
"Could not connected to server(#{0}) - '{1}'.\nError: {2}".format(
|
||||
server.id, server.name, errmsg
|
||||
)
|
||||
server.id, server.name, errmsg
|
||||
)
|
||||
)
|
||||
|
||||
return make_json_response(
|
||||
success=0,
|
||||
status=401,
|
||||
result=render_template(
|
||||
'servers/password.html',
|
||||
server_label=server.name,
|
||||
username=server.username,
|
||||
errmsg=errmsg,
|
||||
_=gettext
|
||||
)
|
||||
)
|
||||
success=0,
|
||||
status=401,
|
||||
result=render_template(
|
||||
'servers/password.html',
|
||||
server_label=server.name,
|
||||
username=server.username,
|
||||
errmsg=errmsg,
|
||||
_=gettext
|
||||
)
|
||||
)
|
||||
else:
|
||||
if save_password:
|
||||
try:
|
||||
@@ -846,21 +848,21 @@ class ServerNode(PGChildNodeView):
|
||||
wal_paused = None
|
||||
|
||||
return make_json_response(
|
||||
success=1,
|
||||
info=gettext("Server connected."),
|
||||
data={
|
||||
'icon': 'icon-{0}'.format(
|
||||
manager.server_type
|
||||
),
|
||||
'connected': True,
|
||||
'type': manager.server_type,
|
||||
'version': manager.version,
|
||||
'db': manager.db,
|
||||
'user': manager.user_info,
|
||||
'in_recovery': in_recovery,
|
||||
'wal_pause': wal_paused
|
||||
}
|
||||
)
|
||||
success=1,
|
||||
info=gettext("Server connected."),
|
||||
data={
|
||||
'icon': 'icon-{0}'.format(
|
||||
manager.server_type
|
||||
),
|
||||
'connected': True,
|
||||
'type': manager.server_type,
|
||||
'version': manager.version,
|
||||
'db': manager.db,
|
||||
'user': manager.user_info,
|
||||
'in_recovery': in_recovery,
|
||||
'wal_pause': wal_paused
|
||||
}
|
||||
)
|
||||
|
||||
def disconnect(self, gid, sid):
|
||||
"""Disconnect the Server."""
|
||||
@@ -879,13 +881,13 @@ class ServerNode(PGChildNodeView):
|
||||
return unauthorized(gettext("Server could not be disconnected."))
|
||||
else:
|
||||
return make_json_response(
|
||||
success=1,
|
||||
info=gettext("Server disconnected."),
|
||||
data={
|
||||
'icon': 'icon-server-not-connected',
|
||||
'connected': False
|
||||
}
|
||||
)
|
||||
success=1,
|
||||
info=gettext("Server disconnected."),
|
||||
data={
|
||||
'icon': 'icon-server-not-connected',
|
||||
'connected': False
|
||||
}
|
||||
)
|
||||
|
||||
def reload_configuration(self, gid, sid):
|
||||
"""Reload the server configuration"""
|
||||
@@ -901,15 +903,16 @@ class ServerNode(PGChildNodeView):
|
||||
|
||||
if not status:
|
||||
return internal_server_error(
|
||||
gettext("Could not reload the server configuration.")
|
||||
)
|
||||
gettext("Could not reload the server configuration.")
|
||||
)
|
||||
else:
|
||||
return make_json_response(data={'status': True,
|
||||
'result': gettext('Server configuration reloaded.')})
|
||||
'result': gettext('Server configuration reloaded.')})
|
||||
|
||||
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': gettext(
|
||||
'Not connected to the server or the connection to the server has been closed.')})
|
||||
|
||||
def create_restore_point(self, gid, sid):
|
||||
"""
|
||||
@@ -947,7 +950,7 @@ class ServerNode(PGChildNodeView):
|
||||
'status': 1,
|
||||
'result': gettext(
|
||||
'Named restore point created: {0}'.format(
|
||||
restore_point_name))
|
||||
restore_point_name))
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
@@ -968,11 +971,11 @@ class ServerNode(PGChildNodeView):
|
||||
try:
|
||||
data = json.loads(request.form['data'])
|
||||
if data and ('password' not in data or
|
||||
data['password'] == '' or
|
||||
'newPassword' not in data or
|
||||
data['newPassword'] == '' or
|
||||
'confirmPassword' not in data or
|
||||
data['confirmPassword'] == ''):
|
||||
data['password'] == '' or
|
||||
'newPassword' not in data or
|
||||
data['newPassword'] == '' or
|
||||
'confirmPassword' not in data or
|
||||
data['confirmPassword'] == ''):
|
||||
return make_json_response(
|
||||
status=400,
|
||||
success=0,
|
||||
@@ -1019,10 +1022,10 @@ class ServerNode(PGChildNodeView):
|
||||
password = pqencryptpassword(data['newPassword'], manager.user)
|
||||
|
||||
SQL = render_template("/".join([
|
||||
'servers/sql',
|
||||
'9.2_plus' if manager.version >= 90200 else '9.1_plus',
|
||||
'change_password.sql'
|
||||
]),
|
||||
'servers/sql',
|
||||
'9.2_plus' if manager.version >= 90200 else '9.1_plus',
|
||||
'change_password.sql'
|
||||
]),
|
||||
conn=conn, _=gettext,
|
||||
user=manager.user, encrypted_password=password)
|
||||
|
||||
@@ -1042,12 +1045,12 @@ class ServerNode(PGChildNodeView):
|
||||
manager.update_session()
|
||||
|
||||
return make_json_response(
|
||||
status=200,
|
||||
success=1,
|
||||
info=gettext(
|
||||
"Password changed successfully."
|
||||
)
|
||||
status=200,
|
||||
success=1,
|
||||
info=gettext(
|
||||
"Password changed successfully."
|
||||
)
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -1128,5 +1131,4 @@ class ServerNode(PGChildNodeView):
|
||||
return self.wal_replay(sid, True)
|
||||
|
||||
|
||||
|
||||
ServerNode.register_node_view(blueprint)
|
||||
|
||||
@@ -61,17 +61,17 @@ class DatabaseModule(CollectionNodeModule):
|
||||
Returns a snippet of css to include in the page
|
||||
"""
|
||||
snippets = [
|
||||
render_template(
|
||||
"browser/css/collection.css",
|
||||
node_type=self.node_type,
|
||||
_=_
|
||||
),
|
||||
render_template(
|
||||
"databases/css/database.css",
|
||||
node_type=self.node_type,
|
||||
_=_
|
||||
)
|
||||
]
|
||||
render_template(
|
||||
"browser/css/collection.css",
|
||||
node_type=self.node_type,
|
||||
_=_
|
||||
),
|
||||
render_template(
|
||||
"databases/css/database.css",
|
||||
node_type=self.node_type,
|
||||
_=_
|
||||
)
|
||||
]
|
||||
|
||||
for submodule in self.submodules:
|
||||
snippets.extend(submodule.csssnippets)
|
||||
@@ -86,12 +86,12 @@ class DatabaseView(PGChildNodeView):
|
||||
node_type = blueprint.node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'}
|
||||
]
|
||||
ids = [
|
||||
{'type': 'int', 'id': 'did'}
|
||||
]
|
||||
{'type': 'int', 'id': 'did'}
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [
|
||||
@@ -108,7 +108,7 @@ class DatabaseView(PGChildNodeView):
|
||||
'module.js': [{}, {}, {'get': 'module_js'}],
|
||||
'connect': [{
|
||||
'get': 'connect_status', 'post': 'connect', 'delete': 'disconnect'
|
||||
}],
|
||||
}],
|
||||
'get_encodings': [{'get': 'get_encodings'}, {'get': 'get_encodings'}],
|
||||
'get_ctypes': [{'get': 'get_ctypes'}, {'get': 'get_ctypes'}],
|
||||
'vopts': [{}, {'get': 'variable_options'}]
|
||||
@@ -120,6 +120,7 @@ class DatabaseView(PGChildNodeView):
|
||||
database connection before running view, it will also attaches
|
||||
manager,conn & template_path properties to self
|
||||
"""
|
||||
|
||||
def wrap(f):
|
||||
@wraps(f)
|
||||
def wrapped(self, *args, **kwargs):
|
||||
@@ -135,7 +136,7 @@ class DatabaseView(PGChildNodeView):
|
||||
if not self.conn.connected():
|
||||
return precondition_required(
|
||||
_("Connection to the server has been lost!")
|
||||
)
|
||||
)
|
||||
|
||||
ver = self.manager.version
|
||||
# we will set template path for sql scripts
|
||||
@@ -146,7 +147,9 @@ class DatabaseView(PGChildNodeView):
|
||||
else:
|
||||
self.template_path = 'databases/sql/9.1_plus'
|
||||
return f(self, *args, **kwargs)
|
||||
|
||||
return wrapped
|
||||
|
||||
return wrap
|
||||
|
||||
@check_precondition(action="list")
|
||||
@@ -156,16 +159,16 @@ class DatabaseView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'properties.sql']),
|
||||
conn=self.conn, last_system_oid=last_system_oid
|
||||
)
|
||||
)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition(action="nodes")
|
||||
def nodes(self, gid, sid):
|
||||
@@ -176,7 +179,7 @@ class DatabaseView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'nodes.sql']),
|
||||
last_system_oid=last_system_oid
|
||||
)
|
||||
)
|
||||
status, rset = self.conn.execute_dict(SQL)
|
||||
|
||||
if not status:
|
||||
@@ -192,31 +195,31 @@ class DatabaseView(PGChildNodeView):
|
||||
canDisConn = True
|
||||
|
||||
res.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
row['did'],
|
||||
sid,
|
||||
row['name'],
|
||||
icon="icon-database-not-connected" if not connected
|
||||
else "pg-icon-database",
|
||||
connected=connected,
|
||||
tablespace=row['spcname'],
|
||||
allowConn=row['datallowconn'],
|
||||
canCreate=row['cancreate'],
|
||||
canDisconn=canDisConn
|
||||
)
|
||||
)
|
||||
self.blueprint.generate_browser_node(
|
||||
row['did'],
|
||||
sid,
|
||||
row['name'],
|
||||
icon="icon-database-not-connected" if not connected
|
||||
else "pg-icon-database",
|
||||
connected=connected,
|
||||
tablespace=row['spcname'],
|
||||
allowConn=row['datallowconn'],
|
||||
canCreate=row['cancreate'],
|
||||
canDisconn=canDisConn
|
||||
)
|
||||
)
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition(action="node")
|
||||
def node(self, gid, sid, did):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'nodes.sql']),
|
||||
did=did, conn=self.conn, last_system_oid=0
|
||||
)
|
||||
)
|
||||
status, rset = self.conn.execute_2darray(SQL)
|
||||
|
||||
if not status:
|
||||
@@ -224,34 +227,33 @@ class DatabaseView(PGChildNodeView):
|
||||
|
||||
for row in rset['rows']:
|
||||
if self.manager.db == row['name']:
|
||||
connected=True
|
||||
connected = True
|
||||
else:
|
||||
conn=self.manager.connection(row['name'])
|
||||
connected=conn.connected()
|
||||
conn = self.manager.connection(row['name'])
|
||||
connected = conn.connected()
|
||||
return make_json_response(
|
||||
data=self.blueprint.generate_browser_node(
|
||||
row['did'],
|
||||
sid,
|
||||
row['name'],
|
||||
icon="icon-database-not-connected" if not connected \
|
||||
else "pg-icon-database",
|
||||
connected=connected,
|
||||
spcname=row['spcname'],
|
||||
allowConn=row['datallowconn'],
|
||||
canCreate=row['cancreate']
|
||||
),
|
||||
status=200
|
||||
)
|
||||
data=self.blueprint.generate_browser_node(
|
||||
row['did'],
|
||||
sid,
|
||||
row['name'],
|
||||
icon="icon-database-not-connected" if not connected \
|
||||
else "pg-icon-database",
|
||||
connected=connected,
|
||||
spcname=row['spcname'],
|
||||
allowConn=row['datallowconn'],
|
||||
canCreate=row['cancreate']
|
||||
),
|
||||
status=200
|
||||
)
|
||||
|
||||
return gone(errormsg=_("Could not find the database on the server."))
|
||||
|
||||
|
||||
@check_precondition(action="properties")
|
||||
def properties(self, gid, sid, did):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'properties.sql']),
|
||||
did=did, conn=self.conn, last_system_oid=0
|
||||
)
|
||||
)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
|
||||
if not status:
|
||||
@@ -260,7 +262,7 @@ class DatabaseView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'acl.sql']),
|
||||
did=did, conn=self.conn
|
||||
)
|
||||
)
|
||||
status, dataclres = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -270,7 +272,7 @@ class DatabaseView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'defacl.sql']),
|
||||
did=did, conn=self.conn
|
||||
)
|
||||
)
|
||||
status, defaclres = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -282,7 +284,7 @@ class DatabaseView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'get_variables.sql']),
|
||||
did=did, conn=self.conn
|
||||
)
|
||||
)
|
||||
|
||||
status, res1 = self.conn.execute_dict(SQL)
|
||||
|
||||
@@ -300,9 +302,9 @@ class DatabaseView(PGChildNodeView):
|
||||
result.update(frmtd_variables)
|
||||
|
||||
return ajax_response(
|
||||
response=result,
|
||||
status=200
|
||||
)
|
||||
response=result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def formatdbacl(res, dbacl):
|
||||
@@ -317,12 +319,12 @@ class DatabaseView(PGChildNodeView):
|
||||
Override this property for your own logic.
|
||||
"""
|
||||
return make_response(
|
||||
render_template(
|
||||
"databases/js/databases.js",
|
||||
_=_
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
render_template(
|
||||
"databases/js/databases.js",
|
||||
_=_
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
|
||||
def connect(self, gid, sid, did):
|
||||
"""Connect the Database."""
|
||||
@@ -334,9 +336,9 @@ class DatabaseView(PGChildNodeView):
|
||||
if not status:
|
||||
current_app.logger.error(
|
||||
"Could not connected to database(#{0}).\nError: {1}".format(
|
||||
did, errmsg
|
||||
)
|
||||
did, errmsg
|
||||
)
|
||||
)
|
||||
|
||||
return internal_server_error(errmsg)
|
||||
else:
|
||||
@@ -344,13 +346,13 @@ class DatabaseView(PGChildNodeView):
|
||||
%s' % (did))
|
||||
|
||||
return make_json_response(
|
||||
success=1,
|
||||
info=_("Database connected."),
|
||||
data={
|
||||
'icon': 'pg-icon-database',
|
||||
'connected': True
|
||||
}
|
||||
)
|
||||
success=1,
|
||||
info=_("Database connected."),
|
||||
data={
|
||||
'icon': 'pg-icon-database',
|
||||
'connected': True
|
||||
}
|
||||
)
|
||||
|
||||
def disconnect(self, gid, sid, did):
|
||||
"""Disconnect the database."""
|
||||
@@ -365,37 +367,37 @@ class DatabaseView(PGChildNodeView):
|
||||
return unauthorized(_("Database could not be disconnected."))
|
||||
else:
|
||||
return make_json_response(
|
||||
success=1,
|
||||
info=_("Database disconnected."),
|
||||
data={
|
||||
'icon': 'icon-database-not-connected',
|
||||
'connected': False
|
||||
}
|
||||
)
|
||||
success=1,
|
||||
info=_("Database disconnected."),
|
||||
data={
|
||||
'icon': 'icon-database-not-connected',
|
||||
'connected': False
|
||||
}
|
||||
)
|
||||
|
||||
@check_precondition(action="get_encodings")
|
||||
def get_encodings(self, gid, sid, did=None):
|
||||
"""
|
||||
This function to return list of avialable encodings
|
||||
"""
|
||||
res = [{ 'label': '', 'value': '' }]
|
||||
res = [{'label': '', 'value': ''}]
|
||||
try:
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'get_encodings.sql'])
|
||||
)
|
||||
)
|
||||
status, rset = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
{ 'label': row['encoding'], 'value': row['encoding'] }
|
||||
)
|
||||
{'label': row['encoding'], 'value': row['encoding']}
|
||||
)
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -405,16 +407,16 @@ class DatabaseView(PGChildNodeView):
|
||||
"""
|
||||
This function to return list of available collation/character types
|
||||
"""
|
||||
res = [{ 'label': '', 'value': '' }]
|
||||
res = [{'label': '', 'value': ''}]
|
||||
default_list = ['C', 'POSIX']
|
||||
for val in default_list:
|
||||
res.append(
|
||||
{'label': val, 'value': val}
|
||||
)
|
||||
{'label': val, 'value': val}
|
||||
)
|
||||
try:
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'get_ctypes.sql'])
|
||||
)
|
||||
)
|
||||
status, rset = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -424,9 +426,9 @@ class DatabaseView(PGChildNodeView):
|
||||
res.append({'label': row['cname'], 'value': row['cname']})
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -454,7 +456,7 @@ class DatabaseView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'create.sql']),
|
||||
data=data, conn=self.conn
|
||||
)
|
||||
)
|
||||
status, msg = self.conn.execute_scalar(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=msg)
|
||||
@@ -466,7 +468,7 @@ class DatabaseView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'grant.sql']),
|
||||
data=data, conn=self.conn
|
||||
)
|
||||
)
|
||||
SQL = SQL.strip('\n').strip(' ')
|
||||
if SQL and SQL != "":
|
||||
status, msg = self.conn.execute_scalar(SQL)
|
||||
@@ -477,7 +479,7 @@ class DatabaseView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'properties.sql']),
|
||||
name=data['name'], conn=self.conn, last_system_oid=0
|
||||
)
|
||||
)
|
||||
SQL = SQL.strip('\n').strip(' ')
|
||||
if SQL and SQL != "":
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
@@ -497,8 +499,8 @@ class DatabaseView(PGChildNodeView):
|
||||
allowConn=True,
|
||||
canCreate=response['cancreate'],
|
||||
canDisconn=True
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return make_json_response(
|
||||
@@ -513,7 +515,7 @@ class DatabaseView(PGChildNodeView):
|
||||
|
||||
data = request.form if request.form else json.loads(
|
||||
request.data.decode()
|
||||
)
|
||||
)
|
||||
info = "nothing to update."
|
||||
|
||||
if did is not None:
|
||||
@@ -522,15 +524,15 @@ class DatabaseView(PGChildNodeView):
|
||||
render_template(
|
||||
"/".join([self.template_path, 'nodes.sql']),
|
||||
did=did, conn=self.conn, last_system_oid=0
|
||||
)
|
||||
)
|
||||
)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=rset)
|
||||
|
||||
if len(rset['rows']) == 0:
|
||||
return gone(
|
||||
_("Couldnot find the database on the server.")
|
||||
)
|
||||
)
|
||||
|
||||
data['old_name'] = (rset['rows'][0])['name']
|
||||
if 'name' not in data:
|
||||
@@ -563,7 +565,7 @@ class DatabaseView(PGChildNodeView):
|
||||
|
||||
return make_json_response(
|
||||
success=1,
|
||||
info = info,
|
||||
info=info,
|
||||
data={
|
||||
'id': did,
|
||||
'sid': sid,
|
||||
@@ -586,7 +588,7 @@ class DatabaseView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'delete.sql']),
|
||||
did=did, conn=self.conn
|
||||
)
|
||||
)
|
||||
status, res = default_conn.execute_scalar(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -605,7 +607,7 @@ class DatabaseView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'delete.sql']),
|
||||
datname=res, conn=self.conn
|
||||
)
|
||||
)
|
||||
|
||||
status, msg = default_conn.execute_scalar(SQL)
|
||||
if not status:
|
||||
@@ -642,15 +644,15 @@ class DatabaseView(PGChildNodeView):
|
||||
SQL = res.strip('\n').strip(' ')
|
||||
|
||||
return make_json_response(
|
||||
data=SQL,
|
||||
status=200
|
||||
)
|
||||
data=SQL,
|
||||
status=200
|
||||
)
|
||||
except Exception as e:
|
||||
current_app.logger.exception(e)
|
||||
return make_json_response(
|
||||
data=_("-- modified SQL"),
|
||||
status=200
|
||||
)
|
||||
data=_("-- modified SQL"),
|
||||
status=200
|
||||
)
|
||||
|
||||
def get_sql(self, gid, sid, data, did=None):
|
||||
SQL = ''
|
||||
@@ -660,15 +662,15 @@ class DatabaseView(PGChildNodeView):
|
||||
render_template(
|
||||
"/".join([self.template_path, 'nodes.sql']),
|
||||
did=did, conn=self.conn, last_system_oid=0
|
||||
)
|
||||
)
|
||||
)
|
||||
if not status:
|
||||
return False, internal_server_error(errormsg=rset)
|
||||
|
||||
if len(rset['rows']) == 0:
|
||||
return False, gone(
|
||||
_("Could not find the database on the server.")
|
||||
)
|
||||
)
|
||||
|
||||
data['old_name'] = (rset['rows'][0])['name']
|
||||
if 'name' not in data:
|
||||
@@ -689,8 +691,8 @@ class DatabaseView(PGChildNodeView):
|
||||
Generates sql for creating new database.
|
||||
"""
|
||||
required_args = [
|
||||
u'name'
|
||||
]
|
||||
u'name'
|
||||
]
|
||||
|
||||
for arg in required_args:
|
||||
if arg not in data:
|
||||
@@ -700,7 +702,7 @@ class DatabaseView(PGChildNodeView):
|
||||
try:
|
||||
acls = render_template(
|
||||
"/".join([self.template_path, 'allowed_privs.json'])
|
||||
)
|
||||
)
|
||||
acls = json.loads(acls)
|
||||
except Exception as e:
|
||||
current_app.logger.exception(e)
|
||||
@@ -711,17 +713,17 @@ class DatabaseView(PGChildNodeView):
|
||||
allowedacl = acls[aclcol]
|
||||
data[aclcol] = parse_priv_to_db(
|
||||
data[aclcol], allowedacl['acl']
|
||||
)
|
||||
)
|
||||
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'create.sql']),
|
||||
data=data, conn=self.conn
|
||||
)
|
||||
)
|
||||
SQL += "\n"
|
||||
SQL += render_template(
|
||||
"/".join([self.template_path, 'grant.sql']),
|
||||
data=data, conn=self.conn
|
||||
)
|
||||
)
|
||||
return SQL
|
||||
|
||||
def get_online_sql(self, gid, sid, data, did=None):
|
||||
@@ -733,7 +735,7 @@ class DatabaseView(PGChildNodeView):
|
||||
try:
|
||||
acls = render_template(
|
||||
"/".join([self.template_path, 'allowed_privs.json'])
|
||||
)
|
||||
)
|
||||
acls = json.loads(acls)
|
||||
except Exception as e:
|
||||
current_app.logger.exception(e)
|
||||
@@ -747,12 +749,12 @@ class DatabaseView(PGChildNodeView):
|
||||
if key in data[aclcol]:
|
||||
data[aclcol][key] = parse_priv_to_db(
|
||||
data[aclcol][key], allowedacl['acl']
|
||||
)
|
||||
)
|
||||
|
||||
return render_template(
|
||||
"/".join([self.template_path, 'alter_online.sql']),
|
||||
data=data, conn=self.conn
|
||||
)
|
||||
)
|
||||
|
||||
def get_offline_sql(self, gid, sid, data, did=None, action=None):
|
||||
"""
|
||||
@@ -763,22 +765,22 @@ class DatabaseView(PGChildNodeView):
|
||||
return render_template(
|
||||
"/".join([self.template_path, 'alter_offline.sql']),
|
||||
data=data, conn=self.conn, action=action
|
||||
)
|
||||
)
|
||||
|
||||
@check_precondition(action="variable_options")
|
||||
def variable_options(self, gid, sid):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'variables.sql'])
|
||||
)
|
||||
)
|
||||
status, rset = self.conn.execute_dict(SQL)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(errormsg=rset)
|
||||
|
||||
return make_json_response(
|
||||
data=rset['rows'],
|
||||
status=200
|
||||
)
|
||||
data=rset['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition()
|
||||
def statistics(self, gid, sid, did=None):
|
||||
@@ -794,16 +796,16 @@ class DatabaseView(PGChildNodeView):
|
||||
render_template(
|
||||
"/".join([self.template_path, 'stats.sql']),
|
||||
did=did, conn=self.conn, last_system_oid=last_system_oid
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition(action="sql")
|
||||
def sql(self, gid, sid, did):
|
||||
@@ -813,7 +815,7 @@ class DatabaseView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'properties.sql']),
|
||||
did=did, conn=self.conn, last_system_oid=0
|
||||
)
|
||||
)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -821,7 +823,7 @@ class DatabaseView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'acl.sql']),
|
||||
did=did, conn=self.conn
|
||||
)
|
||||
)
|
||||
status, dataclres = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -830,7 +832,7 @@ class DatabaseView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'defacl.sql']),
|
||||
did=did, conn=self.conn
|
||||
)
|
||||
)
|
||||
status, defaclres = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -842,7 +844,7 @@ class DatabaseView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'get_variables.sql']),
|
||||
did=did, conn=self.conn
|
||||
)
|
||||
)
|
||||
status, res1 = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res1)
|
||||
@@ -875,9 +877,9 @@ class DatabaseView(PGChildNodeView):
|
||||
"""
|
||||
dependents_result = self.get_dependents(self.conn, did)
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition()
|
||||
def dependencies(self, gid, sid, did):
|
||||
@@ -892,8 +894,9 @@ class DatabaseView(PGChildNodeView):
|
||||
"""
|
||||
dependencies_result = self.get_dependencies(self.conn, did)
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
DatabaseView.register_node_view(blueprint)
|
||||
|
||||
@@ -621,13 +621,13 @@ class CastView(PGChildNodeView):
|
||||
return internal_server_error(
|
||||
_("Could not generate reversed engineered SQL for the cast.\n\n{0}").format(
|
||||
res
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
if res is None:
|
||||
return gone(
|
||||
_("Could not generate reversed engineered SQL for the cast node.\n")
|
||||
)
|
||||
)
|
||||
|
||||
return ajax_response(response=res)
|
||||
|
||||
@@ -648,9 +648,9 @@ class CastView(PGChildNodeView):
|
||||
"""
|
||||
dependents_result = self.get_dependents(self.conn, cid)
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, cid):
|
||||
@@ -666,10 +666,9 @@ class CastView(PGChildNodeView):
|
||||
"""
|
||||
dependencies_result = self.get_dependencies(self.conn, cid)
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
CastView.register_node_view(blueprint)
|
||||
|
||||
@@ -143,13 +143,13 @@ class EventTriggerView(PGChildNodeView):
|
||||
node_type = blueprint.node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'}
|
||||
]
|
||||
ids = [
|
||||
{'type': 'int', 'id': 'etid'}
|
||||
]
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [
|
||||
@@ -172,12 +172,12 @@ class EventTriggerView(PGChildNodeView):
|
||||
Returns the javascript module for event trigger.
|
||||
"""
|
||||
return make_response(
|
||||
render_template(
|
||||
"event_triggers/js/event_trigger.js",
|
||||
_=gettext
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
render_template(
|
||||
"event_triggers/js/event_trigger.js",
|
||||
_=gettext
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
|
||||
def check_precondition(f):
|
||||
"""
|
||||
@@ -185,6 +185,7 @@ class EventTriggerView(PGChildNodeView):
|
||||
database connection before running view, it will also attaches
|
||||
manager,conn & template_path properties to self
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
# Here args[0] will hold self & kwargs will hold gid,sid,did
|
||||
@@ -196,7 +197,7 @@ class EventTriggerView(PGChildNodeView):
|
||||
if not self.conn.connected():
|
||||
return precondition_required(
|
||||
gettext(
|
||||
"Connection to the server has been lost!"
|
||||
"Connection to the server has been lost!"
|
||||
)
|
||||
)
|
||||
|
||||
@@ -205,8 +206,8 @@ class EventTriggerView(PGChildNodeView):
|
||||
self.template_path = 'event_triggers/sql/9.3_plus'
|
||||
|
||||
return f(*args, **kwargs)
|
||||
return wrap
|
||||
|
||||
return wrap
|
||||
|
||||
@check_precondition
|
||||
def list(self, gid, sid, did):
|
||||
@@ -229,9 +230,9 @@ class EventTriggerView(PGChildNodeView):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def nodes(self, gid, sid, did):
|
||||
@@ -256,17 +257,17 @@ class EventTriggerView(PGChildNodeView):
|
||||
|
||||
for row in res['rows']:
|
||||
result.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
did,
|
||||
row['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
))
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
did,
|
||||
row['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
))
|
||||
|
||||
return make_json_response(
|
||||
data=result,
|
||||
status=200
|
||||
)
|
||||
data=result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def properties(self, gid, sid, did, etid):
|
||||
@@ -297,12 +298,12 @@ class EventTriggerView(PGChildNodeView):
|
||||
sec_labels.append({
|
||||
'provider': sec.group(1),
|
||||
'securitylabel': sec.group(2)
|
||||
})
|
||||
})
|
||||
result.update({"seclabels": sec_labels})
|
||||
return ajax_response(
|
||||
response=result,
|
||||
status=200
|
||||
)
|
||||
response=result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def create(self, gid, sid, did):
|
||||
@@ -320,11 +321,11 @@ class EventTriggerView(PGChildNodeView):
|
||||
"""
|
||||
data = request.form if request.form else json.loads(request.data.decode())
|
||||
required_args = {
|
||||
'name':'Name',
|
||||
'eventowner':'Owner',
|
||||
'eventfunname':'Trigger function',
|
||||
'enabled':'Enabled status',
|
||||
'eventname':'Events'
|
||||
'name': 'Name',
|
||||
'eventowner': 'Owner',
|
||||
'eventfunname': 'Trigger function',
|
||||
'enabled': 'Enabled status',
|
||||
'eventname': 'Events'
|
||||
}
|
||||
err = []
|
||||
for arg in required_args:
|
||||
@@ -332,12 +333,12 @@ class EventTriggerView(PGChildNodeView):
|
||||
err.append(required_args.get(arg, arg))
|
||||
if err:
|
||||
return make_json_response(
|
||||
status=400,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
"Could not find the required parameter %s." % err
|
||||
)
|
||||
status=400,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
"Could not find the required parameter %s." % err
|
||||
)
|
||||
)
|
||||
try:
|
||||
sql = render_template("/".join([self.template_path, 'create.sql']), data=data, conn=self.conn)
|
||||
status, res = self.conn.execute_scalar(sql)
|
||||
@@ -395,13 +396,13 @@ class EventTriggerView(PGChildNodeView):
|
||||
status, etid = self.conn.execute_scalar(sql)
|
||||
|
||||
return jsonify(
|
||||
node=self.blueprint.generate_browser_node(
|
||||
etid,
|
||||
did,
|
||||
data['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
)
|
||||
node=self.blueprint.generate_browser_node(
|
||||
etid,
|
||||
did,
|
||||
data['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
)
|
||||
)
|
||||
else:
|
||||
return make_json_response(
|
||||
success=1,
|
||||
@@ -417,7 +418,6 @@ class EventTriggerView(PGChildNodeView):
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
|
||||
@check_precondition
|
||||
def delete(self, gid, sid, did, etid):
|
||||
"""
|
||||
@@ -464,7 +464,7 @@ class EventTriggerView(PGChildNodeView):
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
@check_precondition
|
||||
def msql(self, gid, sid, did, etid = None):
|
||||
def msql(self, gid, sid, did, etid=None):
|
||||
"""
|
||||
This function is used to return modified SQL for the selected
|
||||
event trigger node.
|
||||
@@ -489,9 +489,9 @@ class EventTriggerView(PGChildNodeView):
|
||||
sql = sql.strip('\n').strip(' ')
|
||||
|
||||
return make_json_response(
|
||||
data=sql,
|
||||
status=200
|
||||
)
|
||||
data=sql,
|
||||
status=200
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -523,11 +523,11 @@ class EventTriggerView(PGChildNodeView):
|
||||
sql = render_template("/".join([self.template_path, 'update.sql']), data=data, o_data=old_data)
|
||||
else:
|
||||
required_args = {
|
||||
'name':'Name',
|
||||
'eventowner':'Owner',
|
||||
'eventfunname':'Trigger function',
|
||||
'enabled':'Enabled status',
|
||||
'eventname':'Events'
|
||||
'name': 'Name',
|
||||
'eventowner': 'Owner',
|
||||
'eventfunname': 'Trigger function',
|
||||
'enabled': 'Enabled status',
|
||||
'eventname': 'Events'
|
||||
}
|
||||
err = []
|
||||
for arg in required_args:
|
||||
@@ -535,12 +535,12 @@ class EventTriggerView(PGChildNodeView):
|
||||
err.append(required_args.get(arg, arg))
|
||||
if err:
|
||||
return make_json_response(
|
||||
status=400,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
"Could not find the required parameter %s." % err
|
||||
)
|
||||
status=400,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
"Could not find the required parameter %s." % err
|
||||
)
|
||||
)
|
||||
sql = render_template("/".join([self.template_path, 'create.sql']), data=data)
|
||||
sql += "\n"
|
||||
sql += render_template("/".join([self.template_path, 'grant.sql']), data=data)
|
||||
@@ -581,8 +581,8 @@ class EventTriggerView(PGChildNodeView):
|
||||
sql_header = "-- Event Trigger: {0} on database {1}\n\n-- ".format(result['name'], db_name)
|
||||
|
||||
sql_header += render_template(
|
||||
"/".join([self.template_path, 'delete.sql']),
|
||||
name=result['name'], )
|
||||
"/".join([self.template_path, 'delete.sql']),
|
||||
name=result['name'], )
|
||||
sql_header += "\n"
|
||||
|
||||
sql = sql_header + sql
|
||||
@@ -592,7 +592,6 @@ class EventTriggerView(PGChildNodeView):
|
||||
except Exception as e:
|
||||
return ajax_response(response=str(e))
|
||||
|
||||
|
||||
@check_precondition
|
||||
def get_event_funcs(self, gid, sid, did, etid=None):
|
||||
"""
|
||||
@@ -608,7 +607,7 @@ class EventTriggerView(PGChildNodeView):
|
||||
Returns:
|
||||
|
||||
"""
|
||||
res = [{ 'label': '', 'value': '' }]
|
||||
res = [{'label': '', 'value': ''}]
|
||||
sql = render_template("/".join([self.template_path, 'eventfunctions.sql']))
|
||||
status, rest = self.conn.execute_2darray(sql)
|
||||
if not status:
|
||||
@@ -618,9 +617,9 @@ class EventTriggerView(PGChildNodeView):
|
||||
{'label': row['tfname'], 'value': row['tfname']}
|
||||
)
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependents(self, gid, sid, did, etid=None):
|
||||
@@ -636,9 +635,9 @@ class EventTriggerView(PGChildNodeView):
|
||||
"""
|
||||
dependents_result = self.get_dependents(self.conn, etid)
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, etid):
|
||||
@@ -654,8 +653,9 @@ class EventTriggerView(PGChildNodeView):
|
||||
"""
|
||||
dependencies_result = self.get_dependencies(self.conn, etid)
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
EventTriggerView.register_node_view(blueprint)
|
||||
|
||||
@@ -104,13 +104,13 @@ class ExtensionView(PGChildNodeView):
|
||||
node_type = blueprint.node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'}
|
||||
]
|
||||
ids = [
|
||||
{'type': 'int', 'id': 'eid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'eid'}
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [
|
||||
@@ -136,17 +136,19 @@ class ExtensionView(PGChildNodeView):
|
||||
database connection before running view, it will also attaches
|
||||
manager,conn & template_path properties to self
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
# Here args[0] will hold self & kwargs will hold gid,sid,did
|
||||
self = args[0]
|
||||
self.manager = get_driver(
|
||||
PG_DEFAULT_DRIVER
|
||||
).connection_manager(kwargs['sid'])
|
||||
PG_DEFAULT_DRIVER
|
||||
).connection_manager(kwargs['sid'])
|
||||
self.conn = self.manager.connection(did=kwargs['did'])
|
||||
self.template_path = 'extensions/sql'
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return wrap
|
||||
|
||||
@check_precondition
|
||||
@@ -160,9 +162,9 @@ class ExtensionView(PGChildNodeView):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def nodes(self, gid, sid, did):
|
||||
@@ -177,17 +179,17 @@ class ExtensionView(PGChildNodeView):
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
row['eid'],
|
||||
did,
|
||||
row['name'],
|
||||
'icon-extension'
|
||||
))
|
||||
self.blueprint.generate_browser_node(
|
||||
row['eid'],
|
||||
did,
|
||||
row['name'],
|
||||
'icon-extension'
|
||||
))
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def properties(self, gid, sid, did, eid):
|
||||
@@ -201,9 +203,9 @@ class ExtensionView(PGChildNodeView):
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
return ajax_response(
|
||||
response=res['rows'][0],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'][0],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def create(self, gid, sid, did):
|
||||
@@ -230,8 +232,8 @@ class ExtensionView(PGChildNodeView):
|
||||
render_template(
|
||||
"/".join([self.template_path, 'create.sql']),
|
||||
data=data
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -248,12 +250,12 @@ class ExtensionView(PGChildNodeView):
|
||||
|
||||
for row in rset['rows']:
|
||||
return jsonify(
|
||||
node=self.blueprint.generate_browser_node(
|
||||
node=self.blueprint.generate_browser_node(
|
||||
row['eid'],
|
||||
did,
|
||||
row['name'],
|
||||
'icon-extension'
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
@@ -310,8 +312,8 @@ class ExtensionView(PGChildNodeView):
|
||||
return internal_server_error(errormsg=name)
|
||||
# drop extension
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'delete.sql']
|
||||
), name=name, cascade=cascade)
|
||||
[self.template_path, 'delete.sql']
|
||||
), name=name, cascade=cascade)
|
||||
status, res = self.conn.execute_scalar(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -339,14 +341,14 @@ class ExtensionView(PGChildNodeView):
|
||||
if SQL and isinstance(SQL, basestring) and SQL.strip('\n') \
|
||||
and SQL.strip(' '):
|
||||
return make_json_response(
|
||||
data=SQL,
|
||||
status=200
|
||||
)
|
||||
data=SQL,
|
||||
status=200
|
||||
)
|
||||
else:
|
||||
return make_json_response(
|
||||
data=gettext('-- Modified SQL --'),
|
||||
status=200
|
||||
)
|
||||
data=gettext('-- Modified SQL --'),
|
||||
status=200
|
||||
)
|
||||
|
||||
def getSQL(self, gid, sid, data, did, eid=None):
|
||||
"""
|
||||
@@ -358,8 +360,8 @@ class ExtensionView(PGChildNodeView):
|
||||
try:
|
||||
if eid is not None:
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'properties.sql']
|
||||
), eid=eid)
|
||||
[self.template_path, 'properties.sql']
|
||||
), eid=eid)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -368,12 +370,12 @@ class ExtensionView(PGChildNodeView):
|
||||
if arg not in data:
|
||||
data[arg] = old_data[arg]
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'update.sql']
|
||||
), data=data, o_data=old_data)
|
||||
[self.template_path, 'update.sql']
|
||||
), data=data, o_data=old_data)
|
||||
else:
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'create.sql']
|
||||
), data=data)
|
||||
[self.template_path, 'create.sql']
|
||||
), data=data)
|
||||
return SQL
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -388,9 +390,9 @@ class ExtensionView(PGChildNodeView):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=rset)
|
||||
return make_json_response(
|
||||
data=rset['rows'],
|
||||
status=200
|
||||
)
|
||||
data=rset['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def schemas(self, gid, sid, did):
|
||||
@@ -402,21 +404,21 @@ class ExtensionView(PGChildNodeView):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=rset)
|
||||
return make_json_response(
|
||||
data=rset['rows'],
|
||||
status=200
|
||||
)
|
||||
data=rset['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
def module_js(self):
|
||||
"""
|
||||
This property defines whether javascript exists for this node.
|
||||
"""
|
||||
return make_response(
|
||||
render_template(
|
||||
"extensions/js/extensions.js",
|
||||
_=gettext
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
render_template(
|
||||
"extensions/js/extensions.js",
|
||||
_=gettext
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def sql(self, gid, sid, did, eid):
|
||||
@@ -424,8 +426,8 @@ class ExtensionView(PGChildNodeView):
|
||||
This function will generate sql for the sql panel
|
||||
"""
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'properties.sql']
|
||||
), eid=eid)
|
||||
[self.template_path, 'properties.sql']
|
||||
), eid=eid)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -433,8 +435,8 @@ class ExtensionView(PGChildNodeView):
|
||||
result = res['rows'][0]
|
||||
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'create.sql']
|
||||
),
|
||||
[self.template_path, 'create.sql']
|
||||
),
|
||||
data=result,
|
||||
conn=self.conn,
|
||||
display_comments=True
|
||||
@@ -458,7 +460,7 @@ class ExtensionView(PGChildNodeView):
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, eid):
|
||||
@@ -476,7 +478,8 @@ class ExtensionView(PGChildNodeView):
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
# Register and add ExtensionView as blueprint
|
||||
ExtensionView.register_node_view(blueprint)
|
||||
|
||||
@@ -83,6 +83,7 @@ class ForeignDataWrapperModule(CollectionNodeModule):
|
||||
"""
|
||||
return servers.ServerModule.NODE_TYPE
|
||||
|
||||
|
||||
blueprint = ForeignDataWrapperModule(__name__)
|
||||
|
||||
|
||||
@@ -155,13 +156,13 @@ class ForeignDataWrapperView(PGChildNodeView):
|
||||
node_type = blueprint.node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'}
|
||||
]
|
||||
ids = [
|
||||
{'type': 'int', 'id': 'fid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'fid'}
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [
|
||||
@@ -169,7 +170,7 @@ class ForeignDataWrapperView(PGChildNodeView):
|
||||
{'get': 'list', 'post': 'create'}
|
||||
],
|
||||
'delete': [{
|
||||
'delete': 'delete'
|
||||
'delete': 'delete'
|
||||
}],
|
||||
'nodes': [{'get': 'node'}, {'get': 'nodes'}],
|
||||
'children': [{'get': 'children'}],
|
||||
@@ -189,12 +190,12 @@ class ForeignDataWrapperView(PGChildNodeView):
|
||||
Override this property for your own logic.
|
||||
"""
|
||||
return make_response(
|
||||
render_template(
|
||||
"foreign_data_wrappers/js/foreign_data_wrappers.js",
|
||||
_=gettext
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
render_template(
|
||||
"foreign_data_wrappers/js/foreign_data_wrappers.js",
|
||||
_=gettext
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
|
||||
def check_precondition(f):
|
||||
"""
|
||||
@@ -202,6 +203,7 @@ class ForeignDataWrapperView(PGChildNodeView):
|
||||
database connection before running view, it will also attaches
|
||||
manager,conn & template_path properties to self
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
# Here args[0] will hold self & kwargs will hold gid,sid,did
|
||||
@@ -213,7 +215,7 @@ class ForeignDataWrapperView(PGChildNodeView):
|
||||
if not self.conn.connected():
|
||||
return precondition_required(
|
||||
gettext(
|
||||
"Connection to the server has been lost!"
|
||||
"Connection to the server has been lost!"
|
||||
)
|
||||
)
|
||||
|
||||
@@ -225,6 +227,7 @@ class ForeignDataWrapperView(PGChildNodeView):
|
||||
self.template_path = 'foreign_data_wrappers/sql/9.1_plus'
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return wrap
|
||||
|
||||
@check_precondition
|
||||
@@ -248,9 +251,9 @@ class ForeignDataWrapperView(PGChildNodeView):
|
||||
row['fdwoptions'] = self.tokenize_options(row['fdwoptions'])
|
||||
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def nodes(self, gid, sid, did):
|
||||
@@ -271,17 +274,17 @@ class ForeignDataWrapperView(PGChildNodeView):
|
||||
|
||||
for row in r_set['rows']:
|
||||
res.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
row['fdwoid'],
|
||||
did,
|
||||
row['name'],
|
||||
icon="icon-foreign_data_wrapper"
|
||||
))
|
||||
self.blueprint.generate_browser_node(
|
||||
row['fdwoid'],
|
||||
did,
|
||||
row['name'],
|
||||
icon="icon-foreign_data_wrapper"
|
||||
))
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
def tokenize_options(self, option_value):
|
||||
"""
|
||||
@@ -334,9 +337,9 @@ class ForeignDataWrapperView(PGChildNodeView):
|
||||
res['rows'][0][row['deftype']] = [privilege]
|
||||
|
||||
return ajax_response(
|
||||
response=res['rows'][0],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'][0],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def create(self, gid, sid, did):
|
||||
@@ -431,7 +434,7 @@ class ForeignDataWrapperView(PGChildNodeView):
|
||||
success=1,
|
||||
info="Foreign Data Wrapper updated",
|
||||
data={
|
||||
'id': fid,
|
||||
'id': fid,
|
||||
'did': did,
|
||||
'sid': sid,
|
||||
'gid': gid
|
||||
@@ -442,7 +445,7 @@ class ForeignDataWrapperView(PGChildNodeView):
|
||||
success=1,
|
||||
info="Nothing to update",
|
||||
data={
|
||||
'id': fid,
|
||||
'id': fid,
|
||||
'did': did,
|
||||
'sid': sid,
|
||||
'gid': gid
|
||||
@@ -516,9 +519,9 @@ class ForeignDataWrapperView(PGChildNodeView):
|
||||
|
||||
sql = self.get_sql(gid, sid, data, did, fid)
|
||||
if sql and sql.strip('\n') and sql.strip(' '):
|
||||
return make_json_response(data=sql,status=200)
|
||||
return make_json_response(data=sql, status=200)
|
||||
else:
|
||||
return make_json_response(data='-- Modified SQL --',status=200)
|
||||
return make_json_response(data='-- Modified SQL --', status=200)
|
||||
|
||||
def get_sql(self, gid, sid, data, did, fid=None):
|
||||
"""
|
||||
@@ -547,11 +550,11 @@ class ForeignDataWrapperView(PGChildNodeView):
|
||||
for key in ['fdwacl']:
|
||||
if key in data and data[key] is not None:
|
||||
if 'added' in data[key]:
|
||||
data[key]['added'] = parse_priv_to_db(data[key]['added'], ['U'])
|
||||
data[key]['added'] = parse_priv_to_db(data[key]['added'], ['U'])
|
||||
if 'changed' in data[key]:
|
||||
data[key]['changed'] = parse_priv_to_db(data[key]['changed'], ['U'])
|
||||
data[key]['changed'] = parse_priv_to_db(data[key]['changed'], ['U'])
|
||||
if 'deleted' in data[key]:
|
||||
data[key]['deleted'] = parse_priv_to_db(data[key]['deleted'], ['U'])
|
||||
data[key]['deleted'] = parse_priv_to_db(data[key]['deleted'], ['U'])
|
||||
|
||||
old_data = res['rows'][0]
|
||||
for arg in required_args:
|
||||
@@ -688,7 +691,7 @@ class ForeignDataWrapperView(PGChildNodeView):
|
||||
for row in r_set['rows']:
|
||||
res.append({'label': row['fdwvalue'], 'value': row['fdwvalue']})
|
||||
|
||||
return make_json_response( data=res, status=200)
|
||||
return make_json_response(data=res, status=200)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -715,9 +718,9 @@ class ForeignDataWrapperView(PGChildNodeView):
|
||||
res.append({'label': row['fdwhan'], 'value': row['fdwhan']})
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -736,9 +739,9 @@ class ForeignDataWrapperView(PGChildNodeView):
|
||||
"""
|
||||
dependents_result = self.get_dependents(self.conn, fid)
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, fid):
|
||||
@@ -754,8 +757,9 @@ class ForeignDataWrapperView(PGChildNodeView):
|
||||
"""
|
||||
dependencies_result = self.get_dependencies(self.conn, fid)
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
ForeignDataWrapperView.register_node_view(blueprint)
|
||||
|
||||
@@ -84,6 +84,7 @@ class ForeignServerModule(CollectionNodeModule):
|
||||
"""
|
||||
return databases.DatabaseModule.NODE_TYPE
|
||||
|
||||
|
||||
blueprint = ForeignServerModule(__name__)
|
||||
|
||||
|
||||
@@ -150,14 +151,14 @@ class ForeignServerView(PGChildNodeView):
|
||||
node_type = blueprint.node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'fid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'fid'}
|
||||
]
|
||||
ids = [
|
||||
{'type': 'int', 'id': 'fsid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'fsid'}
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [
|
||||
@@ -165,7 +166,7 @@ class ForeignServerView(PGChildNodeView):
|
||||
{'get': 'list', 'post': 'create'}
|
||||
],
|
||||
'delete': [{
|
||||
'delete': 'delete'
|
||||
'delete': 'delete'
|
||||
}],
|
||||
'nodes': [{'get': 'node'}, {'get': 'nodes'}],
|
||||
'children': [{'get': 'children'}],
|
||||
@@ -183,12 +184,12 @@ class ForeignServerView(PGChildNodeView):
|
||||
Override this property for your own logic.
|
||||
"""
|
||||
return make_response(
|
||||
render_template(
|
||||
"foreign_servers/js/foreign_servers.js",
|
||||
_=gettext
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
render_template(
|
||||
"foreign_servers/js/foreign_servers.js",
|
||||
_=gettext
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
|
||||
def check_precondition(f):
|
||||
"""
|
||||
@@ -196,6 +197,7 @@ class ForeignServerView(PGChildNodeView):
|
||||
database connection before running view, it will also attaches
|
||||
manager,conn & template_path properties to self
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
# Here args[0] will hold self & kwargs will hold gid,sid,did
|
||||
@@ -207,7 +209,7 @@ class ForeignServerView(PGChildNodeView):
|
||||
if not self.conn.connected():
|
||||
return precondition_required(
|
||||
gettext(
|
||||
"Connection to the server has been lost!"
|
||||
"Connection to the server has been lost!"
|
||||
)
|
||||
)
|
||||
|
||||
@@ -219,6 +221,7 @@ class ForeignServerView(PGChildNodeView):
|
||||
self.template_path = 'foreign_servers/sql/9.1_plus'
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return wrap
|
||||
|
||||
@check_precondition
|
||||
@@ -240,9 +243,9 @@ class ForeignServerView(PGChildNodeView):
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def nodes(self, gid, sid, did, fid):
|
||||
@@ -266,17 +269,17 @@ class ForeignServerView(PGChildNodeView):
|
||||
|
||||
for row in r_set['rows']:
|
||||
res.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
row['fsrvid'],
|
||||
fid,
|
||||
row['name'],
|
||||
icon="icon-foreign_server"
|
||||
))
|
||||
self.blueprint.generate_browser_node(
|
||||
row['fsrvid'],
|
||||
fid,
|
||||
row['name'],
|
||||
icon="icon-foreign_server"
|
||||
))
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
def tokenizeOptions(self, option_value):
|
||||
"""
|
||||
@@ -333,9 +336,9 @@ class ForeignServerView(PGChildNodeView):
|
||||
res['rows'][0][row['deftype']] = [privilege]
|
||||
|
||||
return ajax_response(
|
||||
response=res['rows'][0],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'][0],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def create(self, gid, sid, did, fid):
|
||||
@@ -437,7 +440,7 @@ class ForeignServerView(PGChildNodeView):
|
||||
success=1,
|
||||
info="Foreign server updated",
|
||||
data={
|
||||
'id': fsid,
|
||||
'id': fsid,
|
||||
'fid': fid,
|
||||
'did': did,
|
||||
'sid': sid,
|
||||
@@ -449,7 +452,7 @@ class ForeignServerView(PGChildNodeView):
|
||||
success=1,
|
||||
info="Nothing to update",
|
||||
data={
|
||||
'id': fsid,
|
||||
'id': fsid,
|
||||
'fid': fid,
|
||||
'did': did,
|
||||
'sid': sid,
|
||||
@@ -530,14 +533,14 @@ class ForeignServerView(PGChildNodeView):
|
||||
sql = self.get_sql(gid, sid, data, did, fid, fsid)
|
||||
if sql and sql.strip('\n') and sql.strip(' '):
|
||||
return make_json_response(
|
||||
data=sql,
|
||||
status=200
|
||||
)
|
||||
data=sql,
|
||||
status=200
|
||||
)
|
||||
else:
|
||||
return make_json_response(
|
||||
data='-- Modified SQL --',
|
||||
status=200
|
||||
)
|
||||
data='-- Modified SQL --',
|
||||
status=200
|
||||
)
|
||||
|
||||
def get_sql(self, gid, sid, data, did, fid, fsid=None):
|
||||
"""
|
||||
@@ -568,11 +571,11 @@ class ForeignServerView(PGChildNodeView):
|
||||
for key in ['fsrvacl']:
|
||||
if key in data and data[key] is not None:
|
||||
if 'added' in data[key]:
|
||||
data[key]['added'] = parse_priv_to_db(data[key]['added'], ['U'])
|
||||
data[key]['added'] = parse_priv_to_db(data[key]['added'], ['U'])
|
||||
if 'changed' in data[key]:
|
||||
data[key]['changed'] = parse_priv_to_db(data[key]['changed'], ['U'])
|
||||
data[key]['changed'] = parse_priv_to_db(data[key]['changed'], ['U'])
|
||||
if 'deleted' in data[key]:
|
||||
data[key]['deleted'] = parse_priv_to_db(data[key]['deleted'], ['U'])
|
||||
data[key]['deleted'] = parse_priv_to_db(data[key]['deleted'], ['U'])
|
||||
|
||||
old_data = res['rows'][0]
|
||||
for arg in required_args:
|
||||
@@ -727,12 +730,13 @@ class ForeignServerView(PGChildNodeView):
|
||||
internal_server_error(errormsg=result)
|
||||
|
||||
for row in result['rows']:
|
||||
dependents_result.append({'type': 'user_mapping', 'name': row['name'], 'field': 'normal' if (row['deptype'] == 'n') else ''})
|
||||
dependents_result.append(
|
||||
{'type': 'user_mapping', 'name': row['name'], 'field': 'normal' if (row['deptype'] == 'n') else ''})
|
||||
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, fid, fsid):
|
||||
@@ -749,8 +753,9 @@ class ForeignServerView(PGChildNodeView):
|
||||
"""
|
||||
dependencies_result = self.get_dependencies(self.conn, fsid)
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
ForeignServerView.register_node_view(blueprint)
|
||||
|
||||
@@ -97,6 +97,7 @@ class UserMappingModule(CollectionNodeModule):
|
||||
|
||||
return servers.ServerModule.NODE_TYPE
|
||||
|
||||
|
||||
blueprint = UserMappingModule(__name__)
|
||||
|
||||
|
||||
@@ -163,15 +164,15 @@ class UserMappingView(PGChildNodeView):
|
||||
node_type = blueprint.node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'fid'},
|
||||
{'type': 'int', 'id': 'fsid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'fid'},
|
||||
{'type': 'int', 'id': 'fsid'}
|
||||
]
|
||||
ids = [
|
||||
{'type': 'int', 'id': 'umid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'umid'}
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [
|
||||
@@ -179,7 +180,7 @@ class UserMappingView(PGChildNodeView):
|
||||
{'get': 'list', 'post': 'create'}
|
||||
],
|
||||
'delete': [{
|
||||
'delete': 'delete'
|
||||
'delete': 'delete'
|
||||
}],
|
||||
'nodes': [{'get': 'node'}, {'get': 'nodes'}],
|
||||
'children': [{'get': 'children'}],
|
||||
@@ -197,12 +198,12 @@ class UserMappingView(PGChildNodeView):
|
||||
Override this property for your own logic.
|
||||
"""
|
||||
return make_response(
|
||||
render_template(
|
||||
"user_mappings/js/user_mappings.js",
|
||||
_=gettext
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
render_template(
|
||||
"user_mappings/js/user_mappings.js",
|
||||
_=gettext
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
|
||||
def check_precondition(f):
|
||||
"""
|
||||
@@ -210,6 +211,7 @@ class UserMappingView(PGChildNodeView):
|
||||
database connection before running view, it will also attaches
|
||||
manager,conn & template_path properties to self
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
# Here args[0] will hold self & kwargs will hold gid,sid,did
|
||||
@@ -221,7 +223,7 @@ class UserMappingView(PGChildNodeView):
|
||||
if not self.conn.connected():
|
||||
return precondition_required(
|
||||
gettext(
|
||||
"Connection to the server has been lost!"
|
||||
"Connection to the server has been lost!"
|
||||
)
|
||||
)
|
||||
|
||||
@@ -233,6 +235,7 @@ class UserMappingView(PGChildNodeView):
|
||||
self.template_path = 'user_mappings/sql/9.1_plus'
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return wrap
|
||||
|
||||
@check_precondition
|
||||
@@ -255,9 +258,9 @@ class UserMappingView(PGChildNodeView):
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def nodes(self, gid, sid, did, fid, fsid):
|
||||
@@ -282,17 +285,17 @@ class UserMappingView(PGChildNodeView):
|
||||
|
||||
for row in r_set['rows']:
|
||||
res.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
row['um_oid'],
|
||||
fsid,
|
||||
row['name'],
|
||||
icon="icon-user_mapping"
|
||||
))
|
||||
self.blueprint.generate_browser_node(
|
||||
row['um_oid'],
|
||||
fsid,
|
||||
row['name'],
|
||||
icon="icon-user_mapping"
|
||||
))
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
def tokenizeOptions(self, option_value):
|
||||
"""
|
||||
@@ -310,7 +313,7 @@ class UserMappingView(PGChildNodeView):
|
||||
um_options = []
|
||||
for um_option in option_str:
|
||||
k, v = um_option.split('=', 1)
|
||||
um_options.append({'umoption': k,'umvalue': v})
|
||||
um_options.append({'umoption': k, 'umvalue': v})
|
||||
return um_options
|
||||
|
||||
@check_precondition
|
||||
@@ -340,9 +343,9 @@ class UserMappingView(PGChildNodeView):
|
||||
res['rows'][0]['umoptions'] = self.tokenizeOptions(res['rows'][0]['umoptions'])
|
||||
|
||||
return ajax_response(
|
||||
response=res['rows'][0],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'][0],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def create(self, gid, sid, did, fid, fsid):
|
||||
@@ -415,8 +418,8 @@ class UserMappingView(PGChildNodeView):
|
||||
fsid,
|
||||
row['name'],
|
||||
icon='icon-user_mapping'
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -447,7 +450,7 @@ class UserMappingView(PGChildNodeView):
|
||||
success=1,
|
||||
info="User Mapping updated",
|
||||
data={
|
||||
'id': umid,
|
||||
'id': umid,
|
||||
'fsid': fsid,
|
||||
'fid': fid,
|
||||
'did': did,
|
||||
@@ -460,7 +463,7 @@ class UserMappingView(PGChildNodeView):
|
||||
success=1,
|
||||
info="Nothing to update",
|
||||
data={
|
||||
'id': umid,
|
||||
'id': umid,
|
||||
'fsid': fsid,
|
||||
'fid': fid,
|
||||
'did': did,
|
||||
@@ -553,14 +556,14 @@ class UserMappingView(PGChildNodeView):
|
||||
sql = self.get_sql(gid, sid, data, did, fid, fsid, umid)
|
||||
if sql and sql.strip('\n') and sql.strip(' '):
|
||||
return make_json_response(
|
||||
data=sql,
|
||||
status=200
|
||||
)
|
||||
data=sql,
|
||||
status=200
|
||||
)
|
||||
else:
|
||||
return make_json_response(
|
||||
data='-- Modified SQL --',
|
||||
status=200
|
||||
)
|
||||
data='-- Modified SQL --',
|
||||
status=200
|
||||
)
|
||||
|
||||
def get_sql(self, gid, sid, data, did, fid, fsid, umid=None):
|
||||
"""
|
||||
@@ -728,9 +731,9 @@ class UserMappingView(PGChildNodeView):
|
||||
|
||||
dependents_result = self.get_dependents(self.conn, umid)
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, fid, fsid, umid):
|
||||
@@ -748,8 +751,9 @@ class UserMappingView(PGChildNodeView):
|
||||
"""
|
||||
dependencies_result = self.get_dependencies(self.conn, umid)
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
UserMappingView.register_node_view(blueprint)
|
||||
|
||||
@@ -94,6 +94,7 @@ class LanguageModule(CollectionNodeModule):
|
||||
"""
|
||||
return databases.DatabaseModule.NODE_TYPE
|
||||
|
||||
|
||||
blueprint = LanguageModule(__name__)
|
||||
|
||||
|
||||
@@ -154,13 +155,13 @@ class LanguageView(PGChildNodeView):
|
||||
node_type = blueprint.node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'}
|
||||
]
|
||||
ids = [
|
||||
{'type': 'int', 'id': 'lid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'lid'}
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [
|
||||
@@ -196,12 +197,12 @@ class LanguageView(PGChildNodeView):
|
||||
This property defines whether javascript exists for this node.
|
||||
"""
|
||||
return make_response(
|
||||
render_template(
|
||||
"languages/js/languages.js",
|
||||
_=gettext
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
render_template(
|
||||
"languages/js/languages.js",
|
||||
_=gettext
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
|
||||
def check_precondition(f):
|
||||
"""
|
||||
@@ -209,6 +210,7 @@ class LanguageView(PGChildNodeView):
|
||||
database connection before running the view. It also attaches
|
||||
manager, conn & template_path properties to self
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
# Here args[0] will hold self & kwargs will hold gid,sid,did
|
||||
@@ -221,7 +223,7 @@ class LanguageView(PGChildNodeView):
|
||||
if not self.conn.connected():
|
||||
return precondition_required(
|
||||
gettext(
|
||||
"Connection to the server has been lost!"
|
||||
"Connection to the server has been lost!"
|
||||
)
|
||||
)
|
||||
|
||||
@@ -233,6 +235,7 @@ class LanguageView(PGChildNodeView):
|
||||
self.template_path = 'languages/sql/9.1_plus'
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return wrap
|
||||
|
||||
@check_precondition
|
||||
@@ -251,9 +254,9 @@ class LanguageView(PGChildNodeView):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def nodes(self, gid, sid, did):
|
||||
@@ -274,17 +277,17 @@ class LanguageView(PGChildNodeView):
|
||||
|
||||
for row in result['rows']:
|
||||
res.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
did,
|
||||
row['name'],
|
||||
icon="icon-language"
|
||||
))
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
did,
|
||||
row['name'],
|
||||
icon="icon-language"
|
||||
))
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def properties(self, gid, sid, did, lid):
|
||||
@@ -323,9 +326,9 @@ class LanguageView(PGChildNodeView):
|
||||
res['rows'][0][row['deftype']] = [priv]
|
||||
|
||||
return ajax_response(
|
||||
response=res['rows'][0],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'][0],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def update(self, gid, sid, did, lid):
|
||||
@@ -393,14 +396,14 @@ class LanguageView(PGChildNodeView):
|
||||
sql = self.get_sql(data, lid)
|
||||
if sql and sql.strip('\n') and sql.strip(' '):
|
||||
return make_json_response(
|
||||
data=sql,
|
||||
status=200
|
||||
)
|
||||
data=sql,
|
||||
status=200
|
||||
)
|
||||
else:
|
||||
return make_json_response(
|
||||
data='-- Modified SQL --',
|
||||
status=200
|
||||
)
|
||||
data='-- Modified SQL --',
|
||||
status=200
|
||||
)
|
||||
|
||||
def get_sql(self, data, lid=None):
|
||||
"""
|
||||
@@ -455,9 +458,9 @@ class LanguageView(PGChildNodeView):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=result)
|
||||
return make_json_response(
|
||||
data=result['rows'],
|
||||
status=200
|
||||
)
|
||||
data=result['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def sql(self, gid, sid, did, lid):
|
||||
@@ -495,9 +498,9 @@ class LanguageView(PGChildNodeView):
|
||||
"""
|
||||
dependents_result = self.get_dependents(self.conn, lid)
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, lid):
|
||||
@@ -513,8 +516,9 @@ class LanguageView(PGChildNodeView):
|
||||
"""
|
||||
dependencies_result = self.get_dependencies(self.conn, lid)
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
LanguageView.register_node_view(blueprint)
|
||||
|
||||
@@ -120,6 +120,7 @@ def check_precondition(f):
|
||||
Assumptions:
|
||||
This function will always be used as decorator of a class method.
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
# Here args[0] will hold self & kwargs will hold gid,sid,did
|
||||
@@ -139,7 +140,7 @@ def check_precondition(f):
|
||||
self.ppas_template_path(self.manager.version)
|
||||
if self.manager.server_type == 'ppas' else
|
||||
self.pg_template_path(self.manager.version)
|
||||
)
|
||||
)
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
@@ -201,20 +202,20 @@ class SchemaView(PGChildNodeView):
|
||||
node_type = schema_blueprint.node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'}
|
||||
]
|
||||
ids = [
|
||||
{'type': 'int', 'id': 'scid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'scid'}
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [
|
||||
{'get': 'properties', 'delete': 'delete', 'put': 'update'},
|
||||
{'get': 'list', 'post': 'create'}
|
||||
],
|
||||
'children': [{ 'get': 'children'}],
|
||||
'children': [{'get': 'children'}],
|
||||
'nodes': [{'get': 'nodes'}, {'get': 'nodes'}],
|
||||
'sql': [{'get': 'sql'}],
|
||||
'msql': [{'get': 'msql'}, {'get': 'msql'}],
|
||||
@@ -237,7 +238,6 @@ class SchemaView(PGChildNodeView):
|
||||
self.template_path = None
|
||||
self.template_initial = 'schema'
|
||||
|
||||
|
||||
@staticmethod
|
||||
def ppas_template_path(ver):
|
||||
"""
|
||||
@@ -261,7 +261,7 @@ class SchemaView(PGChildNodeView):
|
||||
try:
|
||||
acls = render_template(
|
||||
"/".join([self.template_path, 'allowed_privs.json'])
|
||||
)
|
||||
)
|
||||
acls = json.loads(acls)
|
||||
except Exception as e:
|
||||
current_app.logger.exception(e)
|
||||
@@ -278,7 +278,7 @@ class SchemaView(PGChildNodeView):
|
||||
if modifier in data[aclcol]:
|
||||
data[aclcol][modifier] = parse_priv_to_db(
|
||||
data[aclcol][modifier], allowedacl['acl']
|
||||
)
|
||||
)
|
||||
else:
|
||||
data[aclcol] = parse_priv_to_db(data[aclcol], allowedacl['acl'])
|
||||
|
||||
@@ -322,7 +322,7 @@ class SchemaView(PGChildNodeView):
|
||||
seclabels.append({
|
||||
'provider': sec.group(1),
|
||||
'label': sec.group(2)
|
||||
})
|
||||
})
|
||||
|
||||
data['seclabels'] = seclabels
|
||||
|
||||
@@ -331,7 +331,7 @@ class SchemaView(PGChildNodeView):
|
||||
"/".join([self.template_path, 'sql/acl.sql']),
|
||||
_=gettext,
|
||||
scid=scid
|
||||
)
|
||||
)
|
||||
status, acl = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=acl)
|
||||
@@ -350,7 +350,7 @@ class SchemaView(PGChildNodeView):
|
||||
"/".join([self.template_path, 'sql/defacl.sql']),
|
||||
_=gettext,
|
||||
scid=scid
|
||||
)
|
||||
)
|
||||
|
||||
status, defacl = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
@@ -377,15 +377,15 @@ class SchemaView(PGChildNodeView):
|
||||
"/".join([self.template_path, 'sql/properties.sql']),
|
||||
_=gettext,
|
||||
show_sysobj=self.blueprint.show_system_objects
|
||||
)
|
||||
)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def nodes(self, gid, sid, did, scid=None):
|
||||
@@ -407,7 +407,7 @@ class SchemaView(PGChildNodeView):
|
||||
show_sysobj=self.blueprint.show_system_objects,
|
||||
_=gettext,
|
||||
scid=scid
|
||||
)
|
||||
)
|
||||
|
||||
status, rset = self.conn.execute_2darray(SQL)
|
||||
if not status:
|
||||
@@ -431,13 +431,13 @@ It may have been removed by another user.
|
||||
icon=icon,
|
||||
can_create=row['can_create'],
|
||||
has_usage=row['has_usage']
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def properties(self, gid, sid, did, scid):
|
||||
@@ -458,7 +458,7 @@ It may have been removed by another user.
|
||||
scid=scid,
|
||||
_=gettext,
|
||||
show_sysobj=self.blueprint.show_system_objects
|
||||
)
|
||||
)
|
||||
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
|
||||
@@ -476,9 +476,9 @@ It may have been removed by another user.
|
||||
copy_data = self._formatter(copy_data, scid)
|
||||
|
||||
return ajax_response(
|
||||
response=copy_data,
|
||||
status=200
|
||||
)
|
||||
response=copy_data,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def create(self, gid, sid, did):
|
||||
@@ -512,22 +512,22 @@ It may have been removed by another user.
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'sql/create.sql']),
|
||||
data=data, conn=self.conn, _=gettext
|
||||
)
|
||||
)
|
||||
status, res = self.conn.execute_scalar(SQL)
|
||||
if not status:
|
||||
return make_json_response(
|
||||
status=410,
|
||||
success=0,
|
||||
errormsg=res + '\n' +
|
||||
'Operation failed while running create statement'
|
||||
)
|
||||
'Operation failed while running create statement'
|
||||
)
|
||||
|
||||
# we need oid to to add object in tree at browser,
|
||||
# below sql will gives the same
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'sql/oid.sql']),
|
||||
schema=data['name'], _=gettext
|
||||
)
|
||||
)
|
||||
|
||||
status, scid = self.conn.execute_scalar(SQL)
|
||||
if not status:
|
||||
@@ -611,7 +611,7 @@ It may have been removed by another user.
|
||||
"/".join([self.template_path, 'sql/get_name.sql']),
|
||||
_=gettext,
|
||||
scid=scid
|
||||
)
|
||||
)
|
||||
|
||||
status, name = self.conn.execute_scalar(SQL)
|
||||
if not status:
|
||||
@@ -621,7 +621,7 @@ It may have been removed by another user.
|
||||
"/".join([self.template_path, 'sql/delete.sql']),
|
||||
_=gettext, name=name, conn=self.conn,
|
||||
cascade=True if self.cmd == 'delete' else False
|
||||
)
|
||||
)
|
||||
status, res = self.conn.execute_scalar(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -665,9 +665,9 @@ It may have been removed by another user.
|
||||
SQL = self.get_sql(gid, sid, data, scid)
|
||||
if SQL and SQL.strip('\n') and SQL.strip(' '):
|
||||
return make_json_response(
|
||||
data=SQL,
|
||||
status=200
|
||||
)
|
||||
data=SQL,
|
||||
status=200
|
||||
)
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
@@ -680,7 +680,7 @@ It may have been removed by another user.
|
||||
"/".join([self.template_path, 'sql/properties.sql']),
|
||||
_=gettext, scid=scid,
|
||||
show_sysobj=self.blueprint.show_system_objects
|
||||
)
|
||||
)
|
||||
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
@@ -699,7 +699,7 @@ It may have been removed by another user.
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'sql/update.sql']),
|
||||
_=gettext, data=data, o_data=old_data, conn=self.conn
|
||||
)
|
||||
)
|
||||
else:
|
||||
required_args = ['name']
|
||||
|
||||
@@ -713,7 +713,7 @@ It may have been removed by another user.
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'sql/create.sql']),
|
||||
data=data, conn=self.conn, _=gettext
|
||||
)
|
||||
)
|
||||
|
||||
return SQL
|
||||
|
||||
@@ -732,7 +732,7 @@ It may have been removed by another user.
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'sql/properties.sql']),
|
||||
scid=scid, _=gettext
|
||||
)
|
||||
)
|
||||
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
@@ -755,7 +755,7 @@ It may have been removed by another user.
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'sql/create.sql']),
|
||||
_=gettext, data=data, conn=self.conn
|
||||
)
|
||||
)
|
||||
|
||||
sql_header = """
|
||||
-- SCHEMA: {0}
|
||||
@@ -782,9 +782,9 @@ It may have been removed by another user.
|
||||
"""
|
||||
dependents_result = self.get_dependents(self.conn, scid)
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, scid):
|
||||
@@ -800,9 +800,9 @@ It may have been removed by another user.
|
||||
"""
|
||||
dependencies_result = self.get_dependencies(self.conn, scid)
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def children(self, **kwargs):
|
||||
@@ -811,7 +811,7 @@ It may have been removed by another user.
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'sql/is_catalog.sql']),
|
||||
scid=kwargs['scid'], _=gettext
|
||||
)
|
||||
)
|
||||
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
|
||||
@@ -882,7 +882,6 @@ class CatalogView(SchemaView):
|
||||
|
||||
self.template_initial = 'catalog'
|
||||
|
||||
|
||||
def _formatter(self, data, scid=None):
|
||||
|
||||
"""
|
||||
@@ -917,7 +916,7 @@ class CatalogView(SchemaView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'sql/properties.sql']),
|
||||
scid=scid, _=gettext
|
||||
)
|
||||
)
|
||||
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
@@ -940,7 +939,7 @@ It may have been removed by another user.
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'sql/create.sql']),
|
||||
_=gettext, data=old_data, conn=self.conn
|
||||
)
|
||||
)
|
||||
|
||||
sql_header = """
|
||||
-- CATALOG: {0}
|
||||
|
||||
@@ -79,6 +79,7 @@ class CatalogObjectModule(SchemaChildModule):
|
||||
"""
|
||||
return database.DatabaseModule.NODE_TYPE
|
||||
|
||||
|
||||
blueprint = CatalogObjectModule(__name__)
|
||||
|
||||
|
||||
@@ -111,14 +112,14 @@ class CatalogObjectView(PGChildNodeView):
|
||||
node_type = blueprint.node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'}
|
||||
]
|
||||
ids = [
|
||||
{'type': 'int', 'id': 'coid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'coid'}
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [{'get': 'properties'}, {'get': 'list'}],
|
||||
@@ -136,6 +137,7 @@ class CatalogObjectView(PGChildNodeView):
|
||||
database connection before running view, it will also attaches
|
||||
manager,conn & template_path properties to self
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
# Here args[0] will hold self & kwargs will hold gid,sid,did
|
||||
@@ -148,12 +150,12 @@ class CatalogObjectView(PGChildNodeView):
|
||||
if not self.conn.connected():
|
||||
return precondition_required(
|
||||
gettext(
|
||||
"Connection to the server has been lost!"
|
||||
"Connection to the server has been lost!"
|
||||
)
|
||||
)
|
||||
|
||||
self.template_path = 'catalog_object/sql/{0}/9.1_plus'.format(
|
||||
'ppas' if self.manager.server_type == 'ppas' else 'pg'
|
||||
'ppas' if self.manager.server_type == 'ppas' else 'pg'
|
||||
)
|
||||
|
||||
return f(*args, **kwargs)
|
||||
@@ -177,8 +179,8 @@ class CatalogObjectView(PGChildNodeView):
|
||||
"""
|
||||
|
||||
SQL = render_template("/".join([
|
||||
self.template_path, 'properties.sql'
|
||||
]), scid=scid
|
||||
self.template_path, 'properties.sql'
|
||||
]), scid=scid
|
||||
)
|
||||
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
@@ -186,9 +188,9 @@ class CatalogObjectView(PGChildNodeView):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def nodes(self, gid, sid, did, scid):
|
||||
@@ -216,17 +218,17 @@ class CatalogObjectView(PGChildNodeView):
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
scid,
|
||||
row['name'],
|
||||
icon="icon-catalog_object"
|
||||
))
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
scid,
|
||||
row['name'],
|
||||
icon="icon-catalog_object"
|
||||
))
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def properties(self, gid, sid, did, scid, coid):
|
||||
@@ -255,9 +257,9 @@ class CatalogObjectView(PGChildNodeView):
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
return ajax_response(
|
||||
response=res['rows'][0],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'][0],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependents(self, gid, sid, did, scid, coid):
|
||||
@@ -275,9 +277,9 @@ class CatalogObjectView(PGChildNodeView):
|
||||
dependents_result = self.get_dependents(self.conn, coid)
|
||||
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, scid, coid):
|
||||
@@ -295,8 +297,9 @@ class CatalogObjectView(PGChildNodeView):
|
||||
dependencies_result = self.get_dependencies(self.conn, coid)
|
||||
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
CatalogObjectView.register_node_view(blueprint)
|
||||
|
||||
@@ -91,8 +91,9 @@ class CatalogObjectColumnsModule(CollectionNodeModule):
|
||||
# node preferences
|
||||
self.browser_preference = Preferences.module('browser')
|
||||
self.pref_show_system_objects = self.browser_preference.preference(
|
||||
'show_system_objects'
|
||||
)
|
||||
'show_system_objects'
|
||||
)
|
||||
|
||||
|
||||
blueprint = CatalogObjectColumnsModule(__name__)
|
||||
|
||||
@@ -131,15 +132,15 @@ class CatalogObjectColumnsView(PGChildNodeView):
|
||||
node_type = blueprint.node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'},
|
||||
{'type': 'int', 'id': 'coid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'},
|
||||
{'type': 'int', 'id': 'coid'}
|
||||
]
|
||||
ids = [
|
||||
{'type': 'int', 'id': 'clid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'clid'}
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [{'get': 'properties'}, {'get': 'list'}],
|
||||
@@ -156,6 +157,7 @@ class CatalogObjectColumnsView(PGChildNodeView):
|
||||
database connection before running view, it will also attaches
|
||||
manager,conn & template_path properties to self
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
# Here args[0] will hold self & kwargs will hold gid,sid,did
|
||||
@@ -168,7 +170,7 @@ class CatalogObjectColumnsView(PGChildNodeView):
|
||||
if not self.conn.connected():
|
||||
return precondition_required(
|
||||
gettext(
|
||||
"Connection to the server has been lost!"
|
||||
"Connection to the server has been lost!"
|
||||
)
|
||||
)
|
||||
|
||||
@@ -201,9 +203,9 @@ class CatalogObjectColumnsView(PGChildNodeView):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def nodes(self, gid, sid, did, scid, coid):
|
||||
@@ -230,17 +232,17 @@ class CatalogObjectColumnsView(PGChildNodeView):
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
row['attnum'],
|
||||
coid,
|
||||
row['attname'],
|
||||
icon="icon-catalog_object_column"
|
||||
))
|
||||
self.blueprint.generate_browser_node(
|
||||
row['attnum'],
|
||||
coid,
|
||||
row['attname'],
|
||||
icon="icon-catalog_object_column"
|
||||
))
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def properties(self, gid, sid, did, scid, coid, clid):
|
||||
@@ -260,16 +262,16 @@ class CatalogObjectColumnsView(PGChildNodeView):
|
||||
JSON of selected column node
|
||||
"""
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
'properties.sql']),coid=coid, clid=clid)
|
||||
'properties.sql']), coid=coid, clid=clid)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
return ajax_response(
|
||||
response=res['rows'][0],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'][0],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependents(self, gid, sid, did, scid, coid, clid):
|
||||
@@ -319,9 +321,9 @@ class CatalogObjectColumnsView(PGChildNodeView):
|
||||
dependents_result.append({'type': 'sequence', 'name': ref_name, 'field': dep_type})
|
||||
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, scid, coid, clid):
|
||||
@@ -348,9 +350,9 @@ class CatalogObjectColumnsView(PGChildNodeView):
|
||||
)
|
||||
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
CatalogObjectColumnsView.register_node_view(blueprint)
|
||||
|
||||
@@ -82,6 +82,7 @@ class CollationModule(SchemaChildModule):
|
||||
def node_inode(self):
|
||||
return False
|
||||
|
||||
|
||||
blueprint = CollationModule(__name__)
|
||||
|
||||
|
||||
@@ -142,14 +143,14 @@ class CollationView(PGChildNodeView):
|
||||
node_type = blueprint.node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'}
|
||||
]
|
||||
ids = [
|
||||
{'type': 'int', 'id': 'coid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'coid'}
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [
|
||||
@@ -175,6 +176,7 @@ class CollationView(PGChildNodeView):
|
||||
database connection before running view, it will also attaches
|
||||
manager,conn & template_path properties to self
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
# Here args[0] will hold self & kwargs will hold gid,sid,did
|
||||
@@ -187,7 +189,7 @@ class CollationView(PGChildNodeView):
|
||||
if not self.conn.connected():
|
||||
return precondition_required(
|
||||
gettext(
|
||||
"Connection to the server has been lost!"
|
||||
"Connection to the server has been lost!"
|
||||
)
|
||||
)
|
||||
|
||||
@@ -197,7 +199,6 @@ class CollationView(PGChildNodeView):
|
||||
|
||||
return wrap
|
||||
|
||||
|
||||
@check_precondition
|
||||
def list(self, gid, sid, did, scid):
|
||||
"""
|
||||
@@ -220,9 +221,9 @@ class CollationView(PGChildNodeView):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def nodes(self, gid, sid, did, scid):
|
||||
@@ -249,17 +250,17 @@ class CollationView(PGChildNodeView):
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
scid,
|
||||
row['name'],
|
||||
icon="icon-collation"
|
||||
))
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
scid,
|
||||
row['name'],
|
||||
icon="icon-collation"
|
||||
))
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def properties(self, gid, sid, did, scid, coid):
|
||||
@@ -288,9 +289,9 @@ class CollationView(PGChildNodeView):
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
return ajax_response(
|
||||
response=res['rows'][0],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'][0],
|
||||
status=200
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -302,7 +303,7 @@ class CollationView(PGChildNodeView):
|
||||
as AJAX response.
|
||||
"""
|
||||
|
||||
res = [{ 'label': '', 'value': '' }]
|
||||
res = [{'label': '', 'value': ''}]
|
||||
try:
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
'get_collations.sql']))
|
||||
@@ -312,13 +313,13 @@ class CollationView(PGChildNodeView):
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
{'label': row['copy_collation'],
|
||||
'value': row['copy_collation']}
|
||||
)
|
||||
{'label': row['copy_collation'],
|
||||
'value': row['copy_collation']}
|
||||
)
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -364,7 +365,6 @@ class CollationView(PGChildNodeView):
|
||||
|
||||
return missing_definition_flag
|
||||
|
||||
|
||||
@check_precondition
|
||||
def create(self, gid, sid, did, scid):
|
||||
"""
|
||||
@@ -546,9 +546,9 @@ class CollationView(PGChildNodeView):
|
||||
SQL = self.get_sql(gid, sid, data, scid, coid)
|
||||
if SQL and SQL.strip('\n') and SQL.strip(' '):
|
||||
return make_json_response(
|
||||
data=SQL,
|
||||
status=200
|
||||
)
|
||||
data=SQL,
|
||||
status=200
|
||||
)
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
@@ -567,7 +567,7 @@ class CollationView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'update.sql']),
|
||||
data=data, o_data=old_data, conn=self.conn
|
||||
)
|
||||
)
|
||||
else:
|
||||
required_args = [
|
||||
'name'
|
||||
@@ -636,9 +636,9 @@ class CollationView(PGChildNodeView):
|
||||
)
|
||||
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, scid, coid):
|
||||
@@ -658,8 +658,9 @@ class CollationView(PGChildNodeView):
|
||||
)
|
||||
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
CollationView.register_node_view(blueprint)
|
||||
|
||||
@@ -220,8 +220,8 @@ class DomainView(PGChildNodeView, DataTypeReader):
|
||||
# Coverts string into python list as expected.
|
||||
data[key] = json.loads(req[key])
|
||||
elif key == 'typnotnull':
|
||||
data[key] = True if req[key] == 'true' or req[key] is\
|
||||
True else\
|
||||
data[key] = True if req[key] == 'true' or req[key] is \
|
||||
True else \
|
||||
(False if req[key] == 'false' or req[key] is
|
||||
False else '')
|
||||
else:
|
||||
@@ -253,6 +253,7 @@ class DomainView(PGChildNodeView, DataTypeReader):
|
||||
Checks database connection status.
|
||||
Attach connection object and template path.
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
self = args[0]
|
||||
@@ -403,7 +404,7 @@ It may have been removed by another user or moved to another schema.
|
||||
|
||||
if basetype != '' and basetype.find("(") > 0:
|
||||
substr = basetype[basetype.find("(") + 1:len(
|
||||
basetype) - 1]
|
||||
basetype) - 1]
|
||||
typlen = substr.split(",")
|
||||
if len(typlen) > 1:
|
||||
typ_len = typlen[0]
|
||||
@@ -797,9 +798,9 @@ AND relkind != 'c'))"""
|
||||
"""
|
||||
dependents_result = self.get_dependents(self.conn, doid)
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, scid, doid):
|
||||
@@ -816,8 +817,9 @@ AND relkind != 'c'))"""
|
||||
"""
|
||||
dependencies_result = self.get_dependencies(self.conn, doid)
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
DomainView.register_node_view(blueprint)
|
||||
|
||||
@@ -82,12 +82,11 @@ class DomainConstraintModule(CollectionNodeModule):
|
||||
Returns a snippet of css to include in the page
|
||||
"""
|
||||
return [
|
||||
render_template(
|
||||
"domain_constraints/css/domain_constraints.css",
|
||||
node_type=self.node_type
|
||||
)
|
||||
]
|
||||
|
||||
render_template(
|
||||
"domain_constraints/css/domain_constraints.css",
|
||||
node_type=self.node_type
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
blueprint = DomainConstraintModule(__name__)
|
||||
@@ -248,6 +247,7 @@ class DomainConstraintView(PGChildNodeView):
|
||||
Checks database connection status.
|
||||
Attach connection object and template path.
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
self = args[0]
|
||||
@@ -620,7 +620,7 @@ class DomainConstraintView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'update.sql']),
|
||||
data=data, o_data=old_data, conn=self.conn
|
||||
)
|
||||
)
|
||||
else:
|
||||
domain, schema = self._get_domain(doid)
|
||||
|
||||
@@ -665,9 +665,9 @@ class DomainConstraintView(PGChildNodeView):
|
||||
"""
|
||||
dependents_result = self.get_dependents(self.conn, coid)
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, scid, doid, coid):
|
||||
@@ -685,8 +685,9 @@ class DomainConstraintView(PGChildNodeView):
|
||||
"""
|
||||
dependencies_result = self.get_dependencies(self.conn, coid)
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
DomainConstraintView.register_node_view(blueprint)
|
||||
|
||||
@@ -202,7 +202,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
|
||||
'get_collations': [
|
||||
{'get': 'get_collations'},
|
||||
{'get': 'get_collations'}
|
||||
],
|
||||
],
|
||||
'get_types': [{'get': 'types'}, {'get': 'types'}],
|
||||
'get_foreign_servers': [{'get': 'get_foreign_servers'},
|
||||
{'get': 'get_foreign_servers'}],
|
||||
@@ -225,6 +225,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
|
||||
|
||||
Above both the arguments will not be validated in the update action.
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(self, **kwargs):
|
||||
|
||||
@@ -264,7 +265,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
|
||||
if key in list_params and req[key] != '' \
|
||||
and req[key] is not None:
|
||||
# Coverts string into python list as expected.
|
||||
data[key] = [] if\
|
||||
data[key] = [] if \
|
||||
type(req[key]) == list and len(req[key]) == 0 else \
|
||||
json.loads(req[key])
|
||||
|
||||
@@ -297,7 +298,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
|
||||
|
||||
elif key == 'typnotnull':
|
||||
data[key] = True if (req[key] == 'true' or req[key]
|
||||
is True) else False if\
|
||||
is True) else False if \
|
||||
(req[key] == 'false' or req[key]) is False else ''
|
||||
else:
|
||||
data[key] = req[key]
|
||||
@@ -328,6 +329,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
|
||||
Checks the database connection status.
|
||||
Attaches the connection object and template path to the class object.
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
self = args[0]
|
||||
@@ -621,7 +623,7 @@ AND relkind != 'c'))"""
|
||||
exc_value,
|
||||
exc_traceback,
|
||||
limit=2
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
return internal_server_error(errormsg=str(exc_value))
|
||||
@@ -700,7 +702,7 @@ AND relkind != 'c'))"""
|
||||
try:
|
||||
# Fetch Name and Schema Name to delete the foreign table.
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
'delete.sql']), scid=scid, foid=foid)
|
||||
'delete.sql']), scid=scid, foid=foid)
|
||||
status, res = self.conn.execute_2darray(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -907,7 +909,8 @@ AND relkind != 'c'))"""
|
||||
|
||||
if 'coloptions' in c and len(c['coloptions']) > 0:
|
||||
for o in c['coloptions']:
|
||||
if o['option'] in old_col_frmt_options and o['value'] != old_col_frmt_options[o['option']]:
|
||||
if o['option'] in old_col_frmt_options and o['value'] != old_col_frmt_options[
|
||||
o['option']]:
|
||||
c['coloptions_updated']['changed'].append(o)
|
||||
elif o['option'] not in old_col_frmt_options:
|
||||
c['coloptions_updated']['added'].append(o)
|
||||
@@ -917,17 +920,16 @@ AND relkind != 'c'))"""
|
||||
for o in old_col_frmt_options:
|
||||
c['coloptions_updated']['deleted'].append({'option': o})
|
||||
|
||||
|
||||
# Parse Privileges
|
||||
if 'acl' in data and 'added' in data['acl']:
|
||||
data['acl']['added'] = parse_priv_to_db(data['acl']['added'],
|
||||
["a", "r", "w", "x"])
|
||||
["a", "r", "w", "x"])
|
||||
if 'acl' in data and 'changed' in data['acl']:
|
||||
data['acl']['changed'] = parse_priv_to_db(
|
||||
data['acl']['changed'],["a", "r", "w", "x"])
|
||||
data['acl']['changed'], ["a", "r", "w", "x"])
|
||||
if 'acl' in data and 'deleted' in data['acl']:
|
||||
data['acl']['deleted'] = parse_priv_to_db(
|
||||
data['acl']['deleted'],["a", "r", "w", "x"])
|
||||
data['acl']['deleted'], ["a", "r", "w", "x"])
|
||||
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'update.sql']),
|
||||
@@ -1002,7 +1004,6 @@ AND relkind != 'c'))"""
|
||||
|
||||
return cols
|
||||
|
||||
|
||||
def _fetch_properties(self, gid, sid, did, scid, foid, inherits=False):
|
||||
"""
|
||||
Returns the Foreign Table properties which will be used in
|
||||
@@ -1167,7 +1168,6 @@ AND relkind != 'c'))"""
|
||||
|
||||
return {"ftoptions": variables_lst}
|
||||
|
||||
|
||||
@check_precondition
|
||||
def select_sql(self, gid, sid, did, scid, foid):
|
||||
"""
|
||||
|
||||
@@ -83,6 +83,7 @@ class FtsConfigurationModule(SchemaChildModule):
|
||||
"""
|
||||
return databases.DatabaseModule.NODE_TYPE
|
||||
|
||||
|
||||
blueprint = FtsConfigurationModule(__name__)
|
||||
|
||||
|
||||
@@ -190,9 +191,9 @@ class FtsConfigurationView(PGChildNodeView):
|
||||
'dependent': [{'get': 'dependents'}],
|
||||
'module.js': [{}, {}, {'get': 'module_js'}],
|
||||
'parsers': [{'get': 'parsers'},
|
||||
{'get': 'parsers'}],
|
||||
{'get': 'parsers'}],
|
||||
'copyConfig': [{'get': 'copyConfig'},
|
||||
{'get': 'copyConfig'}],
|
||||
{'get': 'copyConfig'}],
|
||||
'tokens': [{'get': 'tokens'}, {'get': 'tokens'}],
|
||||
'dictionaries': [{}, {'get': 'dictionaries'}],
|
||||
})
|
||||
@@ -255,9 +256,9 @@ class FtsConfigurationView(PGChildNodeView):
|
||||
"""
|
||||
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'properties.sql']),
|
||||
scid=scid
|
||||
)
|
||||
"/".join([self.template_path, 'properties.sql']),
|
||||
scid=scid
|
||||
)
|
||||
status, res = self.conn.execute_dict(sql)
|
||||
|
||||
if not status:
|
||||
@@ -354,10 +355,10 @@ class FtsConfigurationView(PGChildNodeView):
|
||||
"""
|
||||
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'properties.sql']),
|
||||
scid=scid,
|
||||
cfgid=cfgid
|
||||
)
|
||||
"/".join([self.template_path, 'properties.sql']),
|
||||
scid=scid,
|
||||
cfgid=cfgid
|
||||
)
|
||||
status, res = self.conn.execute_dict(sql)
|
||||
|
||||
if not status:
|
||||
@@ -371,8 +372,8 @@ class FtsConfigurationView(PGChildNodeView):
|
||||
# In edit mode fetch token/dictionary list also
|
||||
if cfgid:
|
||||
sql = render_template("/".join([self.template_path,
|
||||
'tokenDictList.sql']),
|
||||
cfgid=cfgid)
|
||||
'tokenDictList.sql']),
|
||||
cfgid=cfgid)
|
||||
|
||||
status, rset = self.conn.execute_dict(sql)
|
||||
|
||||
@@ -561,7 +562,7 @@ class FtsConfigurationView(PGChildNodeView):
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'get_name.sql']),
|
||||
cfgid=cfgid
|
||||
)
|
||||
)
|
||||
status, res = self.conn.execute_dict(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -578,7 +579,7 @@ class FtsConfigurationView(PGChildNodeView):
|
||||
name=result['name'],
|
||||
schema=result['schema'],
|
||||
cascade=cascade
|
||||
)
|
||||
)
|
||||
|
||||
status, res = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
@@ -679,7 +680,7 @@ class FtsConfigurationView(PGChildNodeView):
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'schema.sql']),
|
||||
data=old_data
|
||||
)
|
||||
)
|
||||
|
||||
status, old_schema = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
@@ -691,14 +692,14 @@ class FtsConfigurationView(PGChildNodeView):
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'update.sql']),
|
||||
data=new_data, o_data=old_data
|
||||
)
|
||||
)
|
||||
# Fetch sql query for modified data
|
||||
else:
|
||||
# Fetch schema name from schema oid
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'schema.sql']),
|
||||
data=data
|
||||
)
|
||||
)
|
||||
|
||||
status, schema = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
@@ -709,7 +710,7 @@ class FtsConfigurationView(PGChildNodeView):
|
||||
new_data['schema'] = schema
|
||||
|
||||
if 'name' in new_data and \
|
||||
'schema' in new_data:
|
||||
'schema' in new_data:
|
||||
sql = render_template("/".join([self.template_path,
|
||||
'create.sql']),
|
||||
data=new_data,
|
||||
@@ -737,7 +738,7 @@ class FtsConfigurationView(PGChildNodeView):
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'parser.sql']),
|
||||
parser=True
|
||||
)
|
||||
)
|
||||
status, rset = self.conn.execute_dict(sql)
|
||||
|
||||
if not status:
|
||||
@@ -745,7 +746,7 @@ class FtsConfigurationView(PGChildNodeView):
|
||||
|
||||
# Empty set is added before actual list as initially it will be visible
|
||||
# at parser control while creating a new FTS Configuration
|
||||
res = [{'label':'', 'value':''}]
|
||||
res = [{'label': '', 'value': ''}]
|
||||
for row in rset['rows']:
|
||||
if row['schemaoid'] > datlastsysoid:
|
||||
row['prsname'] = row['nspname'] + '.' + row['prsname']
|
||||
@@ -772,7 +773,7 @@ class FtsConfigurationView(PGChildNodeView):
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'copy_config.sql']),
|
||||
copy_config=True
|
||||
)
|
||||
)
|
||||
status, rset = self.conn.execute_dict(sql)
|
||||
|
||||
if not status:
|
||||
@@ -809,7 +810,7 @@ class FtsConfigurationView(PGChildNodeView):
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'parser.sql']),
|
||||
cfgid=cfgid
|
||||
)
|
||||
)
|
||||
status, parseroid = self.conn.execute_scalar(sql)
|
||||
|
||||
if not status:
|
||||
@@ -818,7 +819,7 @@ class FtsConfigurationView(PGChildNodeView):
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'tokens.sql']),
|
||||
parseroid=parseroid
|
||||
)
|
||||
)
|
||||
status, rset = self.conn.execute_dict(sql)
|
||||
|
||||
for row in rset['rows']:
|
||||
@@ -844,8 +845,8 @@ class FtsConfigurationView(PGChildNodeView):
|
||||
:param scid: schema id
|
||||
"""
|
||||
sql = render_template(
|
||||
"/".join([self.template_path,'dictionaries.sql'])
|
||||
)
|
||||
"/".join([self.template_path, 'dictionaries.sql'])
|
||||
)
|
||||
status, rset = self.conn.execute_dict(sql)
|
||||
|
||||
if not status:
|
||||
@@ -881,7 +882,7 @@ class FtsConfigurationView(PGChildNodeView):
|
||||
if not status:
|
||||
return internal_server_error(
|
||||
_(
|
||||
"ERROR: Couldn't generate reversed engineered query for the FTS Configuration!\n{0}"
|
||||
"ERROR: Couldn't generate reversed engineered query for the FTS Configuration!\n{0}"
|
||||
).format(
|
||||
res
|
||||
)
|
||||
|
||||
@@ -253,7 +253,6 @@ class FtsDictionaryView(PGChildNodeView):
|
||||
options.append({'option': k, 'value': v})
|
||||
return options
|
||||
|
||||
|
||||
@check_precondition
|
||||
def list(self, gid, sid, did, scid):
|
||||
"""
|
||||
@@ -348,11 +347,11 @@ class FtsDictionaryView(PGChildNodeView):
|
||||
for row in rset['rows']:
|
||||
return make_json_response(
|
||||
data=self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
did,
|
||||
row['name'],
|
||||
icon="icon-fts_dictionary"
|
||||
),
|
||||
row['oid'],
|
||||
did,
|
||||
row['name'],
|
||||
icon="icon-fts_dictionary"
|
||||
),
|
||||
status=200
|
||||
)
|
||||
|
||||
@@ -491,7 +490,7 @@ class FtsDictionaryView(PGChildNodeView):
|
||||
"/".join([self.template_path, 'properties.sql']),
|
||||
dcid=dcid,
|
||||
scid=scid
|
||||
)
|
||||
)
|
||||
|
||||
status, res = self.conn.execute_dict(sql)
|
||||
if not status:
|
||||
@@ -504,12 +503,12 @@ class FtsDictionaryView(PGChildNodeView):
|
||||
|
||||
data = res['rows'][0]
|
||||
return jsonify(
|
||||
node=self.blueprint.generate_browser_node(
|
||||
dcid,
|
||||
did,
|
||||
data['name'],
|
||||
icon="icon-fts_dictionary"
|
||||
)
|
||||
node=self.blueprint.generate_browser_node(
|
||||
dcid,
|
||||
did,
|
||||
data['name'],
|
||||
icon="icon-fts_dictionary"
|
||||
)
|
||||
)
|
||||
# In case FTS Dictionary node is not present
|
||||
else:
|
||||
@@ -555,7 +554,7 @@ class FtsDictionaryView(PGChildNodeView):
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return gone(_("""
|
||||
return gone(_("""
|
||||
Could not find the FTS Dictionary node to delete.
|
||||
"""))
|
||||
|
||||
@@ -597,7 +596,7 @@ class FtsDictionaryView(PGChildNodeView):
|
||||
:param scid: schema id
|
||||
:param dcid: FTS Dictionary id
|
||||
"""
|
||||
#data = request.args
|
||||
# data = request.args
|
||||
data = {}
|
||||
for k, v in request.args.items():
|
||||
try:
|
||||
@@ -694,8 +693,8 @@ class FtsDictionaryView(PGChildNodeView):
|
||||
new_data['schema'] = schema
|
||||
|
||||
if 'template' in new_data and \
|
||||
'name' in new_data and \
|
||||
'schema' in new_data:
|
||||
'name' in new_data and \
|
||||
'schema' in new_data:
|
||||
sql = render_template("/".join([self.template_path,
|
||||
'create.sql']),
|
||||
data=new_data,
|
||||
@@ -731,7 +730,7 @@ class FtsDictionaryView(PGChildNodeView):
|
||||
# at template control while creating a new FTS Dictionary
|
||||
res = [{'label': '', 'value': ''}]
|
||||
for row in rset['rows']:
|
||||
if row['schemaoid'] > datlastsysoid :
|
||||
if row['schemaoid'] > datlastsysoid:
|
||||
row['tmplname'] = row['nspname'] + '.' + row['tmplname']
|
||||
|
||||
res.append({'label': row['tmplname'],
|
||||
@@ -794,9 +793,9 @@ class FtsDictionaryView(PGChildNodeView):
|
||||
"""
|
||||
dependents_result = self.get_dependents(self.conn, dcid)
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, scid, dcid):
|
||||
@@ -813,8 +812,9 @@ class FtsDictionaryView(PGChildNodeView):
|
||||
"""
|
||||
dependencies_result = self.get_dependencies(self.conn, dcid)
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
FtsDictionaryView.register_node_view(blueprint)
|
||||
|
||||
@@ -238,9 +238,9 @@ class FtsParserView(PGChildNodeView):
|
||||
@check_precondition
|
||||
def list(self, gid, sid, did, scid):
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'properties.sql']),
|
||||
scid=scid
|
||||
)
|
||||
"/".join([self.template_path, 'properties.sql']),
|
||||
scid=scid
|
||||
)
|
||||
status, res = self.conn.execute_dict(sql)
|
||||
|
||||
if not status:
|
||||
@@ -255,9 +255,9 @@ class FtsParserView(PGChildNodeView):
|
||||
def nodes(self, gid, sid, did, scid):
|
||||
res = []
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'nodes.sql']),
|
||||
scid=scid
|
||||
)
|
||||
"/".join([self.template_path, 'nodes.sql']),
|
||||
scid=scid
|
||||
)
|
||||
status, rset = self.conn.execute_2darray(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=rset)
|
||||
@@ -279,9 +279,9 @@ class FtsParserView(PGChildNodeView):
|
||||
@check_precondition
|
||||
def node(self, gid, sid, did, scid, pid):
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'nodes.sql']),
|
||||
pid=pid
|
||||
)
|
||||
"/".join([self.template_path, 'nodes.sql']),
|
||||
pid=pid
|
||||
)
|
||||
status, rset = self.conn.execute_2darray(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=rset)
|
||||
@@ -294,21 +294,21 @@ class FtsParserView(PGChildNodeView):
|
||||
for row in rset['rows']:
|
||||
return make_json_response(
|
||||
data=self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
did,
|
||||
row['name'],
|
||||
icon="icon-fts_parser"
|
||||
),
|
||||
row['oid'],
|
||||
did,
|
||||
row['name'],
|
||||
icon="icon-fts_parser"
|
||||
),
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def properties(self, gid, sid, did, scid, pid):
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'properties.sql']),
|
||||
scid=scid,
|
||||
pid=pid
|
||||
)
|
||||
"/".join([self.template_path, 'properties.sql']),
|
||||
scid=scid,
|
||||
pid=pid
|
||||
)
|
||||
status, res = self.conn.execute_dict(sql)
|
||||
|
||||
if not status:
|
||||
@@ -358,10 +358,10 @@ class FtsParserView(PGChildNodeView):
|
||||
try:
|
||||
# Fetch schema name from schema oid
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'schema.sql']),
|
||||
data=data,
|
||||
conn=self.conn,
|
||||
)
|
||||
"/".join([self.template_path, 'schema.sql']),
|
||||
data=data,
|
||||
conn=self.conn,
|
||||
)
|
||||
|
||||
status, schema = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
@@ -372,10 +372,10 @@ class FtsParserView(PGChildNodeView):
|
||||
new_data = data.copy()
|
||||
new_data['schema'] = schema
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'create.sql']),
|
||||
data=new_data,
|
||||
conn=self.conn,
|
||||
)
|
||||
"/".join([self.template_path, 'create.sql']),
|
||||
data=new_data,
|
||||
conn=self.conn,
|
||||
)
|
||||
status, res = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -424,10 +424,10 @@ class FtsParserView(PGChildNodeView):
|
||||
|
||||
if pid is not None:
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'properties.sql']),
|
||||
pid=pid,
|
||||
scid=scid
|
||||
)
|
||||
"/".join([self.template_path, 'properties.sql']),
|
||||
pid=pid,
|
||||
scid=scid
|
||||
)
|
||||
|
||||
status, res = self.conn.execute_dict(sql)
|
||||
if not status:
|
||||
@@ -440,7 +440,7 @@ class FtsParserView(PGChildNodeView):
|
||||
|
||||
data = res['rows'][0]
|
||||
return jsonify(
|
||||
node=self.blueprint.generate_browser_node(
|
||||
node=self.blueprint.generate_browser_node(
|
||||
pid,
|
||||
did,
|
||||
data['name'],
|
||||
@@ -449,16 +449,16 @@ class FtsParserView(PGChildNodeView):
|
||||
)
|
||||
else:
|
||||
return make_json_response(
|
||||
success=1,
|
||||
info="Nothing to update",
|
||||
data={
|
||||
'id': pid,
|
||||
'scid': scid,
|
||||
'sid': sid,
|
||||
'gid': gid,
|
||||
'did': did
|
||||
}
|
||||
)
|
||||
success=1,
|
||||
info="Nothing to update",
|
||||
data={
|
||||
'id': pid,
|
||||
'scid': scid,
|
||||
'sid': sid,
|
||||
'gid': gid,
|
||||
'did': did
|
||||
}
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def delete(self, gid, sid, did, scid, pid):
|
||||
@@ -480,9 +480,9 @@ class FtsParserView(PGChildNodeView):
|
||||
try:
|
||||
# Get name for Parser from pid
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'delete.sql']),
|
||||
pid=pid
|
||||
)
|
||||
"/".join([self.template_path, 'delete.sql']),
|
||||
pid=pid
|
||||
)
|
||||
status, res = self.conn.execute_dict(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -493,11 +493,11 @@ class FtsParserView(PGChildNodeView):
|
||||
# Drop fts Parser
|
||||
result = res['rows'][0]
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'delete.sql']),
|
||||
name=result['name'],
|
||||
schema=result['schema'],
|
||||
cascade=cascade
|
||||
)
|
||||
"/".join([self.template_path, 'delete.sql']),
|
||||
name=result['name'],
|
||||
schema=result['schema'],
|
||||
cascade=cascade
|
||||
)
|
||||
|
||||
status, res = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
@@ -558,10 +558,10 @@ class FtsParserView(PGChildNodeView):
|
||||
# Fetch sql for update
|
||||
if pid is not None:
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'properties.sql']),
|
||||
pid=pid,
|
||||
scid=scid
|
||||
)
|
||||
"/".join([self.template_path, 'properties.sql']),
|
||||
pid=pid,
|
||||
scid=scid
|
||||
)
|
||||
|
||||
status, res = self.conn.execute_dict(sql)
|
||||
if not status:
|
||||
@@ -589,9 +589,9 @@ class FtsParserView(PGChildNodeView):
|
||||
|
||||
# Fetch old schema name using old schema oid
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'schema.sql']),
|
||||
data=old_data
|
||||
)
|
||||
"/".join([self.template_path, 'schema.sql']),
|
||||
data=old_data
|
||||
)
|
||||
|
||||
status, old_schema = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
@@ -601,17 +601,17 @@ class FtsParserView(PGChildNodeView):
|
||||
old_data['schema'] = old_schema
|
||||
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'update.sql']),
|
||||
data=new_data,
|
||||
o_data=old_data
|
||||
)
|
||||
"/".join([self.template_path, 'update.sql']),
|
||||
data=new_data,
|
||||
o_data=old_data
|
||||
)
|
||||
# Fetch sql query for modified data
|
||||
else:
|
||||
# Fetch schema name from schema oid
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'schema.sql']),
|
||||
data=data
|
||||
)
|
||||
"/".join([self.template_path, 'schema.sql']),
|
||||
data=data
|
||||
)
|
||||
|
||||
status, schema = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
@@ -622,16 +622,16 @@ class FtsParserView(PGChildNodeView):
|
||||
new_data['schema'] = schema
|
||||
|
||||
if 'prsstart' in new_data and \
|
||||
'prstoken' in new_data and \
|
||||
'prsend' in new_data and \
|
||||
'prslextype' in new_data and \
|
||||
'name' in new_data and \
|
||||
'schema' in new_data:
|
||||
'prstoken' in new_data and \
|
||||
'prsend' in new_data and \
|
||||
'prslextype' in new_data and \
|
||||
'name' in new_data and \
|
||||
'schema' in new_data:
|
||||
sql = render_template(
|
||||
"/".join([self.template_path,'create.sql']),
|
||||
data=new_data,
|
||||
conn=self.conn
|
||||
)
|
||||
"/".join([self.template_path, 'create.sql']),
|
||||
data=new_data,
|
||||
conn=self.conn
|
||||
)
|
||||
else:
|
||||
sql = "-- incomplete definition"
|
||||
return str(sql.strip('\n'))
|
||||
@@ -828,9 +828,9 @@ class FtsParserView(PGChildNodeView):
|
||||
"""
|
||||
dependents_result = self.get_dependents(self.conn, pid)
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, scid, pid):
|
||||
@@ -847,8 +847,9 @@ class FtsParserView(PGChildNodeView):
|
||||
"""
|
||||
dependencies_result = self.get_dependencies(self.conn, pid)
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
FtsParserView.register_node_view(blueprint)
|
||||
|
||||
@@ -279,11 +279,11 @@ class FtsTemplateView(PGChildNodeView):
|
||||
for row in rset['rows']:
|
||||
return make_json_response(
|
||||
data=self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
did,
|
||||
row['name'],
|
||||
icon="icon-fts_template"
|
||||
),
|
||||
row['oid'],
|
||||
did,
|
||||
row['name'],
|
||||
icon="icon-fts_template"
|
||||
),
|
||||
status=200
|
||||
)
|
||||
|
||||
@@ -695,9 +695,9 @@ class FtsTemplateView(PGChildNodeView):
|
||||
"""
|
||||
dependents_result = self.get_dependents(self.conn, tid)
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, scid, tid):
|
||||
@@ -714,8 +714,9 @@ class FtsTemplateView(PGChildNodeView):
|
||||
"""
|
||||
dependencies_result = self.get_dependencies(self.conn, tid)
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
FtsTemplateView.register_node_view(blueprint)
|
||||
|
||||
@@ -113,6 +113,7 @@ class FunctionModule(SchemaChildModule):
|
||||
|
||||
return snippets
|
||||
|
||||
|
||||
blueprint = FunctionModule(__name__)
|
||||
|
||||
|
||||
@@ -258,7 +259,7 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
||||
if 'fnid' not in kwargs:
|
||||
|
||||
for arg in self.required_args:
|
||||
if (arg not in req or req[arg] == '') or\
|
||||
if (arg not in req or req[arg] == '') or \
|
||||
(arg == 'probin' and req['lanname'] == 'c'
|
||||
and (arg not in req or req[arg] == '')):
|
||||
return make_json_response(
|
||||
@@ -281,12 +282,12 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
||||
# Coverts string into python list as expected.
|
||||
data[key] = json.loads(req[key])
|
||||
elif (
|
||||
key == 'proretset' or key == 'proisstrict' or
|
||||
key == 'prosecdef' or key == 'proiswindow' or
|
||||
key == 'proleakproof'
|
||||
key == 'proretset' or key == 'proisstrict' or
|
||||
key == 'prosecdef' or key == 'proiswindow' or
|
||||
key == 'proleakproof'
|
||||
):
|
||||
data[key] = True if (
|
||||
req[key] == 'true' or req[key] is True)\
|
||||
req[key] == 'true' or req[key] is True) \
|
||||
else False if (req[key] == 'false' or
|
||||
req[key] is False) else ''
|
||||
else:
|
||||
@@ -353,7 +354,7 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
||||
'9.5_plus' if ver >= 90500 else
|
||||
'9.2_plus' if ver >= 90200 else
|
||||
'9.1_plus'
|
||||
])
|
||||
])
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
@@ -458,7 +459,7 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
||||
proargnames: Argument Name
|
||||
proargdefaultvals: Default Value of the Argument
|
||||
"""
|
||||
proargtypes = [ptype for ptype in data['proargtypenames'].split(",")]\
|
||||
proargtypes = [ptype for ptype in data['proargtypenames'].split(",")] \
|
||||
if data['proargtypenames'] else []
|
||||
proargmodes = data['proargmodes'] if data['proargmodes'] else []
|
||||
proargnames = data['proargnames'] if data['proargnames'] else []
|
||||
@@ -544,7 +545,7 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
||||
proargnames[i] if len(proargnames) > i else '',
|
||||
proargdefaultvals[i] if len(proargdefaultvals) > i else ''
|
||||
)
|
||||
for i in range(len(proargtypes))]
|
||||
for i in range(len(proargtypes))]
|
||||
|
||||
proargs = {"proargs": ", ".join(proargs)}
|
||||
|
||||
@@ -676,7 +677,7 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
||||
exc_value,
|
||||
exc_traceback,
|
||||
limit=2
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
return internal_server_error(errormsg=str(exc_value))
|
||||
@@ -699,7 +700,7 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
||||
"""
|
||||
SQL = render_template(
|
||||
"/".join([self.sql_template_path, 'variables.sql'])
|
||||
)
|
||||
)
|
||||
status, rset = self.conn.execute_dict(SQL)
|
||||
|
||||
if not status:
|
||||
@@ -782,7 +783,7 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
||||
try:
|
||||
# Fetch Name and Schema Name to delete the Function.
|
||||
SQL = render_template("/".join([self.sql_template_path,
|
||||
'delete.sql']), scid=scid, fnid=fnid)
|
||||
'delete.sql']), scid=scid, fnid=fnid)
|
||||
status, res = self.conn.execute_2darray(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -904,7 +905,7 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
||||
object_type = 'function'
|
||||
# Fetch the function definition.
|
||||
SQL = render_template("/".join([self.sql_template_path,
|
||||
'get_definition.sql']), fnid=fnid, scid=scid)
|
||||
'get_definition.sql']), fnid=fnid, scid=scid)
|
||||
status, res = self.conn.execute_2darray(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -969,7 +970,7 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
||||
# Get Schema Name from its OID.
|
||||
if 'pronamespace' in data:
|
||||
data['pronamespace'] = self._get_schema(data[
|
||||
'pronamespace'])
|
||||
'pronamespace'])
|
||||
if 'provolatile' in data:
|
||||
data['provolatile'] = vol_dict[data['provolatile']]
|
||||
|
||||
@@ -981,7 +982,7 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
||||
|
||||
# Get Schema Name
|
||||
old_data['pronamespace'] = self._get_schema(old_data[
|
||||
'pronamespace'])
|
||||
'pronamespace'])
|
||||
|
||||
if 'provolatile' in old_data:
|
||||
old_data['provolatile'] = vol_dict[old_data['provolatile']]
|
||||
@@ -1085,11 +1086,11 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
||||
if 'arguments' in data:
|
||||
for a in data['arguments']:
|
||||
if (('argmode' in a and a['argmode'] != 'OUT' and
|
||||
a['argmode'] is not None
|
||||
a['argmode'] is not None
|
||||
) or 'argnode' not in a):
|
||||
if 'argmode' in a:
|
||||
args += a['argmode'] + " "
|
||||
if 'argname' in a and a['argname'] != ''\
|
||||
if 'argname' in a and a['argname'] != '' \
|
||||
and a['argname'] is not None:
|
||||
args += self.qtIdent(
|
||||
self.conn, a['argname']) + " "
|
||||
@@ -1177,7 +1178,7 @@ It may have been removed by another user or moved to another schema.
|
||||
scid: Schema Id
|
||||
"""
|
||||
SQL = render_template("/".join([self.sql_template_path,
|
||||
'get_schema.sql']), scid=scid)
|
||||
'get_schema.sql']), scid=scid)
|
||||
|
||||
status, schema_name = self.conn.execute_scalar(SQL)
|
||||
|
||||
@@ -1238,7 +1239,7 @@ It may have been removed by another user or moved to another schema.
|
||||
"""
|
||||
# Fetch the function definition.
|
||||
SQL = render_template("/".join([self.sql_template_path,
|
||||
'get_definition.sql']), fnid=fnid, scid=scid)
|
||||
'get_definition.sql']), fnid=fnid, scid=scid)
|
||||
status, res = self.conn.execute_2darray(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -1334,16 +1335,16 @@ It may have been removed by another user or moved to another schema.
|
||||
"/".join([self.sql_template_path, sql]),
|
||||
conn=self.conn, fnid=fnid,
|
||||
scid=scid, schema_name=schema_name
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
FunctionView.register_node_view(blueprint)
|
||||
@@ -1416,7 +1417,6 @@ procedure_blueprint = ProcedureModule(__name__)
|
||||
|
||||
|
||||
class ProcedureView(FunctionView):
|
||||
|
||||
node_type = procedure_blueprint.node_type
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
@@ -1457,6 +1457,7 @@ class ProcedureView(FunctionView):
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
|
||||
|
||||
ProcedureView.register_node_view(procedure_blueprint)
|
||||
|
||||
|
||||
@@ -1526,7 +1527,6 @@ trigger_function_blueprint = TriggerFunctionModule(__name__)
|
||||
|
||||
|
||||
class TriggerFunctionView(FunctionView):
|
||||
|
||||
node_type = trigger_function_blueprint.node_type
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
@@ -1567,4 +1567,5 @@ class TriggerFunctionView(FunctionView):
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
|
||||
|
||||
TriggerFunctionView.register_node_view(trigger_function_blueprint)
|
||||
|
||||
@@ -82,6 +82,7 @@ class SequenceModule(SchemaChildModule):
|
||||
"""
|
||||
return False
|
||||
|
||||
|
||||
blueprint = SequenceModule(__name__)
|
||||
|
||||
|
||||
@@ -89,14 +90,14 @@ class SequenceView(PGChildNodeView):
|
||||
node_type = blueprint.node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'}
|
||||
]
|
||||
ids = [
|
||||
{'type': 'int', 'id': 'seid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'seid'}
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [
|
||||
@@ -119,12 +120,12 @@ class SequenceView(PGChildNodeView):
|
||||
This property defines whether javascript exists for this node.
|
||||
"""
|
||||
return make_response(
|
||||
render_template(
|
||||
"sequence/js/sequence.js",
|
||||
_=_
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
render_template(
|
||||
"sequence/js/sequence.js",
|
||||
_=_
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
|
||||
def check_precondition(action=None):
|
||||
"""
|
||||
@@ -132,6 +133,7 @@ class SequenceView(PGChildNodeView):
|
||||
database connection before running view, it will also attaches
|
||||
manager,conn & template_path properties to self
|
||||
"""
|
||||
|
||||
def wrap(f):
|
||||
@wraps(f)
|
||||
def wrapped(self, *args, **kwargs):
|
||||
@@ -147,14 +149,16 @@ class SequenceView(PGChildNodeView):
|
||||
if not self.conn.connected():
|
||||
return precondition_required(
|
||||
_(
|
||||
"Connection to the server has been lost!"
|
||||
"Connection to the server has been lost!"
|
||||
)
|
||||
)
|
||||
|
||||
self.template_path = 'sequence/sql/9.1_plus'
|
||||
self.acl = ['r', 'w', 'U']
|
||||
return f(self, *args, **kwargs)
|
||||
|
||||
return wrapped
|
||||
|
||||
return wrap
|
||||
|
||||
@check_precondition(action='list')
|
||||
@@ -177,9 +181,9 @@ class SequenceView(PGChildNodeView):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition(action='nodes')
|
||||
def nodes(self, gid, sid, did, scid):
|
||||
@@ -204,17 +208,17 @@ class SequenceView(PGChildNodeView):
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
sid,
|
||||
row['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
))
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
sid,
|
||||
row['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
))
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition(action='properties')
|
||||
def properties(self, gid, sid, did, scid, seid):
|
||||
@@ -244,7 +248,7 @@ class SequenceView(PGChildNodeView):
|
||||
sec_lbls.append({
|
||||
'provider': sec.group(1),
|
||||
'label': sec.group(2)
|
||||
})
|
||||
})
|
||||
res['securities'] = sec_lbls
|
||||
|
||||
for row in res['rows']:
|
||||
@@ -273,9 +277,9 @@ class SequenceView(PGChildNodeView):
|
||||
res['rows'][0][row['deftype']] = [priv]
|
||||
|
||||
return ajax_response(
|
||||
response=res['rows'][0],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'][0],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition(action="create")
|
||||
def create(self, gid, sid, did, scid):
|
||||
@@ -340,8 +344,8 @@ class SequenceView(PGChildNodeView):
|
||||
scid,
|
||||
data['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return make_json_response(
|
||||
@@ -488,14 +492,14 @@ class SequenceView(PGChildNodeView):
|
||||
SQL = self.getSQL(gid, sid, did, data, scid, seid)
|
||||
SQL = SQL.strip('\n').strip(' ')
|
||||
return make_json_response(
|
||||
data=SQL,
|
||||
status=200
|
||||
)
|
||||
data=SQL,
|
||||
status=200
|
||||
)
|
||||
except Exception as e:
|
||||
return make_json_response(
|
||||
data="-- modified SQL",
|
||||
status=200
|
||||
)
|
||||
data="-- modified SQL",
|
||||
status=200
|
||||
)
|
||||
|
||||
def getSQL(self, gid, sid, did, data, scid, seid=None):
|
||||
"""
|
||||
@@ -526,11 +530,11 @@ class SequenceView(PGChildNodeView):
|
||||
for key in ['relacl']:
|
||||
if key in data and data[key] is not None:
|
||||
if 'added' in data[key]:
|
||||
data[key]['added'] = parse_priv_to_db(data[key]['added'], self.acl)
|
||||
data[key]['added'] = parse_priv_to_db(data[key]['added'], self.acl)
|
||||
if 'changed' in data[key]:
|
||||
data[key]['changed'] = parse_priv_to_db(data[key]['changed'], self.acl)
|
||||
data[key]['changed'] = parse_priv_to_db(data[key]['changed'], self.acl)
|
||||
if 'deleted' in data[key]:
|
||||
data[key]['deleted'] = parse_priv_to_db(data[key]['deleted'], self.acl)
|
||||
data[key]['deleted'] = parse_priv_to_db(data[key]['deleted'], self.acl)
|
||||
|
||||
# If name is not present with in update data then copy it
|
||||
# from old data
|
||||
@@ -637,9 +641,9 @@ class SequenceView(PGChildNodeView):
|
||||
"""
|
||||
dependents_result = self.get_dependents(self.conn, seid)
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition(action="dependencies")
|
||||
def dependencies(self, gid, sid, did, scid, seid):
|
||||
@@ -686,9 +690,9 @@ class SequenceView(PGChildNodeView):
|
||||
'field': dep_type})
|
||||
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition(action="stats")
|
||||
def statistics(self, gid, sid, did, scid, seid=None):
|
||||
@@ -724,15 +728,16 @@ class SequenceView(PGChildNodeView):
|
||||
"/".join([self.template_path, sql]),
|
||||
conn=self.conn, seid=seid,
|
||||
schema_name=schema_name
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
SequenceView.register_node_view(blueprint)
|
||||
|
||||
@@ -216,14 +216,14 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
node_type = blueprint.node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'}
|
||||
]
|
||||
ids = [
|
||||
{'type': 'int', 'id': 'tid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'tid'}
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [
|
||||
@@ -266,6 +266,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
database connection before running view, it will also attaches
|
||||
manager,conn & template_path properties to self
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
# Here args[0] will hold self & kwargs will hold gid,sid,did
|
||||
@@ -281,7 +282,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
if not self.conn.connected():
|
||||
return precondition_required(
|
||||
gettext(
|
||||
"Connection to the server has been lost!"
|
||||
"Connection to the server has been lost!"
|
||||
)
|
||||
)
|
||||
|
||||
@@ -353,9 +354,9 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def nodes(self, gid, sid, did, scid):
|
||||
@@ -381,19 +382,19 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
scid,
|
||||
row['name'],
|
||||
icon="icon-table",
|
||||
tigger_count=row['triggercount'],
|
||||
has_enable_triggers=row['has_enable_triggers']
|
||||
))
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
scid,
|
||||
row['name'],
|
||||
icon="icon-table",
|
||||
tigger_count=row['triggercount'],
|
||||
has_enable_triggers=row['has_enable_triggers']
|
||||
))
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def get_all_tables(self, gid, sid, did, scid, tid=None):
|
||||
@@ -440,7 +441,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def get_toast_table_vacuum(self, gid, sid, did, scid=None, tid=None):
|
||||
@@ -456,7 +457,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def get_access_methods(self, gid, sid, did, scid, tid=None):
|
||||
@@ -488,9 +489,9 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
{'label': row['amname'], 'value': row['amname']}
|
||||
)
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def get_oper_class(self, gid, sid, did, scid, tid=None):
|
||||
@@ -525,7 +526,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
return make_json_response(
|
||||
data=result,
|
||||
status=200
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
@@ -563,7 +564,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
return make_json_response(
|
||||
data=result,
|
||||
status=200
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
@@ -598,7 +599,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
column['seclabels'] = seclabels
|
||||
|
||||
if 'attnum' in column and column['attnum'] is not None and \
|
||||
column['attnum'] > 0:
|
||||
column['attnum'] > 0:
|
||||
# We need to parse & convert ACL coming from database to json format
|
||||
SQL = render_template("/".join([self.column_template_path, 'acl.sql']),
|
||||
tid=tid, clid=column['attnum'])
|
||||
@@ -737,7 +738,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
|
||||
columns = []
|
||||
for r in res['rows']:
|
||||
columns.append({"column": r['column'].strip('"')})
|
||||
columns.append({"column": r['column'].strip('"')})
|
||||
|
||||
result['columns'] = columns
|
||||
|
||||
@@ -761,7 +762,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
# We will fetch all the index constraints for the table
|
||||
sql = render_template("/".join([self.foreign_key_template_path,
|
||||
'properties.sql']),
|
||||
tid=tid)
|
||||
tid=tid)
|
||||
|
||||
status, result = self.conn.execute_dict(sql)
|
||||
|
||||
@@ -771,10 +772,10 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
for fk in result['rows']:
|
||||
|
||||
sql = render_template("/".join([self.foreign_key_template_path,
|
||||
'get_constraint_cols.sql']),
|
||||
tid=tid,
|
||||
keys=zip(fk['confkey'], fk['conkey']),
|
||||
confrelid=fk['confrelid'])
|
||||
'get_constraint_cols.sql']),
|
||||
tid=tid,
|
||||
keys=zip(fk['confkey'], fk['conkey']),
|
||||
confrelid=fk['confrelid'])
|
||||
|
||||
status, res = self.conn.execute_dict(sql)
|
||||
|
||||
@@ -1039,7 +1040,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
|
||||
# Filter inherited columns from all columns
|
||||
if 'columns' in data and len(data['columns']) > 0 \
|
||||
and len(all_columns) > 0:
|
||||
and len(all_columns) > 0:
|
||||
columns = []
|
||||
for row in data['columns']:
|
||||
for i, col in enumerate(all_columns):
|
||||
@@ -1102,10 +1103,10 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
|
||||
if data['toast_table_vacuum_settings_str'] is not None:
|
||||
data['vacuum_settings_str'] += '\n' + '\n'.join(
|
||||
['toast_' + setting for setting in data[
|
||||
'toast_table_vacuum_settings_str'
|
||||
].split(',')]
|
||||
)
|
||||
['toast_' + setting for setting in data[
|
||||
'toast_table_vacuum_settings_str'
|
||||
].split(',')]
|
||||
)
|
||||
data['vacuum_settings_str'] = data[
|
||||
'vacuum_settings_str'
|
||||
].replace("=", " = ")
|
||||
@@ -1113,9 +1114,9 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
data = self._formatter(scid, tid, data)
|
||||
|
||||
return ajax_response(
|
||||
response=data,
|
||||
status=200
|
||||
)
|
||||
response=data,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def types(self, gid, sid, did, scid, tid=None, clid=None):
|
||||
@@ -1199,14 +1200,14 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
return internal_server_error(errormsg=res)
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
{'label': row['typname'], 'value': row['typname'],
|
||||
'tid': row['oid']
|
||||
}
|
||||
)
|
||||
{'label': row['typname'], 'value': row['typname'],
|
||||
'tid': row['oid']
|
||||
}
|
||||
)
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -1228,14 +1229,14 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
return internal_server_error(errormsg=res)
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
{'label': row['inherits'], 'value': row['inherits'],
|
||||
'tid': row['oid']
|
||||
}
|
||||
)
|
||||
{'label': row['inherits'], 'value': row['inherits'],
|
||||
'tid': row['oid']
|
||||
}
|
||||
)
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -1256,12 +1257,12 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
return internal_server_error(errormsg=res)
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
{'label': row['like_relation'], 'value': row['like_relation']}
|
||||
)
|
||||
{'label': row['like_relation'], 'value': row['like_relation']}
|
||||
)
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -1707,8 +1708,8 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
# Sql for drop
|
||||
sql.append(
|
||||
render_template("/".join(
|
||||
[self.index_constraint_template_path,
|
||||
'delete.sql']),
|
||||
[self.index_constraint_template_path,
|
||||
'delete.sql']),
|
||||
data=c, conn=self.conn).strip('\n')
|
||||
)
|
||||
|
||||
@@ -1747,7 +1748,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
data=c, conn=self.conn,
|
||||
constraint_name='PRIMARY KEY'
|
||||
if ctype == 'p' else 'UNIQUE'
|
||||
).strip('\n')
|
||||
).strip('\n')
|
||||
)
|
||||
else:
|
||||
sql.append(
|
||||
@@ -1784,8 +1785,8 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
# Sql for drop
|
||||
sql.append(
|
||||
render_template("/".join(
|
||||
[self.foreign_key_template_path,
|
||||
'delete.sql']),
|
||||
[self.foreign_key_template_path,
|
||||
'delete.sql']),
|
||||
data=c, conn=self.conn).strip('\n')
|
||||
)
|
||||
|
||||
@@ -1824,13 +1825,13 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
|
||||
coveringindex = self.search_coveringindex(tid, cols)
|
||||
|
||||
if coveringindex is None and 'autoindex' in c and c['autoindex'] and\
|
||||
('coveringindex' in c and
|
||||
c['coveringindex'] != ''):
|
||||
if coveringindex is None and 'autoindex' in c and c['autoindex'] and \
|
||||
('coveringindex' in c and
|
||||
c['coveringindex'] != ''):
|
||||
sql.append(render_template(
|
||||
"/".join([self.foreign_key_template_path, 'create_index.sql']),
|
||||
data=c, conn=self.conn).strip('\n')
|
||||
)
|
||||
)
|
||||
|
||||
if 'added' in constraint:
|
||||
for c in constraint['added']:
|
||||
@@ -1863,7 +1864,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
"/".join([self.foreign_key_template_path,
|
||||
'create.sql']),
|
||||
data=c, conn=self.conn
|
||||
).strip('\n')
|
||||
).strip('\n')
|
||||
)
|
||||
|
||||
if c['autoindex']:
|
||||
@@ -1947,7 +1948,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
"/".join([self.check_constraint_template_path,
|
||||
'create.sql']),
|
||||
data=c, conn=self.conn
|
||||
).strip('\n')
|
||||
).strip('\n')
|
||||
)
|
||||
|
||||
if len(sql) > 0:
|
||||
@@ -2023,7 +2024,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
"/".join([self.exclusion_constraint_template_path,
|
||||
'create.sql']),
|
||||
data=c, conn=self.conn
|
||||
).strip('\n')
|
||||
).strip('\n')
|
||||
)
|
||||
|
||||
if len(sql) > 0:
|
||||
@@ -2127,11 +2128,11 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
self.column_acl)
|
||||
|
||||
properties_sql = render_template("/".join([self.column_template_path,
|
||||
'properties.sql']),
|
||||
tid=tid,
|
||||
clid=c['attnum'],
|
||||
show_sys_objects=self.blueprint.show_system_objects
|
||||
)
|
||||
'properties.sql']),
|
||||
tid=tid,
|
||||
clid=c['attnum'],
|
||||
show_sys_objects=self.blueprint.show_system_objects
|
||||
)
|
||||
|
||||
status, res = self.conn.execute_dict(properties_sql)
|
||||
if not status:
|
||||
@@ -2249,7 +2250,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
return False
|
||||
|
||||
if data['autoindex'] and ('coveringindex' not in data or
|
||||
data['coveringindex'] == ''):
|
||||
data['coveringindex'] == ''):
|
||||
return False
|
||||
|
||||
return True
|
||||
@@ -2310,9 +2311,9 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
dependents_result.append({'type': 'sequence', 'name': ref_name, 'field': dep_type})
|
||||
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, scid, tid):
|
||||
@@ -2333,9 +2334,9 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
)
|
||||
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def sql(self, gid, sid, did, scid, tid):
|
||||
@@ -2576,7 +2577,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
"""
|
||||
|
||||
SQL = render_template("/".join(
|
||||
[self.rules_template_path, 'properties.sql']), tid=tid)
|
||||
[self.rules_template_path, 'properties.sql']), tid=tid)
|
||||
|
||||
status, rset = self.conn.execute_2darray(SQL)
|
||||
if not status:
|
||||
@@ -2586,7 +2587,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
rules_sql = '\n'
|
||||
SQL = render_template("/".join(
|
||||
[self.rules_template_path, 'properties.sql']
|
||||
), rid=row['oid'], datlastsysoid=self.datlastsysoid)
|
||||
), rid=row['oid'], datlastsysoid=self.datlastsysoid)
|
||||
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
@@ -2798,8 +2799,8 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
render_template(
|
||||
"/".join([self.template_path, 'get_schema.sql']),
|
||||
conn=self.conn, scid=scid
|
||||
)
|
||||
)
|
||||
)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=schema_name)
|
||||
|
||||
@@ -2808,8 +2809,8 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
render_template(
|
||||
"/".join([self.template_path, 'coll_table_stats.sql']),
|
||||
conn=self.conn, schema_name=schema_name
|
||||
)
|
||||
)
|
||||
)
|
||||
else:
|
||||
# For Individual table stats
|
||||
|
||||
@@ -2828,8 +2829,8 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
render_template(
|
||||
"/".join([self.template_path, 'get_table.sql']),
|
||||
conn=self.conn, scid=scid, tid=tid
|
||||
)
|
||||
)
|
||||
)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=table_name)
|
||||
|
||||
@@ -2839,15 +2840,16 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
||||
conn=self.conn, schema_name=schema_name,
|
||||
table_name=table_name,
|
||||
is_pgstattuple=is_pgstattuple, tid=tid
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
TableView.register_node_view(blueprint)
|
||||
|
||||
@@ -70,7 +70,7 @@ class ColumnsModule(CollectionNodeModule):
|
||||
"""
|
||||
Generate the collection node
|
||||
"""
|
||||
assert('tid' in kwargs or 'vid' in kwargs)
|
||||
assert ('tid' in kwargs or 'vid' in kwargs)
|
||||
yield self.generate_browser_collection_node(
|
||||
kwargs['tid'] if 'tid' in kwargs else kwargs['vid']
|
||||
)
|
||||
@@ -155,17 +155,17 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
|
||||
node_type = blueprint.node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'},
|
||||
{'type': 'int', 'id': 'tid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'},
|
||||
{'type': 'int', 'id': 'tid'}
|
||||
]
|
||||
ids = [
|
||||
# Here we specify type as any because table
|
||||
# are also has '-' in them if they are system table
|
||||
{'type': 'string', 'id': 'clid'}
|
||||
]
|
||||
# Here we specify type as any because table
|
||||
# are also has '-' in them if they are system table
|
||||
{'type': 'string', 'id': 'clid'}
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [
|
||||
@@ -188,6 +188,7 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
|
||||
database connection before running view, it will also attaches
|
||||
manager,conn & template_path properties to self
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
# Here args[0] will hold self & kwargs will hold gid,sid,did
|
||||
@@ -202,7 +203,7 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
|
||||
if not self.conn.connected():
|
||||
return precondition_required(
|
||||
gettext(
|
||||
"Connection to the server has been lost!"
|
||||
"Connection to the server has been lost!"
|
||||
)
|
||||
)
|
||||
|
||||
@@ -255,9 +256,9 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def nodes(self, gid, sid, did, scid, tid):
|
||||
@@ -291,12 +292,12 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
|
||||
row['name'],
|
||||
icon="icon-column",
|
||||
datatype=row['datatype'] # We need datatype somewhere in
|
||||
)) # exclusion constraint.
|
||||
)) # exclusion constraint.
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
def _formatter(self, scid, tid, clid, data):
|
||||
"""
|
||||
@@ -468,9 +469,9 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
|
||||
data = self._formatter(scid, tid, clid, data)
|
||||
|
||||
return ajax_response(
|
||||
response=data,
|
||||
status=200
|
||||
)
|
||||
response=data,
|
||||
status=200
|
||||
)
|
||||
|
||||
def _cltype_formatter(self, type):
|
||||
"""
|
||||
@@ -671,7 +672,6 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
|
||||
@check_precondition
|
||||
def msql(self, gid, sid, did, scid, tid, clid=None):
|
||||
"""
|
||||
@@ -706,9 +706,9 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
|
||||
|
||||
if SQL and SQL.strip('\n') and SQL.strip(' '):
|
||||
return make_json_response(
|
||||
data=SQL,
|
||||
status=200
|
||||
)
|
||||
data=SQL,
|
||||
status=200
|
||||
)
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
@@ -739,21 +739,21 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
|
||||
if key in data and data[key] is not None:
|
||||
if 'added' in data[key]:
|
||||
data[key]['added'] = parse_priv_to_db(
|
||||
data[key]['added'], self.acl
|
||||
data[key]['added'], self.acl
|
||||
)
|
||||
if 'changed' in data[key]:
|
||||
data[key]['changed'] = parse_priv_to_db(
|
||||
data[key]['changed'], self.acl
|
||||
data[key]['changed'], self.acl
|
||||
)
|
||||
if 'deleted' in data[key]:
|
||||
data[key]['deleted'] = parse_priv_to_db(
|
||||
data[key]['deleted'], self.acl
|
||||
data[key]['deleted'], self.acl
|
||||
)
|
||||
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'update.sql']),
|
||||
data=data, o_data=old_data, conn=self.conn
|
||||
)
|
||||
)
|
||||
else:
|
||||
required_args = [
|
||||
'name',
|
||||
@@ -875,9 +875,9 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
|
||||
dependents_result.append({'type': 'sequence', 'name': ref_name, 'field': dep_type})
|
||||
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, scid, tid, clid):
|
||||
@@ -900,9 +900,9 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
|
||||
)
|
||||
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def statistics(self, gid, sid, did, scid, tid, clid):
|
||||
@@ -935,16 +935,16 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
|
||||
"/".join([self.template_path, 'stats.sql']),
|
||||
conn=self.conn, schema=self.schema,
|
||||
table=self.table, column=column
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
ColumnsView.register_node_view(blueprint)
|
||||
|
||||
@@ -14,7 +14,7 @@ from flask import render_template, make_response
|
||||
from flask.ext.babel import gettext
|
||||
from pgadmin.browser.collection import CollectionNodeModule
|
||||
from pgadmin.utils.ajax import make_json_response, \
|
||||
make_response as ajax_response
|
||||
make_response as ajax_response
|
||||
|
||||
from .type import ConstraintRegistry
|
||||
|
||||
@@ -63,6 +63,7 @@ class ConstraintsModule(CollectionNodeModule):
|
||||
"""
|
||||
return database.DatabaseModule.NODE_TYPE
|
||||
|
||||
|
||||
blueprint = ConstraintsModule(__name__)
|
||||
|
||||
|
||||
@@ -86,9 +87,9 @@ def nodes(**kwargs):
|
||||
res = res + view.get_nodes(**kwargs)
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
@blueprint.route('/obj/<int:gid>/<int:sid>/<int:did>/<int:scid>/<int:tid>/')
|
||||
@@ -110,9 +111,9 @@ def proplist(**kwargs):
|
||||
res = res + view.get_node_list(**kwargs)
|
||||
|
||||
return ajax_response(
|
||||
response=res,
|
||||
status=200
|
||||
)
|
||||
response=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
@blueprint.route('/module.js')
|
||||
@@ -122,13 +123,13 @@ def module_js():
|
||||
|
||||
"""
|
||||
return make_response(
|
||||
render_template(
|
||||
"constraints/js/constraints.js",
|
||||
_=gettext,
|
||||
constraints=[
|
||||
(ConstraintRegistry.registry[n])['blueprint'].NODE_TYPE \
|
||||
for n in ConstraintRegistry.registry
|
||||
]
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
render_template(
|
||||
"constraints/js/constraints.js",
|
||||
_=gettext,
|
||||
constraints=[
|
||||
(ConstraintRegistry.registry[n])['blueprint'].NODE_TYPE \
|
||||
for n in ConstraintRegistry.registry
|
||||
]
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
|
||||
@@ -83,11 +83,11 @@ class CheckConstraintModule(CollectionNodeModule):
|
||||
Returns a snippet of css to include in the page
|
||||
"""
|
||||
return [
|
||||
render_template(
|
||||
"check_constraint/css/check_constraint.css",
|
||||
node_type=self.node_type
|
||||
)
|
||||
]
|
||||
render_template(
|
||||
"check_constraint/css/check_constraint.css",
|
||||
node_type=self.node_type
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
blueprint = CheckConstraintModule(__name__)
|
||||
@@ -199,6 +199,7 @@ class CheckConstraintView(PGChildNodeView):
|
||||
Checks database connection status.
|
||||
Attach connection object and template path.
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
self = args[0]
|
||||
@@ -260,9 +261,9 @@ class CheckConstraintView(PGChildNodeView):
|
||||
try:
|
||||
res = self.get_node_list(gid, sid, did, scid, tid, cid)
|
||||
return ajax_response(
|
||||
response=res,
|
||||
status=200
|
||||
)
|
||||
response=res,
|
||||
status=200
|
||||
)
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
@@ -305,9 +306,9 @@ class CheckConstraintView(PGChildNodeView):
|
||||
try:
|
||||
res = self.get_nodes(gid, sid, did, scid, tid, cid)
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
@@ -341,13 +342,13 @@ class CheckConstraintView(PGChildNodeView):
|
||||
icon = "icon-check_constraints"
|
||||
valid = True
|
||||
res.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
tid,
|
||||
row['name'],
|
||||
icon=icon,
|
||||
valid=valid
|
||||
))
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
tid,
|
||||
row['name'],
|
||||
icon=icon,
|
||||
valid=valid
|
||||
))
|
||||
return res
|
||||
|
||||
@check_precondition
|
||||
@@ -428,7 +429,7 @@ class CheckConstraintView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'create.sql']),
|
||||
data=data
|
||||
)
|
||||
)
|
||||
|
||||
status, msg = self.conn.execute_scalar(SQL)
|
||||
if not status:
|
||||
@@ -474,8 +475,8 @@ class CheckConstraintView(PGChildNodeView):
|
||||
data['name'],
|
||||
icon=icon,
|
||||
valid=valid
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
self.end_transaction()
|
||||
@@ -633,8 +634,8 @@ class CheckConstraintView(PGChildNodeView):
|
||||
sql_header = "-- Constraint: {0}\n\n-- ".format(data['name'])
|
||||
|
||||
sql_header += render_template(
|
||||
"/".join([self.template_path, 'delete.sql']),
|
||||
data=data)
|
||||
"/".join([self.template_path, 'delete.sql']),
|
||||
data=data)
|
||||
sql_header += "\n"
|
||||
|
||||
SQL = sql_header + SQL
|
||||
@@ -671,9 +672,9 @@ class CheckConstraintView(PGChildNodeView):
|
||||
sql = sql.strip('\n').strip(' ')
|
||||
|
||||
return make_json_response(
|
||||
data=sql,
|
||||
status=200
|
||||
)
|
||||
data=sql,
|
||||
status=200
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -709,7 +710,7 @@ class CheckConstraintView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'update.sql']),
|
||||
data=data, o_data=old_data, conn=self.conn
|
||||
)
|
||||
)
|
||||
else:
|
||||
required_args = ['consrc']
|
||||
|
||||
@@ -743,9 +744,9 @@ class CheckConstraintView(PGChildNodeView):
|
||||
"""
|
||||
dependents_result = self.get_dependents(self.conn, cid)
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, scid, tid, cid):
|
||||
@@ -763,9 +764,9 @@ class CheckConstraintView(PGChildNodeView):
|
||||
"""
|
||||
dependencies_result = self.get_dependencies(self.conn, cid)
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def validate_check_constraint(self, gid, sid, did, scid, tid, cid):
|
||||
@@ -811,7 +812,8 @@ class CheckConstraintView(PGChildNodeView):
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
|
||||
constraint = ConstraintRegistry(
|
||||
'check_constraint', CheckConstraintModule, CheckConstraintView
|
||||
)
|
||||
)
|
||||
CheckConstraintView.register_node_view(blueprint)
|
||||
|
||||
@@ -91,6 +91,7 @@ class ExclusionConstraintModule(ConstraintTypeModule):
|
||||
"""
|
||||
return database.DatabaseModule.NODE_TYPE
|
||||
|
||||
|
||||
blueprint = ExclusionConstraintModule(__name__)
|
||||
|
||||
|
||||
@@ -163,14 +164,14 @@ class ExclusionConstraintView(PGChildNodeView):
|
||||
node_type = 'exclusion_constraint'
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'},
|
||||
{'type': 'int', 'id': 'tid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'},
|
||||
{'type': 'int', 'id': 'tid'}
|
||||
]
|
||||
ids = [{'type': 'int', 'id': 'exid'}
|
||||
]
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [
|
||||
@@ -192,12 +193,12 @@ class ExclusionConstraintView(PGChildNodeView):
|
||||
Override this property for your own logic.
|
||||
"""
|
||||
return make_response(
|
||||
render_template(
|
||||
"exclusion_constraint/js/exclusion_constraint.js",
|
||||
_=_
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
render_template(
|
||||
"exclusion_constraint/js/exclusion_constraint.js",
|
||||
_=_
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
|
||||
def check_precondition(f):
|
||||
"""
|
||||
@@ -205,20 +206,21 @@ class ExclusionConstraintView(PGChildNodeView):
|
||||
database connection before running view, it will also attaches
|
||||
manager,conn & template_path properties to self
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
# Here args[0] will hold self & kwargs will hold gid,sid,did
|
||||
self = args[0]
|
||||
self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(
|
||||
kwargs['sid']
|
||||
)
|
||||
)
|
||||
self.conn = self.manager.connection(did=kwargs['did'])
|
||||
|
||||
# If DB not connected then return error to browser
|
||||
if not self.conn.connected():
|
||||
return precondition_required(
|
||||
_(
|
||||
"Connection to the server has been lost!"
|
||||
"Connection to the server has been lost!"
|
||||
)
|
||||
)
|
||||
|
||||
@@ -246,7 +248,7 @@ class ExclusionConstraintView(PGChildNodeView):
|
||||
|
||||
def end_transaction(self):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'end.sql']))
|
||||
"/".join([self.template_path, 'end.sql']))
|
||||
# End transaction if any.
|
||||
self.conn.execute_scalar(SQL)
|
||||
|
||||
@@ -307,9 +309,9 @@ class ExclusionConstraintView(PGChildNodeView):
|
||||
result['columns'] = columns
|
||||
|
||||
return ajax_response(
|
||||
response=result,
|
||||
status=200
|
||||
)
|
||||
response=result,
|
||||
status=200
|
||||
)
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
@@ -333,9 +335,9 @@ class ExclusionConstraintView(PGChildNodeView):
|
||||
try:
|
||||
res = self.get_node_list(gid, sid, did, scid, tid, exid)
|
||||
return ajax_response(
|
||||
response=res,
|
||||
status=200
|
||||
)
|
||||
response=res,
|
||||
status=200
|
||||
)
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
@@ -358,7 +360,7 @@ class ExclusionConstraintView(PGChildNodeView):
|
||||
"""
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
'properties.sql']),
|
||||
tid=tid)
|
||||
tid=tid)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
|
||||
return res['rows']
|
||||
@@ -383,9 +385,9 @@ class ExclusionConstraintView(PGChildNodeView):
|
||||
try:
|
||||
res = self.get_nodes(gid, sid, did, scid, tid, exid)
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
@@ -413,12 +415,12 @@ class ExclusionConstraintView(PGChildNodeView):
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
tid,
|
||||
row['name'],
|
||||
icon="icon-exclusion_constraint"
|
||||
))
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
tid,
|
||||
row['name'],
|
||||
icon="icon-exclusion_constraint"
|
||||
))
|
||||
return res
|
||||
|
||||
@check_precondition
|
||||
@@ -450,20 +452,20 @@ class ExclusionConstraintView(PGChildNodeView):
|
||||
for arg in required_args:
|
||||
if arg not in data:
|
||||
return make_json_response(
|
||||
status=400,
|
||||
success=0,
|
||||
errormsg=_(
|
||||
"Couldn't find required parameter (%s)." % str(arg)
|
||||
)
|
||||
status=400,
|
||||
success=0,
|
||||
errormsg=_(
|
||||
"Couldn't find required parameter (%s)." % str(arg)
|
||||
)
|
||||
)
|
||||
elif isinstance(data[arg], list) and len(data[arg]) < 1:
|
||||
return make_json_response(
|
||||
status=400,
|
||||
success=0,
|
||||
errormsg=_(
|
||||
"Couldn't find required parameter (%s)." % str(arg)
|
||||
)
|
||||
status=400,
|
||||
success=0,
|
||||
errormsg=_(
|
||||
"Couldn't find required parameter (%s)." % str(arg)
|
||||
)
|
||||
)
|
||||
|
||||
data['schema'] = self.schema
|
||||
data['table'] = self.table
|
||||
@@ -481,7 +483,7 @@ class ExclusionConstraintView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'create.sql']),
|
||||
data=data, conn=self.conn
|
||||
)
|
||||
)
|
||||
status, res = self.conn.execute_scalar(SQL)
|
||||
if not status:
|
||||
self.end_transaction()
|
||||
@@ -515,8 +517,8 @@ class ExclusionConstraintView(PGChildNodeView):
|
||||
tid,
|
||||
data['name'],
|
||||
icon="icon-exclusion_constraint"
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
self.end_transaction()
|
||||
@@ -675,9 +677,9 @@ class ExclusionConstraintView(PGChildNodeView):
|
||||
sql = sql.strip('\n').strip(' ')
|
||||
|
||||
return make_json_response(
|
||||
data=sql,
|
||||
status=200
|
||||
)
|
||||
data=sql,
|
||||
status=200
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -789,8 +791,8 @@ class ExclusionConstraintView(PGChildNodeView):
|
||||
sql_header = "-- Constraint: {0}\n\n-- ".format(data['name'])
|
||||
|
||||
sql_header += render_template(
|
||||
"/".join([self.template_path, 'delete.sql']),
|
||||
data=data)
|
||||
"/".join([self.template_path, 'delete.sql']),
|
||||
data=data)
|
||||
sql_header += "\n"
|
||||
|
||||
SQL = sql_header + SQL
|
||||
@@ -845,18 +847,18 @@ class ExclusionConstraintView(PGChildNodeView):
|
||||
"/".join([self.template_path, 'stats.sql']),
|
||||
conn=self.conn, schema=self.schema,
|
||||
name=name, exid=exid, is_pgstattuple=is_pgstattuple
|
||||
)
|
||||
)
|
||||
)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
constraint = ConstraintRegistry(
|
||||
'exclusion_constraint', ExclusionConstraintModule, ExclusionConstraintView
|
||||
)
|
||||
)
|
||||
ExclusionConstraintView.register_node_view(blueprint)
|
||||
|
||||
@@ -97,23 +97,24 @@ class ForeignKeyConstraintModule(ConstraintTypeModule):
|
||||
Returns a snippet of css to include in the page
|
||||
"""
|
||||
snippets = [
|
||||
render_template(
|
||||
"browser/css/collection.css",
|
||||
node_type=self.node_type,
|
||||
_=_
|
||||
),
|
||||
render_template(
|
||||
"foreign_key/css/foreign_key.css",
|
||||
node_type=self.node_type,
|
||||
_=_
|
||||
)
|
||||
]
|
||||
render_template(
|
||||
"browser/css/collection.css",
|
||||
node_type=self.node_type,
|
||||
_=_
|
||||
),
|
||||
render_template(
|
||||
"foreign_key/css/foreign_key.css",
|
||||
node_type=self.node_type,
|
||||
_=_
|
||||
)
|
||||
]
|
||||
|
||||
for submodule in self.submodules:
|
||||
snippets.extend(submodule.csssnippets)
|
||||
|
||||
return snippets
|
||||
|
||||
|
||||
blueprint = ForeignKeyConstraintModule(__name__)
|
||||
|
||||
|
||||
@@ -177,14 +178,14 @@ class ForeignKeyConstraintView(PGChildNodeView):
|
||||
node_type = 'foreign_key'
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'},
|
||||
{'type': 'int', 'id': 'tid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'},
|
||||
{'type': 'int', 'id': 'tid'}
|
||||
]
|
||||
ids = [{'type': 'int', 'id': 'fkid'}
|
||||
]
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [
|
||||
@@ -211,12 +212,12 @@ class ForeignKeyConstraintView(PGChildNodeView):
|
||||
Override this property for your own logic.
|
||||
"""
|
||||
return make_response(
|
||||
render_template(
|
||||
"foreign_key/js/foreign_key.js",
|
||||
_=_
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
render_template(
|
||||
"foreign_key/js/foreign_key.js",
|
||||
_=_
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
|
||||
def check_precondition(f):
|
||||
"""
|
||||
@@ -224,20 +225,21 @@ class ForeignKeyConstraintView(PGChildNodeView):
|
||||
database connection before running view, it will also attaches
|
||||
manager,conn & template_path properties to self
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
# Here args[0] will hold self & kwargs will hold gid,sid,did
|
||||
self = args[0]
|
||||
self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(
|
||||
kwargs['sid']
|
||||
)
|
||||
)
|
||||
self.conn = self.manager.connection(did=kwargs['did'])
|
||||
|
||||
# If DB not connected then return error to browser
|
||||
if not self.conn.connected():
|
||||
return precondition_required(
|
||||
_(
|
||||
"Connection to the server has been lost!"
|
||||
"Connection to the server has been lost!"
|
||||
)
|
||||
)
|
||||
|
||||
@@ -259,7 +261,7 @@ class ForeignKeyConstraintView(PGChildNodeView):
|
||||
|
||||
def end_transaction(self):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'end.sql']))
|
||||
"/".join([self.template_path, 'end.sql']))
|
||||
# End transaction if any.
|
||||
self.conn.execute_scalar(SQL)
|
||||
|
||||
@@ -323,9 +325,9 @@ class ForeignKeyConstraintView(PGChildNodeView):
|
||||
result['hasindex'] = False
|
||||
|
||||
return ajax_response(
|
||||
response=result,
|
||||
status=200
|
||||
)
|
||||
response=result,
|
||||
status=200
|
||||
)
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
@@ -349,9 +351,9 @@ class ForeignKeyConstraintView(PGChildNodeView):
|
||||
try:
|
||||
res = self.get_node_list(gid, sid, did, scid, tid, fkid)
|
||||
return ajax_response(
|
||||
response=res,
|
||||
status=200
|
||||
)
|
||||
response=res,
|
||||
status=200
|
||||
)
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
@@ -374,7 +376,7 @@ class ForeignKeyConstraintView(PGChildNodeView):
|
||||
"""
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
'properties.sql']),
|
||||
tid=tid)
|
||||
tid=tid)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
|
||||
return res['rows']
|
||||
@@ -399,9 +401,9 @@ class ForeignKeyConstraintView(PGChildNodeView):
|
||||
try:
|
||||
res = self.get_nodes(gid, sid, did, scid, tid, fkid)
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
@@ -435,13 +437,13 @@ class ForeignKeyConstraintView(PGChildNodeView):
|
||||
icon = "icon-foreign_key"
|
||||
valid = True
|
||||
res.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
tid,
|
||||
row['name'],
|
||||
icon=icon,
|
||||
valid=valid
|
||||
))
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
tid,
|
||||
row['name'],
|
||||
icon=icon,
|
||||
valid=valid
|
||||
))
|
||||
return res
|
||||
|
||||
@check_precondition
|
||||
@@ -473,20 +475,20 @@ class ForeignKeyConstraintView(PGChildNodeView):
|
||||
for arg in required_args:
|
||||
if arg not in data:
|
||||
return make_json_response(
|
||||
status=400,
|
||||
success=0,
|
||||
errormsg=_(
|
||||
"Couldn't find required parameter (%s)." % str(arg)
|
||||
)
|
||||
status=400,
|
||||
success=0,
|
||||
errormsg=_(
|
||||
"Couldn't find required parameter (%s)." % str(arg)
|
||||
)
|
||||
)
|
||||
elif isinstance(data[arg], list) and len(data[arg]) < 1:
|
||||
return make_json_response(
|
||||
status=400,
|
||||
success=0,
|
||||
errormsg=_(
|
||||
"Couldn't find required parameter (%s)." % str(arg)
|
||||
)
|
||||
status=400,
|
||||
success=0,
|
||||
errormsg=_(
|
||||
"Couldn't find required parameter (%s)." % str(arg)
|
||||
)
|
||||
)
|
||||
|
||||
data['schema'] = self.schema
|
||||
data['table'] = self.table
|
||||
@@ -514,7 +516,7 @@ class ForeignKeyConstraintView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'create.sql']),
|
||||
data=data, conn=self.conn
|
||||
)
|
||||
)
|
||||
status, res = self.conn.execute_scalar(SQL)
|
||||
if not status:
|
||||
self.end_transaction()
|
||||
@@ -568,8 +570,8 @@ class ForeignKeyConstraintView(PGChildNodeView):
|
||||
data['name'],
|
||||
valid=valid,
|
||||
icon=icon
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
self.end_transaction()
|
||||
@@ -632,8 +634,8 @@ class ForeignKeyConstraintView(PGChildNodeView):
|
||||
'sid': sid,
|
||||
'gid': gid,
|
||||
'did': did,
|
||||
'icon':icon,
|
||||
'valid':valid
|
||||
'icon': icon,
|
||||
'valid': valid
|
||||
}
|
||||
)
|
||||
else:
|
||||
@@ -735,9 +737,9 @@ class ForeignKeyConstraintView(PGChildNodeView):
|
||||
sql = sql.strip('\n').strip(' ')
|
||||
|
||||
return make_json_response(
|
||||
data=sql,
|
||||
status=200
|
||||
)
|
||||
data=sql,
|
||||
status=200
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -769,15 +771,15 @@ class ForeignKeyConstraintView(PGChildNodeView):
|
||||
sql = render_template("/".join([self.template_path, 'update.sql']),
|
||||
data=data, o_data=old_data)
|
||||
|
||||
if 'autoindex' in data and data['autoindex'] and\
|
||||
if 'autoindex' in data and data['autoindex'] and \
|
||||
('coveringindex' in data and
|
||||
data['coveringindex'] != ''):
|
||||
|
||||
col_sql = render_template("/".join([self.template_path,
|
||||
'get_constraint_cols.sql']),
|
||||
tid=tid,
|
||||
keys=zip(old_data['confkey'], old_data['conkey']),
|
||||
confrelid=old_data['confrelid'])
|
||||
'get_constraint_cols.sql']),
|
||||
tid=tid,
|
||||
keys=zip(old_data['confkey'], old_data['conkey']),
|
||||
confrelid=old_data['confrelid'])
|
||||
|
||||
status, res = self.conn.execute_dict(col_sql)
|
||||
|
||||
@@ -805,7 +807,7 @@ class ForeignKeyConstraintView(PGChildNodeView):
|
||||
return _('-- definition incomplete')
|
||||
|
||||
if data['autoindex'] and ('coveringindex' not in data or
|
||||
data['coveringindex'] == ''):
|
||||
data['coveringindex'] == ''):
|
||||
return _('-- definition incomplete')
|
||||
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
@@ -892,8 +894,8 @@ class ForeignKeyConstraintView(PGChildNodeView):
|
||||
sql_header = "-- Constraint: {0}\n\n-- ".format(data['name'])
|
||||
|
||||
sql_header += render_template(
|
||||
"/".join([self.template_path, 'delete.sql']),
|
||||
data=data)
|
||||
"/".join([self.template_path, 'delete.sql']),
|
||||
data=data)
|
||||
sql_header += "\n"
|
||||
|
||||
SQL = sql_header + SQL
|
||||
@@ -917,9 +919,9 @@ class ForeignKeyConstraintView(PGChildNodeView):
|
||||
"""
|
||||
dependents_result = self.get_dependents(self.conn, fkid)
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, scid, tid, fkid=None):
|
||||
@@ -935,9 +937,9 @@ class ForeignKeyConstraintView(PGChildNodeView):
|
||||
"""
|
||||
dependencies_result = self.get_dependencies(self.conn, fkid)
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def validate_foreign_key(self, gid, sid, did, scid, tid, fkid):
|
||||
@@ -1048,11 +1050,12 @@ class ForeignKeyConstraintView(PGChildNodeView):
|
||||
return make_json_response(
|
||||
data=index,
|
||||
status=200
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
|
||||
constraint = ConstraintRegistry(
|
||||
'foreign_key', ForeignKeyConstraintModule, ForeignKeyConstraintView
|
||||
)
|
||||
)
|
||||
ForeignKeyConstraintView.register_node_view(blueprint)
|
||||
|
||||
@@ -182,14 +182,14 @@ class IndexConstraintView(PGChildNodeView):
|
||||
node_label = _('Index constraint')
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'},
|
||||
{'type': 'int', 'id': 'tid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'},
|
||||
{'type': 'int', 'id': 'tid'}
|
||||
]
|
||||
ids = [{'type': 'int', 'id': 'cid'}
|
||||
]
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [
|
||||
@@ -213,14 +213,14 @@ class IndexConstraintView(PGChildNodeView):
|
||||
Override this property for your own logic.
|
||||
"""
|
||||
return make_response(
|
||||
render_template(
|
||||
"index_constraint/js/index_constraint.js",
|
||||
_=_,
|
||||
node_type=self.node_type,
|
||||
node_label=self.node_label
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
render_template(
|
||||
"index_constraint/js/index_constraint.js",
|
||||
_=_,
|
||||
node_type=self.node_type,
|
||||
node_label=self.node_label
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
|
||||
def check_precondition(f):
|
||||
"""
|
||||
@@ -228,20 +228,21 @@ class IndexConstraintView(PGChildNodeView):
|
||||
database connection before running view, it will also attaches
|
||||
manager,conn & template_path properties to self
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
# Here args[0] will hold self & kwargs will hold gid,sid,did
|
||||
self = args[0]
|
||||
self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(
|
||||
kwargs['sid']
|
||||
)
|
||||
)
|
||||
self.conn = self.manager.connection(did=kwargs['did'])
|
||||
|
||||
# If DB not connected then return error to browser
|
||||
if not self.conn.connected():
|
||||
return precondition_required(
|
||||
_(
|
||||
"Connection to the server has been lost!"
|
||||
"Connection to the server has been lost!"
|
||||
)
|
||||
)
|
||||
|
||||
@@ -263,7 +264,7 @@ class IndexConstraintView(PGChildNodeView):
|
||||
|
||||
def end_transaction(self):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'end.sql']))
|
||||
"/".join([self.template_path, 'end.sql']))
|
||||
# End transaction if any.
|
||||
self.conn.execute_scalar(SQL)
|
||||
|
||||
@@ -287,7 +288,7 @@ class IndexConstraintView(PGChildNodeView):
|
||||
sql = render_template("/".join([self.template_path, 'properties.sql']),
|
||||
tid=tid,
|
||||
cid=cid,
|
||||
constraint_type= self.constraint_type)
|
||||
constraint_type=self.constraint_type)
|
||||
status, res = self.conn.execute_dict(sql)
|
||||
|
||||
if not status:
|
||||
@@ -306,14 +307,14 @@ class IndexConstraintView(PGChildNodeView):
|
||||
|
||||
columns = []
|
||||
for row in res['rows']:
|
||||
columns.append({"column": row['column'].strip('"')})
|
||||
columns.append({"column": row['column'].strip('"')})
|
||||
|
||||
result['columns'] = columns
|
||||
|
||||
return ajax_response(
|
||||
response=result,
|
||||
status=200
|
||||
)
|
||||
response=result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def list(self, gid, sid, did, scid, tid, cid=None):
|
||||
@@ -335,9 +336,9 @@ class IndexConstraintView(PGChildNodeView):
|
||||
try:
|
||||
res = self.get_node_list(gid, sid, did, scid, tid, cid)
|
||||
return ajax_response(
|
||||
response=res,
|
||||
status=200
|
||||
)
|
||||
response=res,
|
||||
status=200
|
||||
)
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
@@ -360,7 +361,7 @@ class IndexConstraintView(PGChildNodeView):
|
||||
"""
|
||||
SQL = render_template("/".join([self.template_path, 'properties.sql']),
|
||||
tid=tid,
|
||||
constraint_type= self.constraint_type)
|
||||
constraint_type=self.constraint_type)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
|
||||
return res['rows']
|
||||
@@ -385,9 +386,9 @@ class IndexConstraintView(PGChildNodeView):
|
||||
try:
|
||||
res = self.get_nodes(gid, sid, did, scid, tid, cid)
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
@@ -415,12 +416,12 @@ class IndexConstraintView(PGChildNodeView):
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
tid,
|
||||
row['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
))
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
tid,
|
||||
row['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
))
|
||||
return res
|
||||
|
||||
@check_precondition
|
||||
@@ -440,7 +441,7 @@ class IndexConstraintView(PGChildNodeView):
|
||||
|
||||
"""
|
||||
required_args = [
|
||||
[u'columns', u'index'] # Either of one should be there.
|
||||
[u'columns', u'index'] # Either of one should be there.
|
||||
]
|
||||
|
||||
data = request.form if request.form else json.loads(request.data.decode())
|
||||
@@ -456,16 +457,16 @@ class IndexConstraintView(PGChildNodeView):
|
||||
for param in arg:
|
||||
if (param in data and
|
||||
(not isinstance(data[param], list) or
|
||||
(isinstance(data[param], list) and
|
||||
len(data[param]) > 0))):
|
||||
(isinstance(data[param], list) and
|
||||
len(data[param]) > 0))):
|
||||
break
|
||||
else:
|
||||
return make_json_response(
|
||||
status=400,
|
||||
success=0,
|
||||
errormsg=_(
|
||||
"Couldn't find at least one required parameter (%s)." % str(param)
|
||||
)
|
||||
status=400,
|
||||
success=0,
|
||||
errormsg=_(
|
||||
"Couldn't find at least one required parameter (%s)." % str(param)
|
||||
)
|
||||
)
|
||||
|
||||
elif arg not in data:
|
||||
@@ -494,7 +495,7 @@ class IndexConstraintView(PGChildNodeView):
|
||||
"/".join([self.template_path, 'create.sql']),
|
||||
data=data, conn=self.conn,
|
||||
constraint_name=self.constraint_name
|
||||
)
|
||||
)
|
||||
|
||||
status, msg = self.conn.execute_scalar(SQL)
|
||||
if not status:
|
||||
@@ -534,8 +535,8 @@ class IndexConstraintView(PGChildNodeView):
|
||||
tid,
|
||||
data['name'],
|
||||
icon="icon-%s" % self.node_type
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
self.end_transaction()
|
||||
@@ -636,7 +637,7 @@ class IndexConstraintView(PGChildNodeView):
|
||||
try:
|
||||
sql = render_template("/".join([self.template_path, 'get_name.sql']),
|
||||
tid=tid,
|
||||
constraint_type = self.constraint_type,
|
||||
constraint_type=self.constraint_type,
|
||||
cid=cid)
|
||||
status, res = self.conn.execute_dict(sql)
|
||||
if not status:
|
||||
@@ -698,9 +699,9 @@ class IndexConstraintView(PGChildNodeView):
|
||||
sql = sql.strip('\n').strip(' ')
|
||||
|
||||
return make_json_response(
|
||||
data=sql,
|
||||
status=200
|
||||
)
|
||||
data=sql,
|
||||
status=200
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -721,7 +722,7 @@ class IndexConstraintView(PGChildNodeView):
|
||||
sql = render_template("/".join([self.template_path, 'properties.sql']),
|
||||
tid=tid,
|
||||
cid=cid,
|
||||
constraint_type= self.constraint_type)
|
||||
constraint_type=self.constraint_type)
|
||||
status, res = self.conn.execute_dict(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -737,7 +738,7 @@ class IndexConstraintView(PGChildNodeView):
|
||||
o_data=old_data)
|
||||
else:
|
||||
required_args = [
|
||||
[u'columns', u'index'] # Either of one should be there.
|
||||
[u'columns', u'index'] # Either of one should be there.
|
||||
]
|
||||
|
||||
for arg in required_args:
|
||||
@@ -745,9 +746,9 @@ class IndexConstraintView(PGChildNodeView):
|
||||
for param in arg:
|
||||
if (param in data and
|
||||
((isinstance(data[param], str) and
|
||||
data[param] != "") or
|
||||
(isinstance(data[param], list) and
|
||||
len(data[param]) > 0))):
|
||||
data[param] != "") or
|
||||
(isinstance(data[param], list) and
|
||||
len(data[param]) > 0))):
|
||||
break
|
||||
else:
|
||||
return _('-- definition incomplete')
|
||||
@@ -805,7 +806,7 @@ class IndexConstraintView(PGChildNodeView):
|
||||
|
||||
columns = []
|
||||
for row in res['rows']:
|
||||
columns.append({"column": row['column'].strip('"')})
|
||||
columns.append({"column": row['column'].strip('"')})
|
||||
|
||||
data['columns'] = columns
|
||||
|
||||
@@ -817,8 +818,8 @@ class IndexConstraintView(PGChildNodeView):
|
||||
sql_header = "-- Constraint: {0}\n\n-- ".format(data['name'])
|
||||
|
||||
sql_header += render_template(
|
||||
"/".join([self.template_path, 'delete.sql']),
|
||||
data=data)
|
||||
"/".join([self.template_path, 'delete.sql']),
|
||||
data=data)
|
||||
sql_header += "\n"
|
||||
|
||||
SQL = sql_header + SQL
|
||||
@@ -859,7 +860,7 @@ class IndexConstraintView(PGChildNodeView):
|
||||
sql = render_template("/".join([self.template_path, 'properties.sql']),
|
||||
tid=tid,
|
||||
cid=cid,
|
||||
constraint_type= self.constraint_type)
|
||||
constraint_type=self.constraint_type)
|
||||
status, res = self.conn.execute_dict(sql)
|
||||
|
||||
if not status:
|
||||
@@ -875,15 +876,16 @@ class IndexConstraintView(PGChildNodeView):
|
||||
"/".join([self.template_path, 'stats.sql']),
|
||||
conn=self.conn, schema=self.schema,
|
||||
name=name, cid=cid, is_pgstattuple=is_pgstattuple
|
||||
)
|
||||
)
|
||||
)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
class PrimaryKeyConstraintView(IndexConstraintView):
|
||||
node_type = 'primary_key'
|
||||
@@ -907,11 +909,11 @@ class UniqueConstraintView(IndexConstraintView):
|
||||
|
||||
primary_key_constraint = ConstraintRegistry(
|
||||
'primary_key', PrimaryKeyConstraintModule, PrimaryKeyConstraintView
|
||||
)
|
||||
)
|
||||
|
||||
unique_constraint = ConstraintRegistry(
|
||||
'unique_constraint', UniqueConstraintModule, UniqueConstraintView
|
||||
)
|
||||
)
|
||||
|
||||
PrimaryKeyConstraintView.register_node_view(primary_key_blueprint)
|
||||
UniqueConstraintView.register_node_view(unique_constraint_blueprint)
|
||||
|
||||
@@ -23,7 +23,6 @@ class ConstraintRegistry(object):
|
||||
|
||||
def __init__(self, name, con_blueprint, con_nodeview):
|
||||
if name not in ConstraintRegistry.registry:
|
||||
|
||||
blueprint = con_blueprint(name)
|
||||
|
||||
# TODO:: register the view with the blueprint
|
||||
|
||||
@@ -73,7 +73,7 @@ class IndexesModule(CollectionNodeModule):
|
||||
if not conn.connected():
|
||||
return precondition_required(
|
||||
gettext(
|
||||
"Connection to the server has been lost!"
|
||||
"Connection to the server has been lost!"
|
||||
)
|
||||
)
|
||||
|
||||
@@ -82,7 +82,7 @@ class IndexesModule(CollectionNodeModule):
|
||||
|
||||
template_path = 'index/sql/9.1_plus'
|
||||
SQL = render_template("/".join(
|
||||
[template_path, 'backend_support.sql']), vid=kwargs['vid'])
|
||||
[template_path, 'backend_support.sql']), vid=kwargs['vid'])
|
||||
status, res = conn.execute_scalar(SQL)
|
||||
|
||||
# check if any errors
|
||||
@@ -96,7 +96,7 @@ class IndexesModule(CollectionNodeModule):
|
||||
"""
|
||||
Generate the collection node
|
||||
"""
|
||||
assert('tid' in kwargs or 'vid' in kwargs)
|
||||
assert ('tid' in kwargs or 'vid' in kwargs)
|
||||
yield self.generate_browser_collection_node(
|
||||
kwargs['tid'] if 'tid' in kwargs else kwargs['vid']
|
||||
)
|
||||
@@ -116,6 +116,7 @@ class IndexesModule(CollectionNodeModule):
|
||||
"""
|
||||
return False
|
||||
|
||||
|
||||
blueprint = IndexesModule(__name__)
|
||||
|
||||
|
||||
@@ -180,15 +181,15 @@ class IndexesView(PGChildNodeView):
|
||||
node_type = blueprint.node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'},
|
||||
{'type': 'int', 'id': 'tid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'},
|
||||
{'type': 'int', 'id': 'tid'}
|
||||
]
|
||||
ids = [
|
||||
{'type': 'int', 'id': 'idx'}
|
||||
]
|
||||
{'type': 'int', 'id': 'idx'}
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [
|
||||
@@ -209,7 +210,7 @@ class IndexesView(PGChildNodeView):
|
||||
'get_access_methods': [{'get': 'get_access_methods'},
|
||||
{'get': 'get_access_methods'}],
|
||||
'get_op_class': [{'get': 'get_op_class'},
|
||||
{'get': 'get_op_class'}]
|
||||
{'get': 'get_op_class'}]
|
||||
})
|
||||
|
||||
def check_precondition(f):
|
||||
@@ -218,6 +219,7 @@ class IndexesView(PGChildNodeView):
|
||||
database connection before running view, it will also attaches
|
||||
manager,conn & template_path properties to self
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
# Here args[0] will hold self & kwargs will hold gid,sid,did
|
||||
@@ -230,7 +232,7 @@ class IndexesView(PGChildNodeView):
|
||||
if not self.conn.connected():
|
||||
return precondition_required(
|
||||
gettext(
|
||||
"Connection to the server has been lost!"
|
||||
"Connection to the server has been lost!"
|
||||
)
|
||||
)
|
||||
|
||||
@@ -274,13 +276,13 @@ class IndexesView(PGChildNodeView):
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
{'label': row['collation'],
|
||||
'value': row['collation']}
|
||||
)
|
||||
{'label': row['collation'],
|
||||
'value': row['collation']}
|
||||
)
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -301,13 +303,13 @@ class IndexesView(PGChildNodeView):
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
{'label': row['amname'],
|
||||
'value': row['amname']}
|
||||
)
|
||||
{'label': row['amname'],
|
||||
'value': row['amname']}
|
||||
)
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -346,14 +348,13 @@ class IndexesView(PGChildNodeView):
|
||||
res[row['amname']] = op_class_list
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
|
||||
@check_precondition
|
||||
def list(self, gid, sid, did, scid, tid):
|
||||
"""
|
||||
@@ -377,9 +378,9 @@ class IndexesView(PGChildNodeView):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def nodes(self, gid, sid, did, scid, tid):
|
||||
@@ -406,17 +407,17 @@ class IndexesView(PGChildNodeView):
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
tid,
|
||||
row['name'],
|
||||
icon="icon-index"
|
||||
))
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
tid,
|
||||
row['name'],
|
||||
icon="icon-index"
|
||||
))
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
def _column_details(self, idx, data):
|
||||
"""
|
||||
@@ -469,7 +470,6 @@ class IndexesView(PGChildNodeView):
|
||||
|
||||
return data
|
||||
|
||||
|
||||
@check_precondition
|
||||
def properties(self, gid, sid, did, scid, tid, idx):
|
||||
"""
|
||||
@@ -505,9 +505,9 @@ class IndexesView(PGChildNodeView):
|
||||
data = self._column_details(idx, data)
|
||||
|
||||
return ajax_response(
|
||||
response=data,
|
||||
status=200
|
||||
)
|
||||
response=data,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def create(self, gid, sid, did, scid, tid):
|
||||
@@ -705,7 +705,6 @@ class IndexesView(PGChildNodeView):
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
|
||||
@check_precondition
|
||||
def msql(self, gid, sid, did, scid, tid, idx=None):
|
||||
"""
|
||||
@@ -735,9 +734,9 @@ class IndexesView(PGChildNodeView):
|
||||
|
||||
if SQL and SQL.strip('\n') and SQL.strip(' '):
|
||||
return make_json_response(
|
||||
data=SQL,
|
||||
status=200
|
||||
)
|
||||
data=SQL,
|
||||
status=200
|
||||
)
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
@@ -765,7 +764,7 @@ class IndexesView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'update.sql']),
|
||||
data=data, o_data=old_data, conn=self.conn
|
||||
)
|
||||
)
|
||||
else:
|
||||
required_args = {
|
||||
'name': 'Name',
|
||||
@@ -855,9 +854,9 @@ class IndexesView(PGChildNodeView):
|
||||
)
|
||||
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, scid, tid, idx):
|
||||
@@ -879,9 +878,9 @@ class IndexesView(PGChildNodeView):
|
||||
)
|
||||
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def statistics(self, gid, sid, did, scid, tid, idx=None):
|
||||
@@ -933,8 +932,8 @@ class IndexesView(PGChildNodeView):
|
||||
"/".join([self.template_path, 'stats.sql']),
|
||||
conn=self.conn, schema=self.schema,
|
||||
index=index, idx=idx, is_pgstattuple=is_pgstattuple
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
else:
|
||||
status, res = self.conn.execute_dict(
|
||||
@@ -942,15 +941,16 @@ class IndexesView(PGChildNodeView):
|
||||
"/".join([self.template_path, 'coll_stats.sql']),
|
||||
conn=self.conn, schema=self.schema,
|
||||
table=self.table
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
IndexesView.register_node_view(blueprint)
|
||||
|
||||
@@ -57,7 +57,7 @@ class RuleModule(CollectionNodeModule):
|
||||
if not conn.connected():
|
||||
return precondition_required(
|
||||
gettext(
|
||||
"Connection to the server has been lost!"
|
||||
"Connection to the server has been lost!"
|
||||
)
|
||||
)
|
||||
|
||||
@@ -66,8 +66,8 @@ class RuleModule(CollectionNodeModule):
|
||||
|
||||
self.template_path = 'rules/sql'
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'backend_support.sql']
|
||||
), vid=kwargs['vid'])
|
||||
[self.template_path, 'backend_support.sql']
|
||||
), vid=kwargs['vid'])
|
||||
status, res = conn.execute_scalar(SQL)
|
||||
# check if any errors
|
||||
if not status:
|
||||
@@ -83,10 +83,10 @@ class RuleModule(CollectionNodeModule):
|
||||
"""
|
||||
Generate the collection node
|
||||
"""
|
||||
assert('tid' in kwargs or 'vid' in kwargs)
|
||||
assert ('tid' in kwargs or 'vid' in kwargs)
|
||||
yield self.generate_browser_collection_node(
|
||||
kwargs['tid'] if 'tid' in kwargs else kwargs['vid']
|
||||
)
|
||||
kwargs['tid'] if 'tid' in kwargs else kwargs['vid']
|
||||
)
|
||||
|
||||
@property
|
||||
def node_inode(self):
|
||||
@@ -109,17 +109,17 @@ class RuleModule(CollectionNodeModule):
|
||||
Returns a snippet of css to include in the page
|
||||
"""
|
||||
snippets = [
|
||||
render_template(
|
||||
"browser/css/collection.css",
|
||||
node_type=self.node_type,
|
||||
_=gettext
|
||||
),
|
||||
render_template(
|
||||
"rules/css/rule.css",
|
||||
node_type=self.node_type,
|
||||
_=gettext
|
||||
)
|
||||
]
|
||||
render_template(
|
||||
"browser/css/collection.css",
|
||||
node_type=self.node_type,
|
||||
_=gettext
|
||||
),
|
||||
render_template(
|
||||
"rules/css/rule.css",
|
||||
node_type=self.node_type,
|
||||
_=gettext
|
||||
)
|
||||
]
|
||||
|
||||
for submodule in self.submodules:
|
||||
snippets.extend(submodule.csssnippets)
|
||||
@@ -147,15 +147,15 @@ class RuleView(PGChildNodeView):
|
||||
node_type = blueprint.node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'},
|
||||
{'type': 'int', 'id': 'tid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'},
|
||||
{'type': 'int', 'id': 'tid'}
|
||||
]
|
||||
ids = [
|
||||
{'type': 'int', 'id': 'rid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'rid'}
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [
|
||||
@@ -181,12 +181,12 @@ class RuleView(PGChildNodeView):
|
||||
This property defines whether Javascript exists for this node.
|
||||
"""
|
||||
return make_response(
|
||||
render_template(
|
||||
"rules/js/rules.js",
|
||||
_=gettext
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
render_template(
|
||||
"rules/js/rules.js",
|
||||
_=gettext
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
|
||||
def check_precondition(f):
|
||||
"""
|
||||
@@ -194,20 +194,20 @@ class RuleView(PGChildNodeView):
|
||||
database connection before running a view. It will also attach
|
||||
manager, conn & template_path properties to self
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
|
||||
# Here args[0] will hold self & kwargs will hold gid,sid,did
|
||||
self = args[0]
|
||||
self.manager = get_driver(
|
||||
PG_DEFAULT_DRIVER).connection_manager(kwargs['sid'])
|
||||
PG_DEFAULT_DRIVER).connection_manager(kwargs['sid'])
|
||||
self.conn = self.manager.connection(did=kwargs['did'])
|
||||
|
||||
# If DB not connected then return error to browser
|
||||
if not self.conn.connected():
|
||||
return precondition_required(
|
||||
gettext(
|
||||
"Connection to the server has been lost!"
|
||||
"Connection to the server has been lost!"
|
||||
)
|
||||
)
|
||||
|
||||
@@ -225,15 +225,15 @@ class RuleView(PGChildNodeView):
|
||||
|
||||
# fetch schema name by schema id
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'properties.sql']), tid=tid)
|
||||
[self.template_path, 'properties.sql']), tid=tid)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def nodes(self, gid, sid, did, scid, tid):
|
||||
@@ -242,7 +242,7 @@ class RuleView(PGChildNodeView):
|
||||
"""
|
||||
res = []
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'properties.sql']), tid=tid)
|
||||
[self.template_path, 'properties.sql']), tid=tid)
|
||||
|
||||
status, rset = self.conn.execute_2darray(SQL)
|
||||
if not status:
|
||||
@@ -250,17 +250,17 @@ class RuleView(PGChildNodeView):
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
tid,
|
||||
row['name'],
|
||||
icon="icon-rule"
|
||||
))
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
tid,
|
||||
row['name'],
|
||||
icon="icon-rule"
|
||||
))
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def properties(self, gid, sid, did, scid, tid, rid):
|
||||
@@ -270,16 +270,16 @@ class RuleView(PGChildNodeView):
|
||||
"""
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'properties.sql']
|
||||
), rid=rid, datlastsysoid=self.datlastsysoid)
|
||||
), rid=rid, datlastsysoid=self.datlastsysoid)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
return ajax_response(
|
||||
response=parse_rule_definition(res),
|
||||
status=200
|
||||
)
|
||||
response=parse_rule_definition(res),
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def create(self, gid, sid, did, scid, tid):
|
||||
@@ -373,7 +373,7 @@ class RuleView(PGChildNodeView):
|
||||
try:
|
||||
# Get name for rule from did
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'delete.sql']), rid=rid)
|
||||
[self.template_path, 'delete.sql']), rid=rid)
|
||||
status, res_data = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res_data)
|
||||
@@ -381,10 +381,10 @@ class RuleView(PGChildNodeView):
|
||||
rset = res_data['rows'][0]
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'delete.sql']),
|
||||
rulename=rset['rulename'],
|
||||
relname=rset['relname'],
|
||||
nspname=rset['nspname'],
|
||||
cascade=cascade
|
||||
rulename=rset['rulename'],
|
||||
relname=rset['relname'],
|
||||
nspname=rset['nspname'],
|
||||
cascade=cascade
|
||||
)
|
||||
status, res = self.conn.execute_scalar(SQL)
|
||||
if not status:
|
||||
@@ -412,9 +412,9 @@ class RuleView(PGChildNodeView):
|
||||
data = request.args
|
||||
SQL = self.getSQL(gid, sid, data, tid, rid)
|
||||
return make_json_response(
|
||||
data=SQL,
|
||||
status=200
|
||||
)
|
||||
data=SQL,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def sql(self, gid, sid, did, scid, tid, rid):
|
||||
@@ -422,7 +422,7 @@ class RuleView(PGChildNodeView):
|
||||
This function will generate sql to render into the sql panel
|
||||
"""
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'properties.sql']), rid=rid)
|
||||
[self.template_path, 'properties.sql']), rid=rid)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -440,7 +440,7 @@ class RuleView(PGChildNodeView):
|
||||
try:
|
||||
if rid is not None:
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'properties.sql']), rid=rid)
|
||||
[self.template_path, 'properties.sql']), rid=rid)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
res_data = []
|
||||
res_data = parse_rule_definition(res)
|
||||
@@ -450,7 +450,7 @@ class RuleView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'update.sql']),
|
||||
data=data, o_data=old_data
|
||||
)
|
||||
)
|
||||
else:
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'create.sql']), data=data)
|
||||
@@ -475,7 +475,7 @@ class RuleView(PGChildNodeView):
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, scid, tid, rid):
|
||||
@@ -494,6 +494,7 @@ class RuleView(PGChildNodeView):
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
RuleView.register_node_view(blueprint)
|
||||
|
||||
@@ -73,7 +73,7 @@ class TriggerModule(CollectionNodeModule):
|
||||
if not conn.connected():
|
||||
return precondition_required(
|
||||
gettext(
|
||||
"Connection to the server has been lost!"
|
||||
"Connection to the server has been lost!"
|
||||
)
|
||||
)
|
||||
|
||||
@@ -82,7 +82,7 @@ class TriggerModule(CollectionNodeModule):
|
||||
|
||||
template_path = 'trigger/sql/9.1_plus'
|
||||
SQL = render_template("/".join(
|
||||
[template_path, 'backend_support.sql']), vid=kwargs['vid'])
|
||||
[template_path, 'backend_support.sql']), vid=kwargs['vid'])
|
||||
status, res = conn.execute_scalar(SQL)
|
||||
# check if any errors
|
||||
if not status:
|
||||
@@ -95,7 +95,7 @@ class TriggerModule(CollectionNodeModule):
|
||||
"""
|
||||
Generate the collection node
|
||||
"""
|
||||
assert('tid' in kwargs or 'vid' in kwargs)
|
||||
assert ('tid' in kwargs or 'vid' in kwargs)
|
||||
yield self.generate_browser_collection_node(
|
||||
kwargs['tid'] if 'tid' in kwargs else kwargs['vid']
|
||||
)
|
||||
@@ -121,17 +121,18 @@ class TriggerModule(CollectionNodeModule):
|
||||
Returns a snippet of css to include in the page
|
||||
"""
|
||||
snippets = [
|
||||
render_template(
|
||||
"trigger/css/trigger.css",
|
||||
node_type=self.node_type
|
||||
)
|
||||
]
|
||||
render_template(
|
||||
"trigger/css/trigger.css",
|
||||
node_type=self.node_type
|
||||
)
|
||||
]
|
||||
|
||||
for submodule in self.submodules:
|
||||
snippets.extend(submodule.csssnippets)
|
||||
|
||||
return snippets
|
||||
|
||||
|
||||
blueprint = TriggerModule(__name__)
|
||||
|
||||
|
||||
@@ -210,15 +211,15 @@ class TriggerView(PGChildNodeView):
|
||||
node_type = blueprint.node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'},
|
||||
{'type': 'int', 'id': 'tid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'},
|
||||
{'type': 'int', 'id': 'tid'}
|
||||
]
|
||||
ids = [
|
||||
{'type': 'int', 'id': 'trid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'trid'}
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [
|
||||
@@ -235,7 +236,7 @@ class TriggerView(PGChildNodeView):
|
||||
'dependent': [{'get': 'dependents'}],
|
||||
'module.js': [{}, {}, {'get': 'module_js'}],
|
||||
'get_triggerfunctions': [{'get': 'get_trigger_functions'},
|
||||
{'get': 'get_trigger_functions'}],
|
||||
{'get': 'get_trigger_functions'}],
|
||||
'enable': [{'put': 'enable_disable_trigger'}]
|
||||
})
|
||||
|
||||
@@ -245,6 +246,7 @@ class TriggerView(PGChildNodeView):
|
||||
database connection before running view, it will also attaches
|
||||
manager,conn & template_path properties to self
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
# Here args[0] will hold self & kwargs will hold gid,sid,did
|
||||
@@ -257,7 +259,7 @@ class TriggerView(PGChildNodeView):
|
||||
if not self.conn.connected():
|
||||
return precondition_required(
|
||||
gettext(
|
||||
"Connection to the server has been lost!"
|
||||
"Connection to the server has been lost!"
|
||||
)
|
||||
)
|
||||
|
||||
@@ -285,13 +287,13 @@ class TriggerView(PGChildNodeView):
|
||||
# Here we are storing trigger definition
|
||||
# We will use it to check trigger type definition
|
||||
self.trigger_definition = {
|
||||
'TRIGGER_TYPE_ROW': (1 << 0),
|
||||
'TRIGGER_TYPE_BEFORE': (1 << 1),
|
||||
'TRIGGER_TYPE_INSERT': (1 << 2),
|
||||
'TRIGGER_TYPE_DELETE': (1 << 3),
|
||||
'TRIGGER_TYPE_UPDATE': (1 << 4),
|
||||
'TRIGGER_TYPE_TRUNCATE': (1 << 5),
|
||||
'TRIGGER_TYPE_INSTEAD': (1 << 6)
|
||||
'TRIGGER_TYPE_ROW': (1 << 0),
|
||||
'TRIGGER_TYPE_BEFORE': (1 << 1),
|
||||
'TRIGGER_TYPE_INSERT': (1 << 2),
|
||||
'TRIGGER_TYPE_DELETE': (1 << 3),
|
||||
'TRIGGER_TYPE_UPDATE': (1 << 4),
|
||||
'TRIGGER_TYPE_TRUNCATE': (1 << 5),
|
||||
'TRIGGER_TYPE_INSTEAD': (1 << 6)
|
||||
}
|
||||
|
||||
return f(*args, **kwargs)
|
||||
@@ -314,7 +316,7 @@ class TriggerView(PGChildNodeView):
|
||||
res.append({
|
||||
'label': 'Inline EDB-SPL',
|
||||
'value': 'Inline EDB-SPL'
|
||||
})
|
||||
})
|
||||
try:
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
'get_triggerfunctions.sql']),
|
||||
@@ -326,13 +328,13 @@ class TriggerView(PGChildNodeView):
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
{'label': row['tfunctions'],
|
||||
'value': row['tfunctions']}
|
||||
)
|
||||
{'label': row['tfunctions'],
|
||||
'value': row['tfunctions']}
|
||||
)
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -360,9 +362,9 @@ class TriggerView(PGChildNodeView):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def nodes(self, gid, sid, did, scid, tid):
|
||||
@@ -389,18 +391,18 @@ class TriggerView(PGChildNodeView):
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
tid,
|
||||
row['name'],
|
||||
icon="icon-trigger" if row['is_enable_trigger']
|
||||
else "icon-trigger-bad"
|
||||
))
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
tid,
|
||||
row['name'],
|
||||
icon="icon-trigger" if row['is_enable_trigger']
|
||||
else "icon-trigger-bad"
|
||||
))
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
def _column_details(self, tid, clist):
|
||||
"""
|
||||
@@ -441,7 +443,7 @@ class TriggerView(PGChildNodeView):
|
||||
|
||||
# Fires event definition
|
||||
if data['tgtype'] & self.trigger_definition['TRIGGER_TYPE_BEFORE']:
|
||||
data['fires'] = 'BEFORE'
|
||||
data['fires'] = 'BEFORE'
|
||||
elif data['tgtype'] & self.trigger_definition['TRIGGER_TYPE_INSTEAD']:
|
||||
data['fires'] = 'INSTEAD OF'
|
||||
else:
|
||||
@@ -518,9 +520,9 @@ class TriggerView(PGChildNodeView):
|
||||
data = self._trigger_definition(data)
|
||||
|
||||
return ajax_response(
|
||||
response=data,
|
||||
status=200
|
||||
)
|
||||
response=data,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def create(self, gid, sid, did, scid, tid):
|
||||
@@ -552,11 +554,11 @@ class TriggerView(PGChildNodeView):
|
||||
for arg in required_args:
|
||||
if arg not in data:
|
||||
return make_json_response(
|
||||
status=410,
|
||||
success=0,
|
||||
errormsg=gettext("Couldn't find the required parameter (%s)." % \
|
||||
required_args[arg])
|
||||
)
|
||||
status=410,
|
||||
success=0,
|
||||
errormsg=gettext("Couldn't find the required parameter (%s)." % \
|
||||
required_args[arg])
|
||||
)
|
||||
|
||||
# Adding parent into data dict, will be using it while creating sql
|
||||
data['schema'] = self.schema
|
||||
@@ -716,9 +718,9 @@ class TriggerView(PGChildNodeView):
|
||||
|
||||
if SQL and SQL.strip('\n') and SQL.strip(' '):
|
||||
return make_json_response(
|
||||
data=SQL,
|
||||
status=200
|
||||
)
|
||||
data=SQL,
|
||||
status=200
|
||||
)
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
@@ -756,7 +758,7 @@ class TriggerView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'update.sql']),
|
||||
data=data, o_data=old_data, conn=self.conn
|
||||
)
|
||||
)
|
||||
else:
|
||||
required_args = {
|
||||
'name': 'Name',
|
||||
@@ -893,7 +895,6 @@ class TriggerView(PGChildNodeView):
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
|
||||
@check_precondition
|
||||
def dependents(self, gid, sid, did, scid, tid, trid):
|
||||
"""
|
||||
@@ -913,9 +914,9 @@ class TriggerView(PGChildNodeView):
|
||||
)
|
||||
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, scid, tid, trid):
|
||||
@@ -937,8 +938,9 @@ class TriggerView(PGChildNodeView):
|
||||
)
|
||||
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
TriggerView.register_node_view(blueprint)
|
||||
|
||||
@@ -86,6 +86,7 @@ class TypeModule(SchemaChildModule):
|
||||
"""
|
||||
return False
|
||||
|
||||
|
||||
blueprint = TypeModule(__name__)
|
||||
|
||||
|
||||
@@ -173,14 +174,14 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
||||
node_type = blueprint.node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'}
|
||||
]
|
||||
ids = [
|
||||
{'type': 'int', 'id': 'tid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'tid'}
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [
|
||||
@@ -213,6 +214,7 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
||||
database connection before running view, it will also attaches
|
||||
manager,conn & template_path properties to self
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
# Here args[0] will hold self & kwargs will hold gid,sid,did
|
||||
@@ -227,7 +229,7 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
||||
if not self.conn.connected():
|
||||
return precondition_required(
|
||||
gettext(
|
||||
"Connection to the server has been lost!"
|
||||
"Connection to the server has been lost!"
|
||||
)
|
||||
)
|
||||
|
||||
@@ -267,9 +269,9 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def nodes(self, gid, sid, did, scid):
|
||||
@@ -298,17 +300,17 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
scid,
|
||||
row['name'],
|
||||
icon="icon-type"
|
||||
))
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
scid,
|
||||
row['name'],
|
||||
icon="icon-type"
|
||||
))
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
def additional_properties(self, copy_dict, tid):
|
||||
"""
|
||||
@@ -376,9 +378,10 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
||||
is_precision = True if t_prec else False
|
||||
|
||||
composite_lst.append({
|
||||
'attnum':row['attnum'], 'member_name': row['attname'], 'type': row['typname'], 'collation': full_collate,
|
||||
'attnum': row['attnum'], 'member_name': row['attname'], 'type': row['typname'],
|
||||
'collation': full_collate,
|
||||
'tlength': t_len, 'precision': t_prec,
|
||||
'is_tlength': is_tlength, 'is_precision': is_precision })
|
||||
'is_tlength': is_tlength, 'is_precision': is_precision})
|
||||
|
||||
# Adding both results
|
||||
res['member_list'] = ', '.join(properties_list)
|
||||
@@ -470,9 +473,9 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
||||
copy_dict.update(self.additional_properties(copy_dict, tid))
|
||||
|
||||
return ajax_response(
|
||||
response=copy_dict,
|
||||
status=200
|
||||
)
|
||||
response=copy_dict,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def get_collations(self, gid, sid, did, scid, tid=None):
|
||||
@@ -490,13 +493,13 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
{'label': row['collation'],
|
||||
'value': row['collation']}
|
||||
)
|
||||
{'label': row['collation'],
|
||||
'value': row['collation']}
|
||||
)
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -552,17 +555,17 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
||||
max_val = 10
|
||||
|
||||
res.append(
|
||||
{'label': row['typname'], 'value': row['typname'],
|
||||
'typval': typeval, 'precision': precision,
|
||||
'length': length, 'min_val': min_val, 'max_val': max_val,
|
||||
'is_collatable': row['is_collatable']
|
||||
}
|
||||
)
|
||||
{'label': row['typname'], 'value': row['typname'],
|
||||
'typval': typeval, 'precision': precision,
|
||||
'length': length, 'min_val': min_val, 'max_val': max_val,
|
||||
'is_collatable': row['is_collatable']
|
||||
}
|
||||
)
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
@@ -583,14 +586,14 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
{'label': row['stype'], 'value': row['stype'],
|
||||
'is_collate': row['is_collate']}
|
||||
)
|
||||
{'label': row['stype'], 'value': row['stype'],
|
||||
'is_collate': row['is_collate']}
|
||||
)
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
@@ -614,13 +617,13 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
{'label': row['opcname'],
|
||||
'value': row['opcname']})
|
||||
{'label': row['opcname'],
|
||||
'value': row['opcname']})
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -651,14 +654,14 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
{'label': row['stypdiff'],
|
||||
'value': row['stypdiff']}
|
||||
)
|
||||
{'label': row['stypdiff'],
|
||||
'value': row['stypdiff']}
|
||||
)
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -697,18 +700,17 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
{'label': row['canonical'],
|
||||
'value': row['canonical']})
|
||||
{'label': row['canonical'],
|
||||
'value': row['canonical']})
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
|
||||
@check_precondition
|
||||
def get_external_functions_list(self, gid, sid, did, scid, tid=None):
|
||||
"""
|
||||
@@ -769,7 +771,6 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
|
||||
@check_precondition
|
||||
def create(self, gid, sid, did, scid):
|
||||
"""
|
||||
@@ -922,7 +923,6 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
|
||||
@check_precondition
|
||||
def delete(self, gid, sid, did, scid, tid):
|
||||
"""
|
||||
@@ -976,7 +976,6 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
|
||||
@check_precondition
|
||||
def msql(self, gid, sid, did, scid, tid=None):
|
||||
"""
|
||||
@@ -993,7 +992,7 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
||||
data = dict()
|
||||
|
||||
# converting nested request data in proper json format
|
||||
for key,val in req.items():
|
||||
for key, val in req.items():
|
||||
if key in ['composite', 'enum', 'seclabels', 'typacl']:
|
||||
data[key] = json.loads(val)
|
||||
else:
|
||||
@@ -1004,9 +1003,9 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
||||
|
||||
if SQL and SQL.strip('\n') and SQL.strip(' '):
|
||||
return make_json_response(
|
||||
data=SQL,
|
||||
status=200
|
||||
)
|
||||
data=SQL,
|
||||
status=200
|
||||
)
|
||||
except Exception as e:
|
||||
internal_server_error(errormsg=str(e))
|
||||
|
||||
@@ -1048,11 +1047,11 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
||||
for key in ['typacl']:
|
||||
if key in data and data[key] is not None:
|
||||
if 'added' in data[key]:
|
||||
data[key]['added'] = parse_priv_to_db(data[key]['added'], self.acl)
|
||||
data[key]['added'] = parse_priv_to_db(data[key]['added'], self.acl)
|
||||
if 'changed' in data[key]:
|
||||
data[key]['changed'] = parse_priv_to_db(data[key]['changed'], self.acl)
|
||||
data[key]['changed'] = parse_priv_to_db(data[key]['changed'], self.acl)
|
||||
if 'deleted' in data[key]:
|
||||
data[key]['deleted'] = parse_priv_to_db(data[key]['deleted'], self.acl)
|
||||
data[key]['deleted'] = parse_priv_to_db(data[key]['deleted'], self.acl)
|
||||
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
'properties.sql']),
|
||||
@@ -1091,7 +1090,7 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'update.sql']),
|
||||
data=data, o_data=old_data, conn=self.conn
|
||||
)
|
||||
)
|
||||
else:
|
||||
required_args = [
|
||||
'name',
|
||||
@@ -1112,7 +1111,6 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
||||
|
||||
return SQL
|
||||
|
||||
|
||||
@check_precondition
|
||||
def sql(self, gid, sid, did, scid, tid):
|
||||
"""
|
||||
@@ -1197,9 +1195,9 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
||||
)
|
||||
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, scid, tid):
|
||||
@@ -1219,8 +1217,9 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
||||
)
|
||||
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
TypeView.register_node_view(blueprint)
|
||||
|
||||
@@ -43,22 +43,22 @@ class SchemaChildModule(CollectionNodeModule):
|
||||
|
||||
def BackendSupported(self, manager, **kwargs):
|
||||
return (
|
||||
(
|
||||
kwargs['is_catalog'] and ((
|
||||
self.CATALOG_DB_SUPPORTED and kwargs['db_support']
|
||||
) or (
|
||||
not self.CATALOG_DB_SUPPORTED and
|
||||
not kwargs['db_support'] and
|
||||
(
|
||||
self.SUPPORTED_SCHEMAS is None or (
|
||||
kwargs['schema_name'] in self.SUPPORTED_SCHEMAS
|
||||
)
|
||||
)
|
||||
))
|
||||
) or (
|
||||
not kwargs['is_catalog'] and self.CATALOG_DB_SUPPORTED
|
||||
)
|
||||
) and CollectionNodeModule.BackendSupported(
|
||||
(
|
||||
kwargs['is_catalog'] and ((
|
||||
self.CATALOG_DB_SUPPORTED and kwargs['db_support']
|
||||
) or (
|
||||
not self.CATALOG_DB_SUPPORTED and
|
||||
not kwargs['db_support'] and
|
||||
(
|
||||
self.SUPPORTED_SCHEMAS is None or (
|
||||
kwargs['schema_name'] in self.SUPPORTED_SCHEMAS
|
||||
)
|
||||
)
|
||||
))
|
||||
) or (
|
||||
not kwargs['is_catalog'] and self.CATALOG_DB_SUPPORTED
|
||||
)
|
||||
) and CollectionNodeModule.BackendSupported(
|
||||
self, manager, **kwargs
|
||||
)
|
||||
|
||||
@@ -161,9 +161,9 @@ class DataTypeReader:
|
||||
# Above 7.4, format_type also sends the schema name if it's not included
|
||||
# in the search_path, so we need to skip it in the typname
|
||||
if typname.find(schema + '".') >= 0:
|
||||
name = typname[len(schema)+3]
|
||||
name = typname[len(schema) + 3]
|
||||
elif typname.find(schema + '.') >= 0:
|
||||
name = typname[len(schema)+1]
|
||||
name = typname[len(schema) + 1]
|
||||
else:
|
||||
name = typname
|
||||
|
||||
@@ -191,19 +191,19 @@ class DataTypeReader:
|
||||
_len = (typmod - 4) >> 16;
|
||||
_prec = (typmod - 4) & 0xffff;
|
||||
length += str(_len)
|
||||
if(_prec):
|
||||
if (_prec):
|
||||
length += ',' + str(_prec)
|
||||
elif name == 'time' or \
|
||||
name == 'timetz' or \
|
||||
name == 'time without time zone' or \
|
||||
name == 'time with time zone' or \
|
||||
name == 'timestamp' or \
|
||||
name == 'timestamptz'or \
|
||||
name == 'timestamp without time zone' or \
|
||||
name == 'timestamp with time zone' or \
|
||||
name == 'bit' or \
|
||||
name == 'bit varying' or \
|
||||
name == 'varbit':
|
||||
name == 'timetz' or \
|
||||
name == 'time without time zone' or \
|
||||
name == 'time with time zone' or \
|
||||
name == 'timestamp' or \
|
||||
name == 'timestamptz' or \
|
||||
name == 'timestamp without time zone' or \
|
||||
name == 'timestamp with time zone' or \
|
||||
name == 'bit' or \
|
||||
name == 'bit varying' or \
|
||||
name == 'varbit':
|
||||
_prec = 0
|
||||
_len = typmod
|
||||
length += str(_len)
|
||||
@@ -250,13 +250,13 @@ def trigger_definition(data):
|
||||
# Here we are storing trigger definition
|
||||
# We will use it to check trigger type definition
|
||||
trigger_definition = {
|
||||
'TRIGGER_TYPE_ROW': (1 << 0),
|
||||
'TRIGGER_TYPE_BEFORE': (1 << 1),
|
||||
'TRIGGER_TYPE_INSERT': (1 << 2),
|
||||
'TRIGGER_TYPE_DELETE': (1 << 3),
|
||||
'TRIGGER_TYPE_UPDATE': (1 << 4),
|
||||
'TRIGGER_TYPE_TRUNCATE': (1 << 5),
|
||||
'TRIGGER_TYPE_INSTEAD': (1 << 6)
|
||||
'TRIGGER_TYPE_ROW': (1 << 0),
|
||||
'TRIGGER_TYPE_BEFORE': (1 << 1),
|
||||
'TRIGGER_TYPE_INSERT': (1 << 2),
|
||||
'TRIGGER_TYPE_DELETE': (1 << 3),
|
||||
'TRIGGER_TYPE_UPDATE': (1 << 4),
|
||||
'TRIGGER_TYPE_TRUNCATE': (1 << 5),
|
||||
'TRIGGER_TYPE_INSTEAD': (1 << 6)
|
||||
}
|
||||
|
||||
# Fires event definition
|
||||
@@ -369,6 +369,7 @@ class VacuumSettings:
|
||||
* type - table/toast vacuum type
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@@ -388,8 +389,8 @@ class VacuumSettings:
|
||||
vacuum_fields = json.loads(vacuum_fields)
|
||||
|
||||
# returns an array of setting & name values
|
||||
vacuum_fields_keys = "'"+"','".join(
|
||||
vacuum_fields['table'].keys())+"'"
|
||||
vacuum_fields_keys = "'" + "','".join(
|
||||
vacuum_fields['table'].keys()) + "'"
|
||||
SQL = render_template('vacuum_settings/sql/vacuum_defaults.sql',
|
||||
columns=vacuum_fields_keys)
|
||||
status, res = conn.execute_dict(SQL)
|
||||
@@ -421,8 +422,8 @@ class VacuumSettings:
|
||||
vacuum_fields = json.loads(vacuum_fields)
|
||||
|
||||
# returns an array of setting & name values
|
||||
vacuum_fields_keys = "'"+"','".join(
|
||||
vacuum_fields['toast'].keys())+"'"
|
||||
vacuum_fields_keys = "'" + "','".join(
|
||||
vacuum_fields['toast'].keys()) + "'"
|
||||
SQL = render_template('vacuum_settings/sql/vacuum_defaults.sql',
|
||||
columns=vacuum_fields_keys)
|
||||
status, res = conn.execute_dict(SQL)
|
||||
@@ -456,7 +457,7 @@ class VacuumSettings:
|
||||
vacuum_fields = json.loads(vacuum_fields)
|
||||
|
||||
# returns an array of setting & name values
|
||||
vacuum_fields_keys = "'"+"','".join(
|
||||
vacuum_fields_keys = "'" + "','".join(
|
||||
vacuum_fields[type].keys()) + "'"
|
||||
SQL = render_template('vacuum_settings/sql/vacuum_defaults.sql',
|
||||
columns=vacuum_fields_keys)
|
||||
@@ -492,4 +493,4 @@ class VacuumSettings:
|
||||
value = int(result[row_name])
|
||||
row['value'] = row['setting'] = value
|
||||
|
||||
return res['rows']
|
||||
return res['rows']
|
||||
|
||||
@@ -100,22 +100,22 @@ class ViewModule(SchemaChildModule):
|
||||
Returns a snippet of css to include in the page
|
||||
"""
|
||||
snippets = [
|
||||
render_template(
|
||||
"browser/css/collection.css",
|
||||
node_type=self.node_type,
|
||||
_=gettext
|
||||
),
|
||||
render_template(
|
||||
"view/css/view.css",
|
||||
node_type=self.node_type,
|
||||
_=gettext
|
||||
),
|
||||
render_template(
|
||||
"mview/css/mview.css",
|
||||
node_type='mview',
|
||||
_=gettext
|
||||
)
|
||||
]
|
||||
render_template(
|
||||
"browser/css/collection.css",
|
||||
node_type=self.node_type,
|
||||
_=gettext
|
||||
),
|
||||
render_template(
|
||||
"view/css/view.css",
|
||||
node_type=self.node_type,
|
||||
_=gettext
|
||||
),
|
||||
render_template(
|
||||
"mview/css/mview.css",
|
||||
node_type='mview',
|
||||
_=gettext
|
||||
)
|
||||
]
|
||||
|
||||
for submodule in self.submodules:
|
||||
snippets.extend(submodule.csssnippets)
|
||||
@@ -159,6 +159,7 @@ def check_precondition(f):
|
||||
Assumptions:
|
||||
This function will always be used as decorator of a class method.
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
|
||||
@@ -176,14 +177,14 @@ def check_precondition(f):
|
||||
gettext("Connection to the server has been lost!")
|
||||
)
|
||||
self.datlastsysoid = self.manager.db_info[
|
||||
kwargs['did']]['datlastsysoid']
|
||||
kwargs['did']]['datlastsysoid']
|
||||
|
||||
# Set template path for sql scripts
|
||||
self.template_path = self.template_initial + '/' + (
|
||||
self.ppas_template_path(self.manager.version)
|
||||
if self.manager.server_type == 'ppas' else
|
||||
self.pg_template_path(self.manager.version)
|
||||
)
|
||||
)
|
||||
|
||||
ver = self.manager.version
|
||||
if ver >= 90200:
|
||||
@@ -257,14 +258,14 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
node_type = view_blueprint.node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'},
|
||||
{'type': 'int', 'id': 'did'},
|
||||
{'type': 'int', 'id': 'scid'}
|
||||
]
|
||||
ids = [
|
||||
{'type': 'int', 'id': 'vid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'vid'}
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [
|
||||
@@ -287,11 +288,11 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
'select_sql': [{'get': 'select_sql'}, {'get': 'select_sql'}],
|
||||
'insert_sql': [{'get': 'insert_sql'}, {'get': 'insert_sql'}],
|
||||
'get_table_vacuum': [
|
||||
{'get': 'get_table_vacuum'},
|
||||
{'get': 'get_table_vacuum'}],
|
||||
{'get': 'get_table_vacuum'},
|
||||
{'get': 'get_table_vacuum'}],
|
||||
'get_toast_table_vacuum': [
|
||||
{'get': 'get_toast_table_vacuum'},
|
||||
{'get': 'get_toast_table_vacuum'}]
|
||||
{'get': 'get_toast_table_vacuum'},
|
||||
{'get': 'get_toast_table_vacuum'}]
|
||||
})
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
@@ -336,15 +337,15 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
Fetches all views properties and render into properties tab
|
||||
"""
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'sql/properties.sql']), scid=scid)
|
||||
[self.template_path, 'sql/properties.sql']), scid=scid)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def nodes(self, gid, sid, did, scid):
|
||||
@@ -353,24 +354,24 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
"""
|
||||
res = []
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'sql/properties.sql']), scid=scid)
|
||||
[self.template_path, 'sql/properties.sql']), scid=scid)
|
||||
status, rset = self.conn.execute_2darray(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=rset)
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
scid,
|
||||
row['name'],
|
||||
icon="icon-view"
|
||||
))
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
scid,
|
||||
row['name'],
|
||||
icon="icon-view"
|
||||
))
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
def parse_views_privileges(self, db_privileges):
|
||||
"""
|
||||
@@ -407,13 +408,13 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
"""
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'sql/properties.sql']
|
||||
), vid=vid, datlastsysoid=self.datlastsysoid)
|
||||
), vid=vid, datlastsysoid=self.datlastsysoid)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'sql/acl.sql']), vid=vid)
|
||||
[self.template_path, 'sql/acl.sql']), vid=vid)
|
||||
status, dataclres = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -434,9 +435,9 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
result.update(frmtd_reslt)
|
||||
|
||||
return ajax_response(
|
||||
response=result,
|
||||
status=200
|
||||
)
|
||||
response=result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def formatter(result):
|
||||
@@ -450,7 +451,7 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
sec_lbls.append({
|
||||
'provider': sec.group(1),
|
||||
'label': sec.group(2)
|
||||
})
|
||||
})
|
||||
|
||||
frmtd_result.update({"seclabels": sec_lbls})
|
||||
return frmtd_result
|
||||
@@ -485,14 +486,14 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'sql/view_id.sql']), data=data)
|
||||
[self.template_path, 'sql/view_id.sql']), data=data)
|
||||
status, view_id = self.conn.execute_scalar(SQL)
|
||||
return jsonify(
|
||||
node=self.blueprint.generate_browser_node(
|
||||
view_id,
|
||||
scid,
|
||||
data['name'],
|
||||
icon="icon-view"
|
||||
view_id,
|
||||
scid,
|
||||
data['name'],
|
||||
icon="icon-view"
|
||||
)
|
||||
)
|
||||
else:
|
||||
@@ -520,7 +521,7 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'sql/view_id.sql']), data=data)
|
||||
[self.template_path, 'sql/view_id.sql']), data=data)
|
||||
status, res_data = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -530,10 +531,10 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
if vid != view_id:
|
||||
return jsonify(
|
||||
node=self.blueprint.generate_browser_node(
|
||||
view_id,
|
||||
scid,
|
||||
new_view_name,
|
||||
icon="icon-view"
|
||||
view_id,
|
||||
scid,
|
||||
new_view_name,
|
||||
icon="icon-view"
|
||||
)
|
||||
)
|
||||
else:
|
||||
@@ -608,7 +609,7 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
scid: Schema Id
|
||||
"""
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
'sql/get_schema.sql']), scid=scid)
|
||||
'sql/get_schema.sql']), scid=scid)
|
||||
|
||||
status, schema_name = self.conn.execute_scalar(SQL)
|
||||
|
||||
@@ -631,16 +632,16 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
|
||||
SQL = self.getSQL(gid, sid, data, vid)
|
||||
SQL = SQL.strip('\n')
|
||||
if(SQL):
|
||||
if (SQL):
|
||||
return make_json_response(
|
||||
data=SQL,
|
||||
status=200
|
||||
)
|
||||
data=SQL,
|
||||
status=200
|
||||
)
|
||||
else:
|
||||
return make_json_response(
|
||||
data=gettext("-- Nothing changed"),
|
||||
status=200
|
||||
)
|
||||
data=gettext("-- Nothing changed"),
|
||||
status=200
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def parse_privileges(str_privileges, object_type='VIEW'):
|
||||
@@ -653,7 +654,7 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
'D': 'TRUNCATE',
|
||||
'x': 'REFERENCES',
|
||||
't': 'TRIGGER'
|
||||
}
|
||||
}
|
||||
privileges = []
|
||||
for priv in str_privileges:
|
||||
priv_with_grant = []
|
||||
@@ -661,10 +662,10 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
for privilege in priv['privileges']:
|
||||
if privilege['with_grant']:
|
||||
priv_with_grant.append(
|
||||
db_privileges[privilege['privilege_type']])
|
||||
db_privileges[privilege['privilege_type']])
|
||||
elif privilege['privilege']:
|
||||
priv_without_grant.append(
|
||||
db_privileges[privilege['privilege_type']])
|
||||
db_privileges[privilege['privilege_type']])
|
||||
|
||||
# If we have all acl then just return all
|
||||
if len(priv_with_grant) == len(db_privileges):
|
||||
@@ -675,11 +676,11 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
# Server Level validation
|
||||
if 'grantee' in priv:
|
||||
privileges.append(
|
||||
{
|
||||
'grantee': priv['grantee'] if 'grantee' in priv else '',
|
||||
'with_grant': priv_with_grant,
|
||||
'without_grant': priv_without_grant
|
||||
}
|
||||
{
|
||||
'grantee': priv['grantee'] if 'grantee' in priv else '',
|
||||
'with_grant': priv_with_grant,
|
||||
'without_grant': priv_without_grant
|
||||
}
|
||||
)
|
||||
else:
|
||||
return ''
|
||||
@@ -693,8 +694,8 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
if vid is not None:
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'sql/properties.sql']),
|
||||
vid=vid,
|
||||
datlastsysoid=self.datlastsysoid
|
||||
vid=vid,
|
||||
datlastsysoid=self.datlastsysoid
|
||||
)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
@@ -711,16 +712,16 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
if key in data and data[key] is not None:
|
||||
if 'added' in data[key]:
|
||||
data[key]['added'] = self.parse_privileges(
|
||||
data[key]['added'])
|
||||
data[key]['added'])
|
||||
if 'changed' in data[key]:
|
||||
data[key]['changed'] = self.parse_privileges(
|
||||
data[key]['changed'])
|
||||
data[key]['changed'])
|
||||
if 'deleted' in data[key]:
|
||||
data[key]['deleted'] = self.parse_privileges(
|
||||
data[key]['deleted'])
|
||||
data[key]['deleted'])
|
||||
try:
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'sql/update.sql']), data=data,
|
||||
[self.template_path, 'sql/update.sql']), data=data,
|
||||
o_data=old_data, conn=self.conn)
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -741,11 +742,11 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
if 'datacl' in data and data['datacl'] is not None:
|
||||
data['datacl'] = self.parse_privileges(data['datacl'])
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'sql/create.sql']), data=data)
|
||||
[self.template_path, 'sql/create.sql']), data=data)
|
||||
if data['definition']:
|
||||
SQL += "\n"
|
||||
SQL += render_template("/".join(
|
||||
[self.template_path, 'sql/grant.sql']), data=data)
|
||||
[self.template_path, 'sql/grant.sql']), data=data)
|
||||
return SQL
|
||||
|
||||
except Exception as e:
|
||||
@@ -765,7 +766,7 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
|
||||
self.index_temp_path = 'index'
|
||||
SQL = render_template("/".join([self.index_temp_path,
|
||||
'sql/9.1_plus/column_details.sql']), idx=idx)
|
||||
'sql/9.1_plus/column_details.sql']), idx=idx)
|
||||
status, rset = self.conn.execute_2darray(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=rset)
|
||||
@@ -841,7 +842,7 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
self.rule_temp_path = 'rules'
|
||||
SQL_data = ''
|
||||
SQL = render_template("/".join(
|
||||
[self.rule_temp_path, 'sql/properties.sql']), tid=vid)
|
||||
[self.rule_temp_path, 'sql/properties.sql']), tid=vid)
|
||||
|
||||
status, data = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
@@ -853,13 +854,13 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
if rule['name'] != '_RETURN':
|
||||
res = []
|
||||
SQL = render_template("/".join(
|
||||
[self.rule_temp_path, 'sql/properties.sql']),
|
||||
[self.rule_temp_path, 'sql/properties.sql']),
|
||||
rid=rule['oid']
|
||||
)
|
||||
)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
res = parse_rule_definition(res)
|
||||
SQL = render_template("/".join(
|
||||
[self.rule_temp_path, 'sql/create.sql']),
|
||||
[self.rule_temp_path, 'sql/create.sql']),
|
||||
data=res, display_comments=True)
|
||||
SQL_data += '\n'
|
||||
SQL_data += SQL
|
||||
@@ -888,10 +889,10 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
|
||||
for trigger in data['rows']:
|
||||
SQL = render_template("/".join(
|
||||
[self.trigger_temp_path, 'sql/9.1_plus/properties.sql']),
|
||||
[self.trigger_temp_path, 'sql/9.1_plus/properties.sql']),
|
||||
tid=trigger['oid'],
|
||||
tgrelid=vid
|
||||
)
|
||||
)
|
||||
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
|
||||
@@ -909,7 +910,7 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
res_rows = trigger_definition(res_rows)
|
||||
|
||||
SQL = render_template("/".join(
|
||||
[self.trigger_temp_path, 'sql/9.1_plus/create.sql']),
|
||||
[self.trigger_temp_path, 'sql/9.1_plus/create.sql']),
|
||||
data=res_rows, display_comments=True)
|
||||
SQL_data += '\n'
|
||||
SQL_data += SQL
|
||||
@@ -926,7 +927,7 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
self.index_temp_path = 'index'
|
||||
SQL_data = ''
|
||||
SQL = render_template("/".join(
|
||||
[self.index_temp_path, 'sql/9.1_plus/properties.sql']), tid=vid)
|
||||
[self.index_temp_path, 'sql/9.1_plus/properties.sql']), tid=vid)
|
||||
status, data = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=data)
|
||||
@@ -934,10 +935,10 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
for index in data['rows']:
|
||||
res = []
|
||||
SQL = render_template("/".join(
|
||||
[self.index_temp_path, 'sql/9.1_plus/properties.sql']),
|
||||
[self.index_temp_path, 'sql/9.1_plus/properties.sql']),
|
||||
idx=index['oid'],
|
||||
tid=vid
|
||||
)
|
||||
)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
|
||||
data = dict(res['rows'][0])
|
||||
@@ -949,7 +950,7 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
data = self.get_index_column_details(index['oid'], data)
|
||||
|
||||
SQL = render_template("/".join(
|
||||
[self.index_temp_path, 'sql/9.1_plus/create.sql']),
|
||||
[self.index_temp_path, 'sql/9.1_plus/create.sql']),
|
||||
data=data, display_comments=True)
|
||||
SQL_data += '\n'
|
||||
SQL_data += SQL
|
||||
@@ -963,9 +964,9 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
|
||||
SQL_data = ''
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'sql/properties.sql']),
|
||||
vid=vid,
|
||||
datlastsysoid=self.datlastsysoid
|
||||
[self.template_path, 'sql/properties.sql']),
|
||||
vid=vid,
|
||||
datlastsysoid=self.datlastsysoid
|
||||
)
|
||||
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
@@ -976,7 +977,7 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
|
||||
# Fetch all privileges for view
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'sql/acl.sql']), vid=vid)
|
||||
[self.template_path, 'sql/acl.sql']), vid=vid)
|
||||
status, dataclres = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -993,14 +994,14 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
result['datacl'] = self.parse_privileges(result['datacl'])
|
||||
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'sql/create.sql']),
|
||||
data=result,
|
||||
conn=self.conn,
|
||||
display_comments=True
|
||||
)
|
||||
[self.template_path, 'sql/create.sql']),
|
||||
data=result,
|
||||
conn=self.conn,
|
||||
display_comments=True
|
||||
)
|
||||
SQL += "\n"
|
||||
SQL += render_template("/".join(
|
||||
[self.template_path, 'sql/grant.sql']), data=result)
|
||||
[self.template_path, 'sql/grant.sql']), data=result)
|
||||
|
||||
SQL_data += SQL
|
||||
SQL_data += self.get_rule_sql(vid)
|
||||
@@ -1018,20 +1019,20 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
try:
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'sql/get_tblspc.sql'])
|
||||
)
|
||||
)
|
||||
status, rset = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
{'label': row['spcname'], 'value': row['spcname']}
|
||||
)
|
||||
{'label': row['spcname'], 'value': row['spcname']}
|
||||
)
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -1052,7 +1053,7 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependencies(self, gid, sid, did, scid, vid):
|
||||
@@ -1070,7 +1071,7 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def select_sql(self, gid, sid, did, scid, vid):
|
||||
@@ -1273,8 +1274,8 @@ class MViewNode(ViewNode, VacuumSettings):
|
||||
if vid is not None:
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'sql/properties.sql']),
|
||||
vid=vid,
|
||||
datlastsysoid=self.datlastsysoid
|
||||
vid=vid,
|
||||
datlastsysoid=self.datlastsysoid
|
||||
)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
@@ -1301,65 +1302,65 @@ class MViewNode(ViewNode, VacuumSettings):
|
||||
data['vacuum_data']['reset'].append(item)
|
||||
else:
|
||||
if (old_data[item['name']] is None or
|
||||
(float(old_data[item['name']]) != float(item['value']))):
|
||||
(float(old_data[item['name']]) != float(item['value']))):
|
||||
data['vacuum_data']['changed'].append(item)
|
||||
|
||||
if ('autovacuum_enabled' in data and
|
||||
old_data['autovacuum_enabled'] is not None):
|
||||
old_data['autovacuum_enabled'] is not None):
|
||||
if (data['autovacuum_enabled'] !=
|
||||
old_data['autovacuum_enabled']):
|
||||
old_data['autovacuum_enabled']):
|
||||
data['vacuum_data']['changed'].append(
|
||||
{'name': 'autovacuum_enabled',
|
||||
'value': data['autovacuum_enabled']})
|
||||
elif ('autovacuum_enabled' in data and 'autovacuum_custom' in data and
|
||||
old_data['autovacuum_enabled'] is None and data['autovacuum_custom']):
|
||||
data['vacuum_data']['changed'].append(
|
||||
{'name': 'autovacuum_enabled',
|
||||
'value': data['autovacuum_enabled']})
|
||||
old_data['autovacuum_enabled'] is None and data['autovacuum_custom']):
|
||||
data['vacuum_data']['changed'].append(
|
||||
{'name': 'autovacuum_enabled',
|
||||
'value': data['autovacuum_enabled']})
|
||||
|
||||
# toast autovacuum: separate list of changed and reset data
|
||||
if ('vacuum_toast' in data):
|
||||
if ('changed' in data['vacuum_toast']):
|
||||
for item in data['vacuum_toast']['changed']:
|
||||
if 'value' in item.keys():
|
||||
toast_key = 'toast_'+item['name']
|
||||
item['name'] = 'toast.'+item['name']
|
||||
toast_key = 'toast_' + item['name']
|
||||
item['name'] = 'toast.' + item['name']
|
||||
if item['value'] is None:
|
||||
if old_data[toast_key] != item['value']:
|
||||
data['vacuum_data']['reset'].append(item)
|
||||
else:
|
||||
if (old_data[toast_key] is None or
|
||||
(float(old_data[toast_key]) != float(item['value']))):
|
||||
(float(old_data[toast_key]) != float(item['value']))):
|
||||
data['vacuum_data']['changed'].append(item)
|
||||
|
||||
if ('toast_autovacuum_enabled' in data and
|
||||
old_data['toast_autovacuum_enabled'] is not None):
|
||||
old_data['toast_autovacuum_enabled'] is not None):
|
||||
if (data['toast_autovacuum_enabled'] !=
|
||||
old_data['toast_autovacuum_enabled']):
|
||||
old_data['toast_autovacuum_enabled']):
|
||||
data['vacuum_data']['changed'].append(
|
||||
{'name': 'toast.autovacuum_enabled',
|
||||
'value': data['toast_autovacuum_enabled']})
|
||||
elif ('toast_autovacuum_enabled' in data and 'toast_autovacuum' in data and
|
||||
old_data['toast_autovacuum_enabled'] is None and data['toast_autovacuum']):
|
||||
data['vacuum_data']['changed'].append(
|
||||
{'name': 'toast.autovacuum_enabled',
|
||||
'value': data['toast_autovacuum_enabled']})
|
||||
old_data['toast_autovacuum_enabled'] is None and data['toast_autovacuum']):
|
||||
data['vacuum_data']['changed'].append(
|
||||
{'name': 'toast.autovacuum_enabled',
|
||||
'value': data['toast_autovacuum_enabled']})
|
||||
|
||||
key = 'datacl'
|
||||
if key in data and data[key] is not None:
|
||||
if 'added' in data[key]:
|
||||
data[key]['added'] = self.parse_privileges(
|
||||
data[key]['added'])
|
||||
data[key]['added'])
|
||||
if 'changed' in data[key]:
|
||||
data[key]['changed'] = self.parse_privileges(
|
||||
data[key]['changed'])
|
||||
data[key]['changed'])
|
||||
if 'deleted' in data[key]:
|
||||
data[key]['deleted'] = self.parse_privileges(
|
||||
data[key]['deleted'])
|
||||
data[key]['deleted'])
|
||||
|
||||
try:
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'sql/update.sql']), data=data,
|
||||
[self.template_path, 'sql/update.sql']), data=data,
|
||||
o_data=old_data, conn=self.conn)
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
@@ -1382,7 +1383,7 @@ class MViewNode(ViewNode, VacuumSettings):
|
||||
if 'value' in item.keys() and
|
||||
item['value'] is not None]
|
||||
vacuum_toast = [
|
||||
{'name': 'toast.'+item['name'], 'value':item['value']}
|
||||
{'name': 'toast.' + item['name'], 'value': item['value']}
|
||||
for item in data['vacuum_toast']
|
||||
if 'value' in item.keys() and item['value'] is not None]
|
||||
|
||||
@@ -1390,37 +1391,37 @@ class MViewNode(ViewNode, VacuumSettings):
|
||||
if ('autovacuum_custom' in data and data['autovacuum_custom']):
|
||||
vacuum_table.append(
|
||||
{
|
||||
'name': 'autovacuum_enabled',
|
||||
'value': str(data['autovacuum_enabled'])
|
||||
'name': 'autovacuum_enabled',
|
||||
'value': str(data['autovacuum_enabled'])
|
||||
}
|
||||
)
|
||||
if ('toast_autovacuum' in data and data['toast_autovacuum']):
|
||||
vacuum_table.append(
|
||||
{
|
||||
'name': 'toast.autovacuum_enabled',
|
||||
'value': str(data['toast_autovacuum_enabled'])
|
||||
'name': 'toast.autovacuum_enabled',
|
||||
'value': str(data['toast_autovacuum_enabled'])
|
||||
}
|
||||
)
|
||||
|
||||
# add vacuum_toast dict to vacuum_data only if
|
||||
# table & toast's custom autovacuum is enabled
|
||||
data['vacuum_data'] = (vacuum_table if (
|
||||
'autovacuum_custom' in data and
|
||||
data['autovacuum_custom'] is True
|
||||
) else []) + (
|
||||
vacuum_toast if (
|
||||
'toast_autovacuum' in data and
|
||||
data['toast_autovacuum'] is True
|
||||
) else [])
|
||||
'autovacuum_custom' in data and
|
||||
data['autovacuum_custom'] is True
|
||||
) else []) + (
|
||||
vacuum_toast if (
|
||||
'toast_autovacuum' in data and
|
||||
data['toast_autovacuum'] is True
|
||||
) else [])
|
||||
|
||||
if 'datacl' in data and data['datacl'] is not None:
|
||||
data['datacl'] = self.parse_privileges(data['datacl'])
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'sql/create.sql']), data=data)
|
||||
[self.template_path, 'sql/create.sql']), data=data)
|
||||
if data['definition']:
|
||||
SQL += "\n"
|
||||
SQL += render_template("/".join(
|
||||
[self.template_path, 'sql/grant.sql']), data=data)
|
||||
[self.template_path, 'sql/grant.sql']), data=data)
|
||||
return SQL
|
||||
|
||||
except Exception as e:
|
||||
@@ -1434,9 +1435,9 @@ class MViewNode(ViewNode, VacuumSettings):
|
||||
|
||||
SQL_data = ''
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'sql/properties.sql']),
|
||||
vid=vid,
|
||||
datlastsysoid=self.datlastsysoid
|
||||
[self.template_path, 'sql/properties.sql']),
|
||||
vid=vid,
|
||||
datlastsysoid=self.datlastsysoid
|
||||
)
|
||||
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
@@ -1459,20 +1460,20 @@ class MViewNode(ViewNode, VacuumSettings):
|
||||
vacuum_table = [item for item in result['vacuum_table']
|
||||
if 'value' in item.keys() and item['value'] is not None]
|
||||
vacuum_toast = [
|
||||
{'name': 'toast.'+item['name'], 'value':item['value']}
|
||||
{'name': 'toast.' + item['name'], 'value': item['value']}
|
||||
for item in result['vacuum_toast'] if 'value' in item.keys() and item['value'] is not None]
|
||||
|
||||
# add vacuum_toast dict to vacuum_data only if
|
||||
# toast's autovacuum is enabled
|
||||
if ('toast_autovacuum_enabled' in result and
|
||||
result['toast_autovacuum_enabled'] is True):
|
||||
result['toast_autovacuum_enabled'] is True):
|
||||
result['vacuum_data'] = vacuum_table + vacuum_toast
|
||||
else:
|
||||
result['vacuum_data'] = vacuum_table
|
||||
|
||||
# Fetch all privileges for view
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'sql/acl.sql']), vid=vid)
|
||||
[self.template_path, 'sql/acl.sql']), vid=vid)
|
||||
status, dataclres = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -1489,14 +1490,14 @@ class MViewNode(ViewNode, VacuumSettings):
|
||||
result['datacl'] = self.parse_privileges(result['datacl'])
|
||||
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'sql/create.sql']),
|
||||
data=result,
|
||||
conn=self.conn,
|
||||
display_comments=True
|
||||
)
|
||||
[self.template_path, 'sql/create.sql']),
|
||||
data=result,
|
||||
conn=self.conn,
|
||||
display_comments=True
|
||||
)
|
||||
SQL += "\n"
|
||||
SQL += render_template("/".join(
|
||||
[self.template_path, 'sql/grant.sql']), data=result)
|
||||
[self.template_path, 'sql/grant.sql']), data=result)
|
||||
|
||||
SQL_data += SQL
|
||||
SQL_data += self.get_rule_sql(vid)
|
||||
@@ -1518,9 +1519,9 @@ class MViewNode(ViewNode, VacuumSettings):
|
||||
|
||||
res = self.get_vacuum_table_settings(self.conn)
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def get_toast_table_vacuum(self, gid, sid, did, scid):
|
||||
@@ -1535,9 +1536,9 @@ class MViewNode(ViewNode, VacuumSettings):
|
||||
res = self.get_vacuum_toast_settings(self.conn)
|
||||
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def properties(self, gid, sid, did, scid, vid):
|
||||
@@ -1547,13 +1548,13 @@ class MViewNode(ViewNode, VacuumSettings):
|
||||
"""
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'sql/properties.sql']
|
||||
), vid=vid, datlastsysoid=self.datlastsysoid)
|
||||
), vid=vid, datlastsysoid=self.datlastsysoid)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'sql/acl.sql']), vid=vid)
|
||||
[self.template_path, 'sql/acl.sql']), vid=vid)
|
||||
status, dataclres = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -1579,9 +1580,9 @@ class MViewNode(ViewNode, VacuumSettings):
|
||||
self.conn, result, 'toast')
|
||||
|
||||
return ajax_response(
|
||||
response=result,
|
||||
status=200
|
||||
)
|
||||
response=result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def refresh_data(self, gid, sid, did, scid, vid):
|
||||
@@ -1600,7 +1601,7 @@ class MViewNode(ViewNode, VacuumSettings):
|
||||
|
||||
# Fetch view name by view id
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'sql/get_view_name.sql']), vid=vid)
|
||||
[self.template_path, 'sql/get_view_name.sql']), vid=vid)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -1608,10 +1609,10 @@ class MViewNode(ViewNode, VacuumSettings):
|
||||
# Refresh view
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'sql/refresh.sql']),
|
||||
name=res['rows'][0]['name'],
|
||||
nspname=res['rows'][0]['schema'],
|
||||
is_concurrent=is_concurrent,
|
||||
with_data=with_data
|
||||
name=res['rows'][0]['name'],
|
||||
nspname=res['rows'][0]['schema'],
|
||||
is_concurrent=is_concurrent,
|
||||
with_data=with_data
|
||||
)
|
||||
status, res_data = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
@@ -1631,5 +1632,6 @@ class MViewNode(ViewNode, VacuumSettings):
|
||||
except Exception as e:
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
|
||||
ViewNode.register_node_view(view_blueprint)
|
||||
MViewNode.register_node_view(mview_blueprint)
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
"""Database helper utilities"""
|
||||
|
||||
|
||||
def parse_sec_labels_from_db(db_sec_labels):
|
||||
"""
|
||||
Function to format the output for security label.
|
||||
@@ -29,7 +30,7 @@ def parse_sec_labels_from_db(db_sec_labels):
|
||||
sec_lbls.append({
|
||||
'provider': sec.group(1),
|
||||
'label': sec.group(2)
|
||||
})
|
||||
})
|
||||
|
||||
return {"seclabels": sec_lbls}
|
||||
|
||||
|
||||
@@ -12,9 +12,9 @@ from pgadmin.browser.server_groups.servers.types import ServerType
|
||||
|
||||
|
||||
class PPAS(ServerType):
|
||||
|
||||
def instanceOf(self, ver):
|
||||
return ver.startswith("EnterpriseDB")
|
||||
|
||||
|
||||
# Default Server Type
|
||||
PPAS('ppas', gettext("EDB Advanced Server"), 2)
|
||||
|
||||
@@ -96,6 +96,7 @@ class ResourceGroupModule(CollectionNodeModule):
|
||||
"""
|
||||
return servers.ServerModule.NODE_TYPE
|
||||
|
||||
|
||||
blueprint = ResourceGroupModule(__name__)
|
||||
|
||||
|
||||
@@ -153,12 +154,12 @@ class ResourceGroupView(NodeView):
|
||||
node_type = blueprint.node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'}
|
||||
]
|
||||
ids = [
|
||||
{'type': 'int', 'id': 'rg_id'}
|
||||
]
|
||||
{'type': 'int', 'id': 'rg_id'}
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [
|
||||
@@ -193,12 +194,12 @@ class ResourceGroupView(NodeView):
|
||||
Override this property for your own logic.
|
||||
"""
|
||||
return make_response(
|
||||
render_template(
|
||||
"resource_groups/js/resource_groups.js",
|
||||
_=gettext
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
render_template(
|
||||
"resource_groups/js/resource_groups.js",
|
||||
_=gettext
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
|
||||
def check_precondition(f):
|
||||
"""
|
||||
@@ -206,6 +207,7 @@ class ResourceGroupView(NodeView):
|
||||
database connection before running view, it will also attaches
|
||||
manager,conn & template_path properties to self
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
# Here args[0] will hold self & kwargs will hold gid,sid,did
|
||||
@@ -218,12 +220,13 @@ class ResourceGroupView(NodeView):
|
||||
if not self.conn.connected():
|
||||
return precondition_required(
|
||||
gettext(
|
||||
"Connection to the server has been lost!"
|
||||
"Connection to the server has been lost!"
|
||||
)
|
||||
)
|
||||
|
||||
self.template_path = 'resource_groups/sql'
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return wrap
|
||||
|
||||
@check_precondition
|
||||
@@ -241,9 +244,9 @@ class ResourceGroupView(NodeView):
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def nodes(self, gid, sid):
|
||||
@@ -263,17 +266,17 @@ class ResourceGroupView(NodeView):
|
||||
|
||||
for row in result['rows']:
|
||||
res.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
sid,
|
||||
row['name'],
|
||||
icon="icon-resource_group"
|
||||
))
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
sid,
|
||||
row['name'],
|
||||
icon="icon-resource_group"
|
||||
))
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def properties(self, gid, sid, rg_id):
|
||||
@@ -292,9 +295,9 @@ class ResourceGroupView(NodeView):
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
return ajax_response(
|
||||
response=res['rows'][0],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'][0],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def create(self, gid, sid):
|
||||
@@ -373,7 +376,7 @@ class ResourceGroupView(NodeView):
|
||||
sql = render_template("/".join([self.template_path, 'properties.sql']), rgid=rg_id)
|
||||
status, res = self.conn.execute_dict(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return internal_server_error(errormsg=res)
|
||||
old_data = res['rows'][0]
|
||||
for arg in required_args:
|
||||
if arg not in data:
|
||||
@@ -466,14 +469,14 @@ class ResourceGroupView(NodeView):
|
||||
sql = self.get_sql(data, rg_id)
|
||||
if sql and sql.strip('\n') and sql.strip(' '):
|
||||
return make_json_response(
|
||||
data=sql,
|
||||
status=200
|
||||
)
|
||||
data=sql,
|
||||
status=200
|
||||
)
|
||||
else:
|
||||
return make_json_response(
|
||||
data='-- Modified SQL --',
|
||||
status=200
|
||||
)
|
||||
data='-- Modified SQL --',
|
||||
status=200
|
||||
)
|
||||
|
||||
def get_sql(self, data, rg_id=None):
|
||||
"""
|
||||
@@ -503,7 +506,7 @@ class ResourceGroupView(NodeView):
|
||||
name_changed = True
|
||||
sql = render_template("/".join([self.template_path, 'update.sql']),
|
||||
oldname=old_data['name'], newname=data['name'], conn=self.conn)
|
||||
if (data['cpu_rate_limit'] != old_data['cpu_rate_limit'])\
|
||||
if (data['cpu_rate_limit'] != old_data['cpu_rate_limit']) \
|
||||
or data['dirty_rate_limit'] != old_data['dirty_rate_limit']:
|
||||
if name_changed:
|
||||
sql += "\n-- Following query will be executed in a separate transaction\n"
|
||||
@@ -544,4 +547,5 @@ class ResourceGroupView(NodeView):
|
||||
|
||||
return ajax_response(response=sql)
|
||||
|
||||
|
||||
ResourceGroupView.register_node_view(blueprint)
|
||||
|
||||
@@ -63,11 +63,11 @@ class RoleModule(CollectionNodeModule):
|
||||
Returns a snippet of css to include in the page
|
||||
"""
|
||||
snippets = [
|
||||
render_template(
|
||||
"browser/css/collection.css",
|
||||
node_type=self.node_type
|
||||
),
|
||||
render_template("role/css/role.css")]
|
||||
render_template(
|
||||
"browser/css/collection.css",
|
||||
node_type=self.node_type
|
||||
),
|
||||
render_template("role/css/role.css")]
|
||||
|
||||
for submodule in self.submodules:
|
||||
snippets.extend(submodule.csssnippets)
|
||||
@@ -82,12 +82,12 @@ class RoleView(PGChildNodeView):
|
||||
node_type = 'role'
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'}
|
||||
]
|
||||
ids = [
|
||||
{'type': 'int', 'id': 'rid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'rid'}
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [
|
||||
@@ -103,7 +103,7 @@ class RoleView(PGChildNodeView):
|
||||
'module.js': [{}, {}, {'get': 'module_js'}],
|
||||
'vopts': [{}, {'get': 'voptions'}],
|
||||
'variables': [{'get': 'variables'}],
|
||||
})
|
||||
})
|
||||
|
||||
def validate_request(f):
|
||||
@wraps(f)
|
||||
@@ -120,11 +120,11 @@ class RoleView(PGChildNodeView):
|
||||
|
||||
val = req[key]
|
||||
if key in [
|
||||
u'rolcanlogin', u'rolsuper', u'rolcreatedb',
|
||||
u'rolcreaterole', u'rolinherit', u'rolreplication',
|
||||
u'rolcatupdate', u'variables', u'rolmembership',
|
||||
u'seclabels'
|
||||
]:
|
||||
u'rolcanlogin', u'rolsuper', u'rolcreatedb',
|
||||
u'rolcreaterole', u'rolinherit', u'rolreplication',
|
||||
u'rolcatupdate', u'variables', u'rolmembership',
|
||||
u'seclabels'
|
||||
]:
|
||||
data[key] = json.loads(val)
|
||||
else:
|
||||
data[key] = val
|
||||
@@ -132,8 +132,8 @@ class RoleView(PGChildNodeView):
|
||||
if u'rid' not in kwargs or kwargs['rid'] == -1:
|
||||
if u'rolname' not in data:
|
||||
return precondition_required(
|
||||
_("Name must be specified.")
|
||||
)
|
||||
_("Name must be specified.")
|
||||
)
|
||||
|
||||
if u'rolvaliduntil' in data:
|
||||
# Make date explicit so that it works with every
|
||||
@@ -149,15 +149,15 @@ class RoleView(PGChildNodeView):
|
||||
except Exception as e:
|
||||
return precondition_required(
|
||||
_("Date format is invalid.")
|
||||
)
|
||||
)
|
||||
|
||||
if u'rolconnlimit' in data:
|
||||
if data[u'rolconnlimit'] is not None:
|
||||
data[u'rolconnlimit'] = int(data[u'rolconnlimit'])
|
||||
if type(data[u'rolconnlimit']) != int or data[u'rolconnlimit'] < -1:
|
||||
return precondition_required(
|
||||
_("Connection limit must be an integer value or equal to -1.")
|
||||
)
|
||||
_("Connection limit must be an integer value or equal to -1.")
|
||||
)
|
||||
|
||||
if u'rolmembership' in data:
|
||||
if u'rid' not in kwargs or kwargs['rid'] == -1:
|
||||
@@ -225,7 +225,7 @@ rolmembership:{
|
||||
|
||||
for r in roles:
|
||||
if (type(r) != dict or u'role' not in r or
|
||||
u'admin' not in r):
|
||||
u'admin' not in r):
|
||||
return precondition_required(msg)
|
||||
|
||||
if r[u'admin']:
|
||||
@@ -245,7 +245,7 @@ rolmembership:{
|
||||
|
||||
data[u'revoked'].append(r[u'role'])
|
||||
|
||||
if u'changed' in data[u'rolmembership']:
|
||||
if u'changed' in data[u'rolmembership']:
|
||||
roles = (data[u'rolmembership'])[u'changed']
|
||||
|
||||
if type(roles) != list:
|
||||
@@ -253,7 +253,7 @@ rolmembership:{
|
||||
|
||||
for r in roles:
|
||||
if (type(r) != dict or u'role' not in r or
|
||||
u'admin' not in r):
|
||||
u'admin' not in r):
|
||||
return precondition_required(msg)
|
||||
|
||||
if not r[u'admin']:
|
||||
@@ -278,7 +278,7 @@ seclabels:[{
|
||||
|
||||
for s in data[u'seclabels']:
|
||||
if (type(s) != dict or u'provider' not in s or
|
||||
u'label' not in s):
|
||||
u'label' not in s):
|
||||
return precondition_required(msg)
|
||||
else:
|
||||
msg = _("""
|
||||
@@ -311,13 +311,12 @@ seclabels:{
|
||||
if u'added' in seclabels:
|
||||
new_seclabels = seclabels[u'added']
|
||||
|
||||
|
||||
if type(new_seclabels) != list:
|
||||
return precondition_required(msg)
|
||||
|
||||
for s in new_seclabels:
|
||||
if (type(s) != dict or u'provider' not in s or
|
||||
u'label' not in s):
|
||||
u'label' not in s):
|
||||
return precondition_required(msg)
|
||||
|
||||
if u'deleted' in seclabels:
|
||||
@@ -338,7 +337,7 @@ seclabels:{
|
||||
|
||||
for s in changed_seclabels:
|
||||
if (type(s) != dict or u'provider' not in s
|
||||
and u'label' not in s):
|
||||
and u'label' not in s):
|
||||
return precondition_required(msg)
|
||||
|
||||
if u'variables' in data:
|
||||
@@ -358,8 +357,8 @@ variables:[{
|
||||
|
||||
for r in data[u'variables']:
|
||||
if (type(r) != dict or
|
||||
u'name' not in r or
|
||||
u'value' not in r):
|
||||
u'name' not in r or
|
||||
u'value' not in r):
|
||||
return precondition_required(msg)
|
||||
else:
|
||||
msg = _("""
|
||||
@@ -400,7 +399,7 @@ rolmembership:{
|
||||
|
||||
for v in new_vars:
|
||||
if (type(v) != dict or u'name' not in v or
|
||||
u'value' not in v):
|
||||
u'value' not in v):
|
||||
return precondition_required(msg)
|
||||
|
||||
if u'deleted' in variables:
|
||||
@@ -413,7 +412,7 @@ rolmembership:{
|
||||
if type(v) != dict or u'name' not in v:
|
||||
return precondition_required(msg)
|
||||
|
||||
if u'changed' in variables:
|
||||
if u'changed' in variables:
|
||||
new_vars = variables[u'changed']
|
||||
|
||||
if type(new_vars) != list:
|
||||
@@ -421,12 +420,13 @@ rolmembership:{
|
||||
|
||||
for v in new_vars:
|
||||
if (type(v) != dict or u'name' not in v or
|
||||
u'value' not in v):
|
||||
u'value' not in v):
|
||||
return precondition_required(msg)
|
||||
|
||||
self.request = data
|
||||
|
||||
return f(self, **kwargs)
|
||||
|
||||
return wrap
|
||||
|
||||
def check_precondition(action=None):
|
||||
@@ -437,14 +437,15 @@ rolmembership:{
|
||||
also attach manager, conn (maintenance connection for the server) as
|
||||
properties of the instance.
|
||||
"""
|
||||
|
||||
def wrap(f):
|
||||
@wraps(f)
|
||||
def wrapped(self, **kwargs):
|
||||
self.manager = get_driver(
|
||||
PG_DEFAULT_DRIVER
|
||||
).connection_manager(
|
||||
kwargs['sid']
|
||||
)
|
||||
PG_DEFAULT_DRIVER
|
||||
).connection_manager(
|
||||
kwargs['sid']
|
||||
)
|
||||
self.conn = self.manager.connection()
|
||||
|
||||
driver = get_driver(PG_DEFAULT_DRIVER)
|
||||
@@ -452,30 +453,30 @@ rolmembership:{
|
||||
|
||||
if not self.conn.connected():
|
||||
return precondition_required(
|
||||
_("Connection to the server has been lost!")
|
||||
)
|
||||
_("Connection to the server has been lost!")
|
||||
)
|
||||
|
||||
ver = self.manager.version
|
||||
|
||||
self.sql_path = 'role/sql/{0}/'.format(
|
||||
'post9_4' if ver >= 90500 else \
|
||||
'post9_1' if ver >= 90200 else \
|
||||
'post9_0' if ver >= 90100 else \
|
||||
'post8_4'
|
||||
)
|
||||
'post9_1' if ver >= 90200 else \
|
||||
'post9_0' if ver >= 90100 else \
|
||||
'post8_4'
|
||||
)
|
||||
|
||||
self.alterKeys = [
|
||||
u'rolcanlogin', u'rolsuper', u'rolcreatedb',
|
||||
u'rolcreaterole', u'rolinherit', u'rolreplication',
|
||||
u'rolconnlimit', u'rolvaliduntil', u'rolpassword'
|
||||
] if ver >= 90200 else [
|
||||
u'rolcanlogin', u'rolsuper', u'rolcreatedb',
|
||||
u'rolcreaterole', u'rolinherit', u'rolconnlimit',
|
||||
u'rolvaliduntil', u'rolpassword'
|
||||
]
|
||||
u'rolcanlogin', u'rolsuper', u'rolcreatedb',
|
||||
u'rolcreaterole', u'rolinherit', u'rolreplication',
|
||||
u'rolconnlimit', u'rolvaliduntil', u'rolpassword'
|
||||
] if ver >= 90200 else [
|
||||
u'rolcanlogin', u'rolsuper', u'rolcreatedb',
|
||||
u'rolcreaterole', u'rolinherit', u'rolconnlimit',
|
||||
u'rolvaliduntil', u'rolpassword'
|
||||
]
|
||||
|
||||
check_permission=False
|
||||
fetch_name=False
|
||||
check_permission = False
|
||||
fetch_name = False
|
||||
forbidden_msg = None
|
||||
|
||||
if action in ['drop', 'update']:
|
||||
@@ -483,19 +484,19 @@ rolmembership:{
|
||||
fetch_name = True
|
||||
if action == 'drop':
|
||||
forbidden_msg = _(
|
||||
"The current user does not have permission to drop the role."
|
||||
)
|
||||
"The current user does not have permission to drop the role."
|
||||
)
|
||||
else:
|
||||
forbidden_msg = _(
|
||||
"The current user does not have permission to update the role."
|
||||
)
|
||||
"The current user does not have permission to update the role."
|
||||
)
|
||||
elif action == 'create':
|
||||
check_permission = True
|
||||
forbidden_msg = _(
|
||||
"The current user does not have permission to create the role."
|
||||
)
|
||||
"The current user does not have permission to create the role."
|
||||
)
|
||||
elif (action == 'msql' and
|
||||
'rid' in kwargs and kwargs['rid'] != -1):
|
||||
'rid' in kwargs and kwargs['rid'] != -1):
|
||||
fetch_name = True
|
||||
|
||||
if check_permission:
|
||||
@@ -504,31 +505,31 @@ rolmembership:{
|
||||
if not user['is_superuser'] and \
|
||||
not user['can_create_role']:
|
||||
if (action != 'update' or
|
||||
'rid' in kwargs and kwargs['rid'] != -1 and
|
||||
user['id'] != kwargs['rid']):
|
||||
'rid' in kwargs and kwargs['rid'] != -1 and
|
||||
user['id'] != kwargs['rid']):
|
||||
return forbidden(forbidden_msg)
|
||||
|
||||
if fetch_name:
|
||||
|
||||
status, res = self.conn.execute_dict(
|
||||
render_template(
|
||||
self.sql_path + 'permission.sql',
|
||||
rid=kwargs['rid'],
|
||||
conn=self.conn
|
||||
)
|
||||
)
|
||||
render_template(
|
||||
self.sql_path + 'permission.sql',
|
||||
rid=kwargs['rid'],
|
||||
conn=self.conn
|
||||
)
|
||||
)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(
|
||||
_(
|
||||
"Error retrieving the role information.\n{0}"
|
||||
).format(res)
|
||||
)
|
||||
_(
|
||||
"Error retrieving the role information.\n{0}"
|
||||
).format(res)
|
||||
)
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return gone(
|
||||
_("Couldn't find the role on the database server.")
|
||||
)
|
||||
_("Couldn't find the role on the database server.")
|
||||
)
|
||||
|
||||
row = res['rows'][0]
|
||||
|
||||
@@ -538,61 +539,63 @@ rolmembership:{
|
||||
self.rolSuper = row['rolsuper']
|
||||
|
||||
return f(self, **kwargs)
|
||||
|
||||
return wrapped
|
||||
|
||||
return wrap
|
||||
|
||||
@check_precondition(action='list')
|
||||
def list(self, gid, sid):
|
||||
status, res = self.conn.execute_dict(
|
||||
render_template(
|
||||
self.sql_path + 'properties.sql'
|
||||
)
|
||||
)
|
||||
render_template(
|
||||
self.sql_path + 'properties.sql'
|
||||
)
|
||||
)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(
|
||||
_(
|
||||
"Error retrieving roles from the database server.\n{0}"
|
||||
).format(res)
|
||||
)
|
||||
_(
|
||||
"Error retrieving roles from the database server.\n{0}"
|
||||
).format(res)
|
||||
)
|
||||
|
||||
self.transform(res)
|
||||
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition(action='nodes')
|
||||
def nodes(self, gid, sid):
|
||||
|
||||
status, rset = self.conn.execute_2darray(
|
||||
render_template(self.sql_path + 'nodes.sql')
|
||||
)
|
||||
)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(
|
||||
_(
|
||||
"Error fetching role information from the database server.\n{0}"
|
||||
).format(rset)
|
||||
)
|
||||
_(
|
||||
"Error fetching role information from the database server.\n{0}"
|
||||
).format(rset)
|
||||
)
|
||||
|
||||
res = []
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'], sid,
|
||||
row['rolname'],
|
||||
'icon-role' if row['rolcanlogin'] else 'icon-group',
|
||||
can_login=row['rolcanlogin'],
|
||||
is_superuser=row['rolsuper']
|
||||
)
|
||||
)
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'], sid,
|
||||
row['rolname'],
|
||||
'icon-role' if row['rolcanlogin'] else 'icon-group',
|
||||
can_login=row['rolcanlogin'],
|
||||
is_superuser=row['rolsuper']
|
||||
)
|
||||
)
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition(action='node')
|
||||
def node(self, gid, sid, rid):
|
||||
@@ -601,27 +604,27 @@ rolmembership:{
|
||||
render_template(
|
||||
self.sql_path + 'nodes.sql',
|
||||
rid=rid
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(
|
||||
_(
|
||||
"Error fetching role information from the database server.\n{0}"
|
||||
).format(rset)
|
||||
)
|
||||
_(
|
||||
"Error fetching role information from the database server.\n{0}"
|
||||
).format(rset)
|
||||
)
|
||||
|
||||
for row in rset['rows']:
|
||||
return make_json_response(
|
||||
data=self.blueprint.generate_browser_node(
|
||||
row['oid'], sid,
|
||||
row['rolname'],
|
||||
'icon-role' if row['rolcanlogin'] else 'icon-group',
|
||||
can_login=row['rolcanlogin'],
|
||||
is_superuser=row['rolsuper']
|
||||
),
|
||||
status=200
|
||||
)
|
||||
data=self.blueprint.generate_browser_node(
|
||||
row['oid'], sid,
|
||||
row['rolname'],
|
||||
'icon-role' if row['rolcanlogin'] else 'icon-group',
|
||||
can_login=row['rolcanlogin'],
|
||||
is_superuser=row['rolsuper']
|
||||
),
|
||||
status=200
|
||||
)
|
||||
|
||||
return gone(_("Could not find the role information."))
|
||||
|
||||
@@ -635,13 +638,13 @@ rolmembership:{
|
||||
res.append({
|
||||
'role': role.group(2),
|
||||
'admin': True if role.group(1) == '1' else False
|
||||
})
|
||||
})
|
||||
row['rolmembership'] = res
|
||||
row['rolvaliduntil'] = row['rolvaliduntil'].isoformat() \
|
||||
if isinstance(
|
||||
row['rolvaliduntil'],
|
||||
(datetime.date, datetime.datetime)
|
||||
) else None
|
||||
if isinstance(
|
||||
row['rolvaliduntil'],
|
||||
(datetime.date, datetime.datetime)
|
||||
) else None
|
||||
if 'seclabels' in row and row['seclabels'] is not None:
|
||||
res = []
|
||||
for sec in row['seclabels']:
|
||||
@@ -649,67 +652,67 @@ rolmembership:{
|
||||
res.append({
|
||||
'provider': sec.group(1),
|
||||
'label': sec.group(2)
|
||||
})
|
||||
})
|
||||
|
||||
@check_precondition(action='properties')
|
||||
def properties(self, gid, sid, rid):
|
||||
|
||||
status, res = self.conn.execute_dict(
|
||||
render_template(
|
||||
self.sql_path + 'properties.sql',
|
||||
rid=rid
|
||||
)
|
||||
)
|
||||
render_template(
|
||||
self.sql_path + 'properties.sql',
|
||||
rid=rid
|
||||
)
|
||||
)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(
|
||||
_(
|
||||
"Error retrieving roles from the database server.\n{0}"
|
||||
).format(res)
|
||||
)
|
||||
_(
|
||||
"Error retrieving roles from the database server.\n{0}"
|
||||
).format(res)
|
||||
)
|
||||
|
||||
self.transform(res)
|
||||
if len(res['rows']) == 0:
|
||||
return gone(_("Could not find the role information."))
|
||||
|
||||
return ajax_response(
|
||||
response=res['rows'][0],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'][0],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition(action='drop')
|
||||
def drop(self, gid, sid, rid):
|
||||
|
||||
status, res = self.conn.execute_2darray(
|
||||
"DROP ROLE {0};".format(self.qtIdent(self.conn, self.role))
|
||||
)
|
||||
"DROP ROLE {0};".format(self.qtIdent(self.conn, self.role))
|
||||
)
|
||||
if not status:
|
||||
return internal_server_error(
|
||||
_("Couldn't drop the role.\n{0}").format(res)
|
||||
)
|
||||
_("Couldn't drop the role.\n{0}").format(res)
|
||||
)
|
||||
|
||||
return success_return()
|
||||
|
||||
@check_precondition()
|
||||
def sql(self, gid, sid, rid):
|
||||
status, res = self.conn.execute_scalar(
|
||||
render_template(
|
||||
self.sql_path + 'sql.sql'
|
||||
),
|
||||
dict({'rid':rid})
|
||||
)
|
||||
render_template(
|
||||
self.sql_path + 'sql.sql'
|
||||
),
|
||||
dict({'rid': rid})
|
||||
)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(
|
||||
_("Could not generate reversed engineered Query for the role.\n{0}").format(
|
||||
res
|
||||
)
|
||||
)
|
||||
_("Could not generate reversed engineered Query for the role.\n{0}").format(
|
||||
res
|
||||
)
|
||||
)
|
||||
|
||||
if res is None:
|
||||
return gone(
|
||||
_("Could not generate reversed engineered Query for the role.")
|
||||
)
|
||||
_("Could not generate reversed engineered Query for the role.")
|
||||
)
|
||||
|
||||
return ajax_response(response=res.strip('\n'))
|
||||
|
||||
@@ -718,51 +721,50 @@ rolmembership:{
|
||||
def create(self, gid, sid):
|
||||
|
||||
sql = render_template(
|
||||
self.sql_path + 'create.sql',
|
||||
data=self.request,
|
||||
dummy=False,
|
||||
conn=self.conn
|
||||
)
|
||||
self.sql_path + 'create.sql',
|
||||
data=self.request,
|
||||
dummy=False,
|
||||
conn=self.conn
|
||||
)
|
||||
|
||||
status, msg = self.conn.execute_dict(sql)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(
|
||||
_("Could not create the role.\n{0}").format(msg)
|
||||
)
|
||||
_("Could not create the role.\n{0}").format(msg)
|
||||
)
|
||||
|
||||
status, rid = self.conn.execute_scalar(
|
||||
"SELECT oid FROM pg_roles WHERE rolname = %(rolname)s",
|
||||
{'rolname': self.request[u'rolname']}
|
||||
)
|
||||
"SELECT oid FROM pg_roles WHERE rolname = %(rolname)s",
|
||||
{'rolname': self.request[u'rolname']}
|
||||
)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(
|
||||
_("Could not retrieve the role information.\n{0}").format(msg)
|
||||
)
|
||||
|
||||
_("Could not retrieve the role information.\n{0}").format(msg)
|
||||
)
|
||||
|
||||
status, rset = self.conn.execute_dict(
|
||||
render_template(self.sql_path + 'nodes.sql',
|
||||
rid=rid
|
||||
)
|
||||
)
|
||||
render_template(self.sql_path + 'nodes.sql',
|
||||
rid=rid
|
||||
)
|
||||
)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(
|
||||
_(
|
||||
"Error fetching role information from the database server.\n{0}"
|
||||
).format(rset)
|
||||
)
|
||||
_(
|
||||
"Error fetching role information from the database server.\n{0}"
|
||||
).format(rset)
|
||||
)
|
||||
for row in rset['rows']:
|
||||
return jsonify(
|
||||
node=self.blueprint.generate_browser_node(
|
||||
rid, sid,
|
||||
row['rolname'],
|
||||
'icon-role' if row['rolcanlogin'] else 'icon-group',
|
||||
can_login=row['rolcanlogin']
|
||||
)
|
||||
)
|
||||
node=self.blueprint.generate_browser_node(
|
||||
rid, sid,
|
||||
row['rolname'],
|
||||
'icon-role' if row['rolcanlogin'] else 'icon-group',
|
||||
can_login=row['rolcanlogin']
|
||||
)
|
||||
)
|
||||
|
||||
return gone(_("Could not find the role information."))
|
||||
|
||||
@@ -771,47 +773,47 @@ rolmembership:{
|
||||
def update(self, gid, sid, rid):
|
||||
|
||||
sql = render_template(
|
||||
self.sql_path + 'update.sql',
|
||||
data=self.request,
|
||||
dummy=False,
|
||||
conn=self.conn,
|
||||
role=self.role,
|
||||
rolCanLogin=self.rolCanLogin,
|
||||
rolCatUpdate=self.rolCatUpdate,
|
||||
rolSuper=self.rolSuper,
|
||||
alterKeys=self.alterKeys
|
||||
)
|
||||
self.sql_path + 'update.sql',
|
||||
data=self.request,
|
||||
dummy=False,
|
||||
conn=self.conn,
|
||||
role=self.role,
|
||||
rolCanLogin=self.rolCanLogin,
|
||||
rolCatUpdate=self.rolCatUpdate,
|
||||
rolSuper=self.rolSuper,
|
||||
alterKeys=self.alterKeys
|
||||
)
|
||||
|
||||
status, msg = self.conn.execute_dict(sql)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(
|
||||
_("Could not create the role.\n{0}").format(msg)
|
||||
)
|
||||
_("Could not create the role.\n{0}").format(msg)
|
||||
)
|
||||
|
||||
status, rset = self.conn.execute_dict(
|
||||
render_template(self.sql_path + 'nodes.sql',
|
||||
rid=rid
|
||||
)
|
||||
)
|
||||
render_template(self.sql_path + 'nodes.sql',
|
||||
rid=rid
|
||||
)
|
||||
)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(
|
||||
_(
|
||||
"Error fetching role information from the database server.\n{0}"
|
||||
).format(rset)
|
||||
)
|
||||
_(
|
||||
"Error fetching role information from the database server.\n{0}"
|
||||
).format(rset)
|
||||
)
|
||||
|
||||
for row in rset['rows']:
|
||||
return jsonify(
|
||||
node=self.blueprint.generate_browser_node(
|
||||
rid, sid,
|
||||
row['rolname'],
|
||||
'icon-role' if row['rolcanlogin'] else 'icon-group',
|
||||
can_login=row['rolcanlogin'],
|
||||
is_superuser=row['rolsuper']
|
||||
)
|
||||
)
|
||||
node=self.blueprint.generate_browser_node(
|
||||
rid, sid,
|
||||
row['rolname'],
|
||||
'icon-role' if row['rolcanlogin'] else 'icon-group',
|
||||
can_login=row['rolcanlogin'],
|
||||
is_superuser=row['rolsuper']
|
||||
)
|
||||
)
|
||||
|
||||
return gone(_("Could not find the role information."))
|
||||
|
||||
@@ -820,27 +822,27 @@ rolmembership:{
|
||||
def msql(self, gid, sid, rid=-1):
|
||||
if rid == -1:
|
||||
return make_json_response(
|
||||
data=render_template(
|
||||
self.sql_path + 'create.sql',
|
||||
data=self.request,
|
||||
dummy=True,
|
||||
conn=self.conn
|
||||
).strip('\n')
|
||||
)
|
||||
data=render_template(
|
||||
self.sql_path + 'create.sql',
|
||||
data=self.request,
|
||||
dummy=True,
|
||||
conn=self.conn
|
||||
).strip('\n')
|
||||
)
|
||||
else:
|
||||
return make_json_response(
|
||||
data=render_template(
|
||||
self.sql_path + 'update.sql',
|
||||
data=self.request,
|
||||
dummy=True,
|
||||
conn=self.conn,
|
||||
role=self.role,
|
||||
rolCanLogin=self.rolCanLogin,
|
||||
rolCatUpdate=self.rolCatUpdate,
|
||||
rolSuper=self.rolSuper,
|
||||
alterKeys=self.alterKeys
|
||||
).strip('\n')
|
||||
)
|
||||
data=render_template(
|
||||
self.sql_path + 'update.sql',
|
||||
data=self.request,
|
||||
dummy=True,
|
||||
conn=self.conn,
|
||||
role=self.role,
|
||||
rolCanLogin=self.rolCanLogin,
|
||||
rolCatUpdate=self.rolCatUpdate,
|
||||
rolSuper=self.rolSuper,
|
||||
alterKeys=self.alterKeys
|
||||
).strip('\n')
|
||||
)
|
||||
|
||||
@check_precondition()
|
||||
def dependencies(self, gid, sid, rid):
|
||||
@@ -855,9 +857,9 @@ rolmembership:{
|
||||
"""
|
||||
dependencies_result = self.get_dependencies(self.conn, rid)
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition()
|
||||
def dependents(self, gid, sid, rid):
|
||||
@@ -872,9 +874,9 @@ rolmembership:{
|
||||
"""
|
||||
dependents_result = self.get_dependents(self.conn, sid, rid)
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
def get_dependents(self, conn, sid, rid):
|
||||
"""
|
||||
@@ -992,52 +994,52 @@ rolmembership:{
|
||||
def variables(self, gid, sid, rid):
|
||||
|
||||
status, rset = self.conn.execute_dict(
|
||||
render_template(self.sql_path + 'variables.sql',
|
||||
rid=rid
|
||||
)
|
||||
)
|
||||
render_template(self.sql_path + 'variables.sql',
|
||||
rid=rid
|
||||
)
|
||||
)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(
|
||||
_(
|
||||
"Error retrieving variable information for the role.\n{0}"
|
||||
).format(rset)
|
||||
)
|
||||
_(
|
||||
"Error retrieving variable information for the role.\n{0}"
|
||||
).format(rset)
|
||||
)
|
||||
|
||||
return make_json_response(
|
||||
data=rset['rows']
|
||||
)
|
||||
data=rset['rows']
|
||||
)
|
||||
|
||||
@check_precondition()
|
||||
def voptions(self, gid, sid):
|
||||
|
||||
status, res = self.conn.execute_dict(
|
||||
"""
|
||||
"""
|
||||
SELECT
|
||||
name, vartype, min_val, max_val, enumvals
|
||||
name, vartype, min_val, max_val, enumvals
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
'role'::text AS name, 'string'::text AS vartype,
|
||||
NULL AS min_val, NULL AS max_val, NULL::text[] AS enumvals
|
||||
UNION ALL
|
||||
SELECT
|
||||
name, vartype, min_val::numeric AS min_val, max_val::numeric AS max_val, enumvals
|
||||
FROM
|
||||
pg_settings
|
||||
WHERE
|
||||
context in ('user', 'superuser')
|
||||
) a""")
|
||||
(
|
||||
SELECT
|
||||
'role'::text AS name, 'string'::text AS vartype,
|
||||
NULL AS min_val, NULL AS max_val, NULL::text[] AS enumvals
|
||||
UNION ALL
|
||||
SELECT
|
||||
name, vartype, min_val::numeric AS min_val, max_val::numeric AS max_val, enumvals
|
||||
FROM
|
||||
pg_settings
|
||||
WHERE
|
||||
context in ('user', 'superuser')
|
||||
) a""")
|
||||
|
||||
if not status:
|
||||
return internal_server_error(
|
||||
_(
|
||||
"Error retrieving the variable options for the role.\n{0}"
|
||||
).format(res)
|
||||
)
|
||||
_(
|
||||
"Error retrieving the variable options for the role.\n{0}"
|
||||
).format(res)
|
||||
)
|
||||
return make_json_response(
|
||||
data=res['rows']
|
||||
)
|
||||
data=res['rows']
|
||||
)
|
||||
|
||||
|
||||
RoleView.register_node_view(blueprint)
|
||||
|
||||
@@ -55,12 +55,12 @@ class TablespaceView(PGChildNodeView):
|
||||
node_type = blueprint.node_type
|
||||
|
||||
parent_ids = [
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'gid'},
|
||||
{'type': 'int', 'id': 'sid'}
|
||||
]
|
||||
ids = [
|
||||
{'type': 'int', 'id': 'tsid'}
|
||||
]
|
||||
{'type': 'int', 'id': 'tsid'}
|
||||
]
|
||||
|
||||
operations = dict({
|
||||
'obj': [
|
||||
@@ -86,12 +86,12 @@ class TablespaceView(PGChildNodeView):
|
||||
Override this property for your own logic.
|
||||
"""
|
||||
return make_response(
|
||||
render_template(
|
||||
"tablespaces/js/tablespaces.js",
|
||||
_=gettext
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
render_template(
|
||||
"tablespaces/js/tablespaces.js",
|
||||
_=gettext
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
|
||||
def check_precondition(f):
|
||||
"""
|
||||
@@ -99,6 +99,7 @@ class TablespaceView(PGChildNodeView):
|
||||
database connection before running view, it will also attaches
|
||||
manager,conn & template_path properties to self
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
def wrap(*args, **kwargs):
|
||||
# Here args[0] will hold self & kwargs will hold gid,sid,tsid
|
||||
@@ -110,11 +111,11 @@ class TablespaceView(PGChildNodeView):
|
||||
if not self.conn.connected():
|
||||
current_app.logger.warning(
|
||||
"Connection to the server has been lost!"
|
||||
)
|
||||
)
|
||||
return precondition_required(
|
||||
gettext(
|
||||
"Connection to the server has been lost!"
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
ver = self.manager.version
|
||||
@@ -124,11 +125,12 @@ class TablespaceView(PGChildNodeView):
|
||||
self.template_path = 'tablespaces/sql/9.1_plus'
|
||||
current_app.logger.debug(
|
||||
"Using the template path: %s", self.template_path
|
||||
)
|
||||
)
|
||||
# Allowed ACL on tablespace
|
||||
self.acl = ['C']
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return wrap
|
||||
|
||||
@check_precondition
|
||||
@@ -136,15 +138,15 @@ class TablespaceView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'properties.sql']),
|
||||
conn=self.conn
|
||||
)
|
||||
)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return ajax_response(
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
response=res['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def nodes(self, gid, sid, tsid=None):
|
||||
@@ -152,24 +154,24 @@ class TablespaceView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'nodes.sql']),
|
||||
tsid=tsid, conn=self.conn
|
||||
)
|
||||
)
|
||||
status, rset = self.conn.execute_2darray(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=rset)
|
||||
|
||||
for row in rset['rows']:
|
||||
res.append(
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
sid,
|
||||
row['name'],
|
||||
icon="icon-tablespace"
|
||||
))
|
||||
self.blueprint.generate_browser_node(
|
||||
row['oid'],
|
||||
sid,
|
||||
row['name'],
|
||||
icon="icon-tablespace"
|
||||
))
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
data=res,
|
||||
status=200
|
||||
)
|
||||
|
||||
def _formatter(self, data, tsid=None):
|
||||
"""
|
||||
@@ -202,7 +204,7 @@ class TablespaceView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'acl.sql']),
|
||||
tsid=tsid, conn=self.conn
|
||||
)
|
||||
)
|
||||
status, acl = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=acl)
|
||||
@@ -225,7 +227,7 @@ class TablespaceView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'properties.sql']),
|
||||
tsid=tsid, conn=self.conn
|
||||
)
|
||||
)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -235,9 +237,9 @@ class TablespaceView(PGChildNodeView):
|
||||
copy_data = self._formatter(copy_data, tsid)
|
||||
|
||||
return ajax_response(
|
||||
response=copy_data,
|
||||
status=200
|
||||
)
|
||||
response=copy_data,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def create(self, gid, sid):
|
||||
@@ -271,7 +273,7 @@ class TablespaceView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'create.sql']),
|
||||
data=data, conn=self.conn
|
||||
)
|
||||
)
|
||||
|
||||
status, res = self.conn.execute_scalar(SQL)
|
||||
|
||||
@@ -280,7 +282,7 @@ class TablespaceView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'alter.sql']),
|
||||
data=data, conn=self.conn
|
||||
)
|
||||
)
|
||||
|
||||
# Checking if we are not executing empty query
|
||||
if SQL and SQL.strip('\n') and SQL.strip(' '):
|
||||
@@ -292,7 +294,7 @@ class TablespaceView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'alter.sql']),
|
||||
tablespace=data['name'], conn=self.conn
|
||||
)
|
||||
)
|
||||
|
||||
status, tsid = self.conn.execute_scalar(SQL)
|
||||
|
||||
@@ -360,8 +362,8 @@ class TablespaceView(PGChildNodeView):
|
||||
render_template(
|
||||
"/".join([self.template_path, 'nodes.sql']),
|
||||
tsid=tsid, conn=self.conn
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(errormsg=rset)
|
||||
@@ -369,13 +371,13 @@ class TablespaceView(PGChildNodeView):
|
||||
if len(rset['rows']) != 1:
|
||||
return gone(
|
||||
errormsg=gettext("Could not find the tablespace on the server.")
|
||||
)
|
||||
)
|
||||
|
||||
# drop tablespace
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'delete.sql']),
|
||||
tsname=(rset['rows'][0])['name'], conn=self.conn
|
||||
)
|
||||
)
|
||||
|
||||
status, res = self.conn.execute_scalar(SQL)
|
||||
if not status:
|
||||
@@ -388,8 +390,8 @@ class TablespaceView(PGChildNodeView):
|
||||
'id': tsid,
|
||||
'sid': sid,
|
||||
'gid': gid,
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
current_app.logger.exception(e)
|
||||
@@ -431,7 +433,7 @@ class TablespaceView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'properties.sql']),
|
||||
tsid=tsid, conn=self.conn
|
||||
)
|
||||
)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -444,11 +446,11 @@ class TablespaceView(PGChildNodeView):
|
||||
for key in ['spcacl']:
|
||||
if key in data and data[key] is not None:
|
||||
if 'added' in data[key]:
|
||||
data[key]['added'] = parse_priv_to_db(data[key]['added'], self.acl)
|
||||
data[key]['added'] = parse_priv_to_db(data[key]['added'], self.acl)
|
||||
if 'changed' in data[key]:
|
||||
data[key]['changed'] = parse_priv_to_db(data[key]['changed'], self.acl)
|
||||
data[key]['changed'] = parse_priv_to_db(data[key]['changed'], self.acl)
|
||||
if 'deleted' in data[key]:
|
||||
data[key]['deleted'] = parse_priv_to_db(data[key]['deleted'], self.acl)
|
||||
data[key]['deleted'] = parse_priv_to_db(data[key]['deleted'], self.acl)
|
||||
|
||||
# If name is not present with in update data then copy it
|
||||
# from old data
|
||||
@@ -459,7 +461,7 @@ class TablespaceView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'update.sql']),
|
||||
data=data, o_data=old_data
|
||||
)
|
||||
)
|
||||
else:
|
||||
# To format privileges coming from client
|
||||
if 'spcacl' in data:
|
||||
@@ -468,12 +470,12 @@ class TablespaceView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'create.sql']),
|
||||
data=data
|
||||
)
|
||||
)
|
||||
SQL += "\n"
|
||||
SQL += render_template(
|
||||
"/".join([self.template_path, 'alter.sql']),
|
||||
data=data, conn=self.conn
|
||||
)
|
||||
)
|
||||
SQL = re.sub('\n{2,}', '\n\n', SQL)
|
||||
return SQL
|
||||
|
||||
@@ -485,7 +487,7 @@ class TablespaceView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'properties.sql']),
|
||||
tsid=tsid, conn=self.conn
|
||||
)
|
||||
)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -505,12 +507,12 @@ class TablespaceView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'create.sql']),
|
||||
data=old_data
|
||||
)
|
||||
)
|
||||
SQL += "\n"
|
||||
SQL += render_template(
|
||||
"/".join([self.template_path, 'alter.sql']),
|
||||
data=old_data, conn=self.conn
|
||||
)
|
||||
)
|
||||
|
||||
sql_header = """
|
||||
-- Tablespace: {0}
|
||||
@@ -523,7 +525,6 @@ class TablespaceView(PGChildNodeView):
|
||||
SQL = re.sub('\n{2,}', '\n\n', SQL)
|
||||
return ajax_response(response=SQL.strip('\n'))
|
||||
|
||||
|
||||
@check_precondition
|
||||
def variable_options(self, gid, sid):
|
||||
"""
|
||||
@@ -537,16 +538,16 @@ class TablespaceView(PGChildNodeView):
|
||||
"""
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'variables.sql'])
|
||||
)
|
||||
)
|
||||
status, rset = self.conn.execute_dict(SQL)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(errormsg=rset)
|
||||
|
||||
return make_json_response(
|
||||
data=rset['rows'],
|
||||
status=200
|
||||
)
|
||||
data=rset['rows'],
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def statistics(self, gid, sid, tsid=None):
|
||||
@@ -556,7 +557,7 @@ class TablespaceView(PGChildNodeView):
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'stats.sql']),
|
||||
tsid=tsid, conn=self.conn
|
||||
)
|
||||
)
|
||||
status, res = self.conn.execute_scalar(SQL)
|
||||
|
||||
if not status:
|
||||
@@ -581,9 +582,9 @@ class TablespaceView(PGChildNodeView):
|
||||
"""
|
||||
dependencies_result = self.get_dependencies(self.conn, tsid)
|
||||
return ajax_response(
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
response=dependencies_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def dependents(self, gid, sid, tsid):
|
||||
@@ -598,9 +599,9 @@ class TablespaceView(PGChildNodeView):
|
||||
"""
|
||||
dependents_result = self.get_dependents(self.conn, sid, tsid)
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
response=dependents_result,
|
||||
status=200
|
||||
)
|
||||
|
||||
def get_dependents(self, conn, sid, tsid):
|
||||
"""
|
||||
@@ -648,7 +649,7 @@ class TablespaceView(PGChildNodeView):
|
||||
if tsid == oid:
|
||||
dependents.append({
|
||||
'type': 'database', 'name': '', 'field': db_row['datname']
|
||||
})
|
||||
})
|
||||
|
||||
# If connection to the database is not allowed then continue
|
||||
# with the next database
|
||||
@@ -780,7 +781,9 @@ class TablespaceView(PGChildNodeView):
|
||||
)
|
||||
|
||||
return make_json_response(
|
||||
data=sql.strip('\n'),
|
||||
status=200
|
||||
)
|
||||
data=sql.strip('\n'),
|
||||
status=200
|
||||
)
|
||||
|
||||
|
||||
TablespaceView.register_node_view(blueprint)
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
<div>{% if errmsg %}
|
||||
<div class="highlight has-error">
|
||||
<div class='control-label'>{{ errmsg }}</div>
|
||||
</div>{% endif %}
|
||||
<div><b>{{ _('Please enter the password for the user \'{0}\' to connect the server - "{1}"').format(username, server_label) }}</b></div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div><b>{{ _('Please enter the password for the user \'{0}\' to connect the server - "{1}"').format(username,
|
||||
server_label) }}</b></div>
|
||||
<div style="padding: 5px; height: 1px;"></div>
|
||||
<div style="width: 100%">
|
||||
<span style="width: 25%;display: inline-table;">Password</span>
|
||||
|
||||
@@ -31,7 +31,7 @@ class ServerType(object):
|
||||
self.spriority = priority
|
||||
self.utility_path = None
|
||||
|
||||
assert(server_type not in ServerType.registry)
|
||||
assert (server_type not in ServerType.registry)
|
||||
ServerType.registry[server_type] = self
|
||||
|
||||
@property
|
||||
@@ -66,8 +66,8 @@ class ServerType(object):
|
||||
|
||||
def __str__(self):
|
||||
return "Type: {0}, Description:{1}, Priority: {2}".format(
|
||||
self.stype, self.desc, self.spriority
|
||||
)
|
||||
self.stype, self.desc, self.spriority
|
||||
)
|
||||
|
||||
def instanceOf(self, version):
|
||||
return True
|
||||
@@ -78,19 +78,19 @@ class ServerType(object):
|
||||
Returns a snippet of css to include in the page
|
||||
"""
|
||||
return [
|
||||
render_template(
|
||||
"css/server_type.css",
|
||||
server_type=self.stype
|
||||
)
|
||||
]
|
||||
render_template(
|
||||
"css/server_type.css",
|
||||
server_type=self.stype
|
||||
)
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def types(cls):
|
||||
return sorted(
|
||||
ServerType.registry.values(),
|
||||
key=lambda x: x.priority,
|
||||
reverse=True
|
||||
)
|
||||
ServerType.registry.values(),
|
||||
key=lambda x: x.priority,
|
||||
reverse=True
|
||||
)
|
||||
|
||||
def utility(self, operation, sverion):
|
||||
res = None
|
||||
|
||||
@@ -17,8 +17,8 @@ def parse_priv_from_db(db_privileges):
|
||||
acl = {
|
||||
'grantor': db_privileges['grantor'],
|
||||
'grantee': db_privileges['grantee'],
|
||||
'privileges':[]
|
||||
}
|
||||
'privileges': []
|
||||
}
|
||||
|
||||
privileges = []
|
||||
for idx, priv in enumerate(db_privileges['privileges']):
|
||||
@@ -26,14 +26,14 @@ def parse_priv_from_db(db_privileges):
|
||||
"privilege_type": priv,
|
||||
"privilege": True,
|
||||
"with_grant": db_privileges['grantable'][idx]
|
||||
})
|
||||
})
|
||||
|
||||
acl['privileges'] = privileges
|
||||
|
||||
return acl
|
||||
|
||||
|
||||
def parse_priv_to_db(str_privileges, allowed_acls = []):
|
||||
def parse_priv_to_db(str_privileges, allowed_acls=[]):
|
||||
"""
|
||||
Common utility function to parse privileges before sending to database.
|
||||
"""
|
||||
@@ -50,7 +50,7 @@ def parse_priv_to_db(str_privileges, allowed_acls = []):
|
||||
't': 'TRIGGER',
|
||||
'U': 'USAGE',
|
||||
'X': 'EXECUTE'
|
||||
}
|
||||
}
|
||||
|
||||
privileges = []
|
||||
allowed_acls_len = len(allowed_acls)
|
||||
@@ -69,12 +69,12 @@ def parse_priv_to_db(str_privileges, allowed_acls = []):
|
||||
|
||||
if privilege['with_grant']:
|
||||
priv_with_grant.append(
|
||||
db_privileges[privilege['privilege_type']]
|
||||
)
|
||||
db_privileges[privilege['privilege_type']]
|
||||
)
|
||||
elif privilege['privilege']:
|
||||
priv_without_grant.append(
|
||||
db_privileges[privilege['privilege_type']]
|
||||
)
|
||||
db_privileges[privilege['privilege_type']]
|
||||
)
|
||||
# If we have all acl then just return all
|
||||
if len(priv_with_grant) == allowed_acls_len:
|
||||
priv_with_grant = ['ALL']
|
||||
@@ -85,6 +85,6 @@ def parse_priv_to_db(str_privileges, allowed_acls = []):
|
||||
'grantee': priv['grantee'],
|
||||
'with_grant': priv_with_grant,
|
||||
'without_grant': priv_without_grant
|
||||
})
|
||||
})
|
||||
|
||||
return privileges
|
||||
|
||||
@@ -2,84 +2,92 @@
|
||||
{% block title %}{{ config.APP_NAME }}{% endblock %}
|
||||
{% block init_script %}
|
||||
try {
|
||||
require(
|
||||
['pgadmin', 'pgadmin.browser'],
|
||||
function(pgAdmin, pgBrowser) {
|
||||
pgBrowser.init();
|
||||
},
|
||||
function() {
|
||||
/* TODO:: Show proper error dialog */
|
||||
console.log(arguments);
|
||||
});
|
||||
require(
|
||||
['pgadmin', 'pgadmin.browser'],
|
||||
function(pgAdmin, pgBrowser) {
|
||||
pgBrowser.init();
|
||||
},
|
||||
function() {
|
||||
/* TODO:: Show proper error dialog */
|
||||
console.log(arguments);
|
||||
});
|
||||
} catch (err) {
|
||||
/* Show proper error dialog */
|
||||
console.log(err);
|
||||
/* Show proper error dialog */
|
||||
console.log(err);
|
||||
}
|
||||
{% endblock %}
|
||||
{% block body %}
|
||||
<nav class="navbar-inverse navbar-fixed-top">
|
||||
<div class="container-fluid">
|
||||
<div class="navbar-header">
|
||||
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-menu">
|
||||
<span class="sr-only">{{ _('Toggle navigation') }}</span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="#">
|
||||
<i class="app-icon {{ config.APP_ICON }}"></i>
|
||||
<span> {{ config.APP_NAME }}</span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="container-fluid">
|
||||
<div class="navbar-header">
|
||||
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-menu">
|
||||
<span class="sr-only">{{ _('Toggle navigation') }}</span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="#">
|
||||
<i class="app-icon {{ config.APP_ICON }}"></i>
|
||||
<span> {{ config.APP_NAME }}</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbar-menu">
|
||||
<div class="collapse navbar-collapse" id="navbar-menu">
|
||||
|
||||
<ul class="nav navbar-nav">
|
||||
<ul class="nav navbar-nav">
|
||||
|
||||
<li id="mnu_file" class="dropdown hide">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{{ _('File') }} <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu navbar-inverse" role="menu"></ul>
|
||||
</li>
|
||||
<li id="mnu_edit" class="dropdown hide">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{{ _('Edit') }} <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu navbar-inverse" role="menu"></ul>
|
||||
</li>
|
||||
<li id="mnu_obj" class="dropdown ">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{{ _('Object') }} <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu navbar-inverse" role="menu"></ul>
|
||||
</li>
|
||||
<li id="mnu_management" class="dropdown hide">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{{ _('Management') }} <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu navbar-inverse" role="menu"></ul>
|
||||
</li>
|
||||
<li id="mnu_tools" class="dropdown hide">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{{ _('Tools') }} <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu navbar-inverse" role="menu"></ul>
|
||||
</li>
|
||||
<li id="mnu_help" class="dropdown hide">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{{ _('Help') }} <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu navbar-inverse" role="menu"></ul>
|
||||
</li>
|
||||
</ul>
|
||||
{% if config.SERVER_MODE %}
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><img src="{{ username | gravatar }}" width="18" height="18" alt="Gravatar image for {{ username }}"> {{ username }} <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu navbar-inverse">
|
||||
<li><a href="{{ url_for('security.change_password') }}">{{ _('Change Password') }}</a></li>
|
||||
<li class="divider"></li>
|
||||
{% if is_admin %}
|
||||
<li><a href="#" onclick="pgAdmin.Browser.UserManagement.show_users()">{{ _('Users') }}</a></li>
|
||||
<li class="divider"></li>
|
||||
<li id="mnu_file" class="dropdown hide">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{{
|
||||
_('File') }} <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu navbar-inverse" role="menu"></ul>
|
||||
</li>
|
||||
<li id="mnu_edit" class="dropdown hide">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{{
|
||||
_('Edit') }} <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu navbar-inverse" role="menu"></ul>
|
||||
</li>
|
||||
<li id="mnu_obj" class="dropdown ">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{{
|
||||
_('Object') }} <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu navbar-inverse" role="menu"></ul>
|
||||
</li>
|
||||
<li id="mnu_management" class="dropdown hide">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{{
|
||||
_('Management') }} <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu navbar-inverse" role="menu"></ul>
|
||||
</li>
|
||||
<li id="mnu_tools" class="dropdown hide">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{{
|
||||
_('Tools') }} <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu navbar-inverse" role="menu"></ul>
|
||||
</li>
|
||||
<li id="mnu_help" class="dropdown hide">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{{
|
||||
_('Help') }} <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu navbar-inverse" role="menu"></ul>
|
||||
</li>
|
||||
</ul>
|
||||
{% if config.SERVER_MODE %}
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><img
|
||||
src="{{ username | gravatar }}" width="18" height="18"
|
||||
alt="Gravatar image for {{ username }}"> {{ username }} <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu navbar-inverse">
|
||||
<li><a href="{{ url_for('security.change_password') }}">{{ _('Change Password') }}</a></li>
|
||||
<li class="divider"></li>
|
||||
{% if is_admin %}
|
||||
<li><a href="#" onclick="pgAdmin.Browser.UserManagement.show_users()">{{ _('Users') }}</a></li>
|
||||
<li class="divider"></li>
|
||||
{% endif %}
|
||||
<li><a href="{{ url_for('security.logout') }}">{{ _('Logout') }}</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
{% endif %}
|
||||
<li><a href="{{ url_for('security.logout') }}">{{ _('Logout') }}</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div id="dockerContainer" style="position:absolute;left:0px;right:0px;top:50px;bottom:0px;"></div>
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
{%- with messages = get_flashed_messages(with_categories=true) -%}
|
||||
{% if messages %}
|
||||
<div style="position: fixed; top: 70px; right: 20px; width: 400px; z-index: 9999">
|
||||
{% for category, message in messages %}
|
||||
<div class="alert alert-{{ category }} alert-dismissible" role="alert">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
{% if messages %}
|
||||
<div style="position: fixed; top: 70px; right: 20px; width: 400px; z-index: 9999">
|
||||
{% for category, message in messages %}
|
||||
<div class="alert alert-{{ category }} alert-dismissible" role="alert">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span
|
||||
aria-hidden="true">×</span></button>
|
||||
{{ message|safe }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{%- endwith %}
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
<p>{{ _('You are currently running version {0} of {1}, however the current version is {2}.').format(current_version, product_name, upgrade_version) }}</p>
|
||||
<p>{{ _('Please click <a class="alert-link" href="{0}" target="_new">here</a> for more information.').format(download_url) }}</p>
|
||||
<p>{{ _('You are currently running version {0} of {1}, however the current version is {2}.').format(current_version,
|
||||
product_name, upgrade_version) }}</p>
|
||||
<p>{{ _('Please click <a class="alert-link" href="{0}" target="_new">here</a> for more
|
||||
information.').format(download_url) }}</p>
|
||||
@@ -12,6 +12,7 @@ import uuid
|
||||
from pgadmin.utils.route import BaseTestGenerator
|
||||
from regression.config import config_data
|
||||
|
||||
|
||||
class ResetPasswordTestCase(BaseTestGenerator):
|
||||
"""
|
||||
This class validates the reset password functionality by defining
|
||||
|
||||
@@ -54,9 +54,9 @@ class PGChildModule(object):
|
||||
if (self.min_ver is None and self.max_ver is None):
|
||||
return True
|
||||
|
||||
assert(self.max_ver is None or isinstance(self.max_ver, int))
|
||||
assert(self.min_ver is None or isinstance(self.min_ver, int))
|
||||
assert(self.server_type is None or isinstance(self.server_type, list))
|
||||
assert (self.max_ver is None or isinstance(self.max_ver, int))
|
||||
assert (self.min_ver is None or isinstance(self.min_ver, int))
|
||||
assert (self.server_type is None or isinstance(self.server_type, list))
|
||||
|
||||
if self.server_type is None or manager.server_type in self.server_type:
|
||||
if self.min_ver is None or self.min_ver <= sversion:
|
||||
@@ -144,7 +144,7 @@ class NodeView(with_metaclass(MethodViewType, View)):
|
||||
cmds.append({
|
||||
'cmd': op, 'req': (idx == 0),
|
||||
'with_id': (idx != 2), 'methods': meths
|
||||
})
|
||||
})
|
||||
idx += 1
|
||||
return cmds
|
||||
|
||||
@@ -196,29 +196,29 @@ class NodeView(with_metaclass(MethodViewType, View)):
|
||||
meth = 'get'
|
||||
|
||||
assert self.cmd in self.operations, \
|
||||
"Unimplemented command ({0}) for {1}".format(
|
||||
self.cmd,
|
||||
str(self.__class__.__name__)
|
||||
)
|
||||
"Unimplemented command ({0}) for {1}".format(
|
||||
self.cmd,
|
||||
str(self.__class__.__name__)
|
||||
)
|
||||
|
||||
has_args, has_id = self.check_args(**kwargs)
|
||||
|
||||
assert (self.cmd in self.operations and
|
||||
(has_id and len(self.operations[self.cmd]) > 0 and
|
||||
meth in self.operations[self.cmd][0]) or
|
||||
meth in self.operations[self.cmd][0]) or
|
||||
(not has_id and len(self.operations[self.cmd]) > 1 and
|
||||
meth in self.operations[self.cmd][1]) or
|
||||
meth in self.operations[self.cmd][1]) or
|
||||
(len(self.operations[self.cmd]) > 2 and
|
||||
meth in self.operations[self.cmd][2])), \
|
||||
"Unimplemented method ({0}) for command ({1}), which {2} an id".format(
|
||||
meth, self.cmd,
|
||||
'requires' if has_id else 'does not require'
|
||||
)
|
||||
meth in self.operations[self.cmd][2])), \
|
||||
"Unimplemented method ({0}) for command ({1}), which {2} an id".format(
|
||||
meth, self.cmd,
|
||||
'requires' if has_id else 'does not require'
|
||||
)
|
||||
|
||||
meth = self.operations[self.cmd][0][meth] if has_id else \
|
||||
self.operations[self.cmd][1][meth] if has_args and \
|
||||
meth in self.operations[self.cmd][1] else \
|
||||
self.operations[self.cmd][2][meth]
|
||||
meth in self.operations[self.cmd][1] else \
|
||||
self.operations[self.cmd][2][meth]
|
||||
|
||||
method = getattr(self, meth, None)
|
||||
|
||||
@@ -244,25 +244,25 @@ class NodeView(with_metaclass(MethodViewType, View)):
|
||||
for c in commands:
|
||||
if c['with_id']:
|
||||
blueprint.add_url_rule(
|
||||
'/{0}{1}'.format(
|
||||
c['cmd'], id_url if c['req'] else url
|
||||
),
|
||||
view_func=cls.as_view(
|
||||
'{0}{1}'.format(
|
||||
c['cmd'], '_id' if c['req'] else ''
|
||||
),
|
||||
cmd=c['cmd']
|
||||
),
|
||||
methods=c['methods']
|
||||
)
|
||||
'/{0}{1}'.format(
|
||||
c['cmd'], id_url if c['req'] else url
|
||||
),
|
||||
view_func=cls.as_view(
|
||||
'{0}{1}'.format(
|
||||
c['cmd'], '_id' if c['req'] else ''
|
||||
),
|
||||
cmd=c['cmd']
|
||||
),
|
||||
methods=c['methods']
|
||||
)
|
||||
else:
|
||||
blueprint.add_url_rule(
|
||||
'/{0}'.format(c['cmd']),
|
||||
view_func=cls.as_view(
|
||||
'{0}'.format(c['cmd']), cmd=c['cmd']
|
||||
),
|
||||
methods=c['methods']
|
||||
)
|
||||
'/{0}'.format(c['cmd']),
|
||||
view_func=cls.as_view(
|
||||
'{0}'.format(c['cmd']), cmd=c['cmd']
|
||||
),
|
||||
methods=c['methods']
|
||||
)
|
||||
|
||||
def module_js(self, **kwargs):
|
||||
"""
|
||||
@@ -270,11 +270,11 @@ class NodeView(with_metaclass(MethodViewType, View)):
|
||||
Override this property for your own logic.
|
||||
"""
|
||||
return flask.make_response(
|
||||
flask.render_template(
|
||||
"{0}/js/{0}.js".format(self.node_type)
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
flask.render_template(
|
||||
"{0}/js/{0}.js".format(self.node_type)
|
||||
),
|
||||
200, {'Content-Type': 'application/x-javascript'}
|
||||
)
|
||||
|
||||
def children(self, *args, **kwargs):
|
||||
"""Build a list of treeview nodes from the child nodes."""
|
||||
@@ -291,7 +291,6 @@ class NodeView(with_metaclass(MethodViewType, View)):
|
||||
|
||||
|
||||
class PGChildNodeView(NodeView):
|
||||
|
||||
def children(self, **kwargs):
|
||||
"""Build a list of treeview nodes from the child nodes."""
|
||||
|
||||
@@ -302,8 +301,8 @@ class PGChildNodeView(NodeView):
|
||||
|
||||
from pgadmin.utils.driver import get_driver
|
||||
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(
|
||||
sid=kwargs['sid']
|
||||
)
|
||||
sid=kwargs['sid']
|
||||
)
|
||||
|
||||
did = None
|
||||
if 'did' in kwargs:
|
||||
@@ -313,10 +312,10 @@ class PGChildNodeView(NodeView):
|
||||
|
||||
if not conn.connected():
|
||||
return precondition_required(
|
||||
gettext(
|
||||
"Connection to the server has been lost."
|
||||
)
|
||||
)
|
||||
gettext(
|
||||
"Connection to the server has been lost."
|
||||
)
|
||||
)
|
||||
|
||||
nodes = []
|
||||
for module in self.blueprint.submodules:
|
||||
|
||||
Reference in New Issue
Block a user