Code tidy.

This commit is contained in:
Dave Page
2016-06-21 14:21:06 +01:00
parent 3026b470e9
commit 7d0fe669ca
114 changed files with 3891 additions and 3680 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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}

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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):
"""

View File

@@ -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
)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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'}
)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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']

View File

@@ -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)

View File

@@ -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}