Added support for the infrastructure for on demand access/create the

server connection.

The BaseDriver and BaseConnection are two abstract classes, which allows
us to replace the existing driver with the currently used. The current
implementation supports to connect the PostgreSQL and Postgres Plus
Advanced Server using the psycopg2 driver.
This commit is contained in:
Ashesh Vashi
2015-10-20 12:33:18 +05:30
parent b52d72f176
commit e27e39a8f3
34 changed files with 2625 additions and 417 deletions

View File

@@ -20,6 +20,7 @@ from pgadmin.utils.ajax import make_json_response, \
from pgadmin.browser import BrowserPluginModule
from pgadmin.utils.menu import MenuItem
from pgadmin.settings.settings_model import db, ServerGroup
from pgadmin.browser.utils import NodeView
class ServerGroupModule(BrowserPluginModule):
@@ -30,13 +31,14 @@ class ServerGroupModule(BrowserPluginModule):
"""Return a JSON document listing the server groups for the user"""
groups = ServerGroup.query.filter_by(user_id=current_user.id)
for group in groups:
group = self.generate_browser_node(
yield self.generate_browser_node(
"%d" % (group.id),
None,
group.name,
"icon-%s" % self.node_type,
True)
yield group
True,
self.node_type
)
@property
def node_type(self):
@@ -46,10 +48,6 @@ class ServerGroupModule(BrowserPluginModule):
def script_load(self):
return None
@property
def node_path(self):
return BrowserPluginModule.browser_url_prefix + self.node_type
class ServerGroupMenuItem(MenuItem):
@@ -65,29 +63,19 @@ class ServerGroupPluginModule(BrowserPluginModule):
__metaclass__ = ABCMeta
@abstractmethod
def get_nodes(self, *arg, **kwargs):
pass
@property
def node_path(self):
return BrowserPluginModule.browser_url_prefix + self.node_type
blueprint = ServerGroupModule( __name__, static_url_path='')
# Initialise the module
from pgadmin.browser.utils import NodeView
blueprint = ServerGroupModule(__name__, static_url_path='')
class ServerGroupView(NodeView):
node_type = ServerGroupModule.NODE_TYPE
parent_ids = []
ids = [{'type':'int', 'id':'gid'}]
ids = [{'type': 'int', 'id': 'gid'}]
def list(self):
res = []
@@ -95,7 +83,6 @@ class ServerGroupView(NodeView):
res.append(g)
return make_json_response(result=res)
def delete(self, gid):
"""Delete a server group node in the settings database"""
@@ -108,18 +95,22 @@ class ServerGroupView(NodeView):
return make_json_response(
status=417,
success=0,
errormsg=gettext('The specified server group could not be found.'))
errormsg=gettext(
'The specified server group could not be found.'
)
)
else:
try:
for sg in servergroup:
db.session.delete(sg)
db.session.commit()
except Exception as e:
return make_json_response(status=410, success=0, errormsg=e.message)
return make_json_response(
status=410, success=0, errormsg=e.message
)
return make_json_response(result=request.form)
def update(self, gid):
"""Update the server-group properties"""
@@ -134,18 +125,22 @@ class ServerGroupView(NodeView):
return make_json_response(
status=417,
success=0,
errormsg=gettext('The specified server group could not be found.'))
errormsg=gettext(
'The specified server group could not be found.'
)
)
else:
try:
if u'name' in data:
servergroup.name = data[u'name']
db.session.commit()
except Exception as e:
return make_json_response(status=410, success=0, errormsg=e.message)
return make_json_response(
status=410, success=0, errormsg=e.message
)
return make_json_response(result=request.form)
def properties(self, gid):
"""Update the server-group properties"""
@@ -159,11 +154,15 @@ class ServerGroupView(NodeView):
return make_json_response(
status=417,
success=0,
errormsg=gettext('The specified server group could not be found.'))
errormsg=gettext(
'The specified server group could not be found.'
)
)
else:
return ajax_response(response={'id': sg.id, 'name': sg.name},
status=200)
return ajax_response(
response={'id': sg.id, 'name': sg.name},
status=200
)
def create(self):
data = request.form if request.form else json.loads(request.data)
@@ -179,14 +178,17 @@ class ServerGroupView(NodeView):
data[u'id'] = sg.id
data[u'name'] = sg.name
return jsonify(node=blueprint.generate_browser_node(
"%d" % (sg.id),
None,
sg.name,
"icon-%s" % self.node_type,
True))
return jsonify(
node=self.blueprint.generate_browser_node(
"%d" % (sg.id),
None,
sg.name,
"icon-%s" % self.node_type,
True,
self.node_type
)
)
except Exception as e:
print 'except'
return make_json_response(
status=410,
success=0,
@@ -198,31 +200,18 @@ class ServerGroupView(NodeView):
success=0,
errormsg=gettext('No server group name was specified'))
def nodes(self, gid):
"""Build a list of treeview nodes from the child nodes."""
nodes = []
for module in blueprint.submodules:
nodes.extend(module.get_nodes(server_group=gid))
return make_json_response(data=nodes)
def sql(self, gid):
return make_json_response(status=422)
def modified_sql(self, gid):
return make_json_response(status=422)
def statistics(self, gid):
return make_json_response(status=422)
def dependencies(self, gid):
return make_json_response(status=422)
def dependents(self, gid):
return make_json_response(status=422)