Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a button to test connections #31

Merged
merged 1 commit into from
Sep 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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