Skip to content

Commit

Permalink
Adding a button to test connections
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Sep 24, 2015
1 parent caafb1e commit e854798
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 3 deletions.
Empty file added panoramix/data/__init__.py
Empty file.
Empty file.
Binary file added panoramix/static/servers.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions panoramix/templates/panoramix/models/database/add.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "appbuilder/general/model/add.html" %}

{% import "panoramix/models/database/macros.html" as macros %}
{% block tail_js %}
{{ super() }}
{{ macros.testconn() }}
{% endblock %}
7 changes: 7 additions & 0 deletions panoramix/templates/panoramix/models/database/edit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "appbuilder/general/model/edit.html" %}

{% import "panoramix/models/database/macros.html" as macros %}
{% block tail_js %}
{{ super() }}
{{ macros.testconn() }}
{% endblock %}
19 changes: 19 additions & 0 deletions panoramix/templates/panoramix/models/database/macros.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% macro testconn() %}
<script>
$("#sqlalchemy_uri").parent()
.append('<button id="testconn" class="btn">Test Connection</button>');
$("#testconn").click(function() {
var url = "/panoramix/testconn";
$.ajax({
method: "GET",
url: url,
data: { uri: $("#sqlalchemy_uri").val() }
}).done(function() {
alert("success");
}).fail(function(error) {
alert("ERROR: " + error.responseText);
});
return false;
});
</script>
{% endmacro %}
21 changes: 18 additions & 3 deletions panoramix/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import logging

from flask import request, redirect, flash, Response
from flask.ext.appbuilder.models.sqla.interface import SQLAInterface
from flask.ext.appbuilder import ModelView, CompactCRUDMixin, BaseView, expose
from flask.ext.appbuilder.actions import action
from flask.ext.appbuilder.models.sqla.interface import SQLAInterface
from flask.ext.appbuilder.security.decorators import has_access
from pydruid.client import doublesum
from sqlalchemy import create_engine
from wtforms.validators import ValidationError
from flask.ext.appbuilder.actions import action

from panoramix import appbuilder, db, models, viz, utils, app, config

Expand Down Expand Up @@ -91,6 +92,8 @@ class DatabaseView(ModelView, DeleteMixin):
list_columns = ['database_name']
add_columns = ['database_name', 'sqlalchemy_uri']
edit_columns = add_columns
add_template = "panoramix/models/database/add.html"
edit_template = "panoramix/models/database/edit.html"

appbuilder.add_view(
DatabaseView,
Expand Down Expand Up @@ -317,7 +320,19 @@ def save_dash(self, dashboard_id):
return "SUCCESS"

@has_access
@expose("/save/")
@expose("/testconn/")
def testconn(self):
try:
db = create_engine(request.args.get('uri'))
for i in range(15):
request.args.get('uri')
db.connect()
return "SUCCESS"
except Exception as e:
return Response(
str(e),
status=500,
mimetype="application/json")

@has_access
@expose("/dashboard/<id_>/")
Expand Down

0 comments on commit e854798

Please sign in to comment.