Add support for dropping multiple objects at once from the collection Properties panel. Fixes #1513

This commit is contained in:
Khushboo Vashi
2018-10-31 10:30:36 +00:00
committed by Dave Page
parent 3359a0de7a
commit f17979141c
124 changed files with 5969 additions and 1315 deletions

View File

@@ -80,7 +80,7 @@ class TablespaceView(PGChildNodeView):
operations = dict({
'obj': [
{'get': 'properties', 'delete': 'delete', 'put': 'update'},
{'get': 'list', 'post': 'create'}
{'get': 'list', 'post': 'create', 'delete': 'delete'}
],
'nodes': [{'get': 'node'}, {'get': 'nodes'}],
'children': [{'get': 'children'}],
@@ -395,51 +395,54 @@ class TablespaceView(PGChildNodeView):
return internal_server_error(errormsg=str(e))
@check_precondition
def delete(self, gid, sid, tsid):
def delete(self, gid, sid, tsid=None):
"""
This function will drop the tablespace object
"""
try:
# Get name for tablespace from tsid
status, rset = self.conn.execute_dict(
render_template(
"/".join([self.template_path, 'nodes.sql']),
tsid=tsid, conn=self.conn
)
if tsid is None:
data = request.form if request.form else json.loads(
request.data, encoding='utf-8'
)
else:
data = {'ids': [tsid]}
if not status:
return internal_server_error(errormsg=rset)
if not rset['rows']:
return make_json_response(
success=0,
errormsg=gettext(
'Error: Object not found.'
),
info=gettext(
'The specified tablespace could not be found.\n'
try:
for tsid in data['ids']:
# Get name for tablespace from tsid
status, rset = self.conn.execute_dict(
render_template(
"/".join([self.template_path, 'nodes.sql']),
tsid=tsid, conn=self.conn
)
)
# drop tablespace
SQL = render_template(
"/".join([self.template_path, 'delete.sql']),
tsname=(rset['rows'][0])['name'], conn=self.conn
)
if not status:
return internal_server_error(errormsg=rset)
status, res = self.conn.execute_scalar(SQL)
if not status:
return internal_server_error(errormsg=res)
if not rset['rows']:
return make_json_response(
success=0,
errormsg=gettext(
'Error: Object not found.'
),
info=gettext(
'The specified tablespace could not be found.\n'
)
)
# 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:
return internal_server_error(errormsg=res)
return make_json_response(
success=1,
info=gettext("Tablespace dropped"),
data={
'id': tsid,
'sid': sid,
'gid': gid,
}
info=gettext("Tablespace dropped")
)
except Exception as e:

View File

@@ -16,6 +16,8 @@ define('pgadmin.node.tablespace', [
columns: ['name', 'spcuser', 'description'],
hasStatistics: true,
statsPrettifyFields: ['Size'],
canDrop: true,
canDropCascade: false,
});
}
@@ -303,6 +305,7 @@ define('pgadmin.node.tablespace', [
},
},
model: pgBrowser.Node.Model.extend({
idAttribute: 'oid',
defaults: {
name: undefined,
owner: undefined,

View File

@@ -44,7 +44,7 @@ def get_tablespace_data(tablespace_path, db_owner):
return data
def create_tablespace(server, test_tablespace_name):
def create_tablespace(server, test_tablespace_name, test_tablespace_dir=None):
try:
connection = utils.get_db_connection(server['db'],
server['username'],
@@ -55,8 +55,10 @@ def create_tablespace(server, test_tablespace_name):
old_isolation_level = connection.isolation_level
connection.set_isolation_level(0)
pg_cursor = connection.cursor()
if test_tablespace_dir is None:
test_tablespace_dir = server['tablespace_path']
pg_cursor.execute("CREATE TABLESPACE %s LOCATION '%s'" %
(test_tablespace_name, server['tablespace_path']))
(test_tablespace_name, test_tablespace_dir))
connection.set_isolation_level(old_isolation_level)
connection.commit()