Skip to content

Commit

Permalink
Adding markdown support for table descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Dec 28, 2015
1 parent 6df3e67 commit 37cbf61
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 12 deletions.
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
List of TODO items for Panoramix

## Improvments
* Read dashboard filter from URL
* Table description is markdown
* Animated scatter plots
* Filter widget
Expand Down
4 changes: 4 additions & 0 deletions panoramix/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ class SqlaTable(Model, Queryable, AuditMixinNullable):
def __repr__(self):
return self.table_name

@property
def description_markeddown(self):
return utils.markdown(self.description)

@property
def perm(self):
return (
Expand Down
5 changes: 5 additions & 0 deletions panoramix/static/panoramix.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ html>body{
padding: 10px;
}

.intable-longtext{
max-height: 200px;
overflow: auto;
}

.slice_container {
height: 100%;
}
Expand Down
4 changes: 2 additions & 2 deletions panoramix/templates/panoramix/explore.html
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ <h4 class="modal-title">Query</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title">Query</h4>
<h4 class="modal-title">Datasource Description</h4>
</div>
<div class="modal-body">
<pre id="query_container">{{ datasource.description }}</pre>
{{ datasource.description_markeddown | safe }}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
Expand Down
8 changes: 5 additions & 3 deletions panoramix/templates/panoramix/featured_datasets.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<h1><i class='fa fa-star'></i> Featured Datasets </h1>
</div>
<hr/>
<table class="table table-hover dataTable" id="dataset-table" style="display:None">
<table class="table table-hover dataTable table-bordered" id="dataset-table" style="display:None">
<thead>
<tr>
<th>Table</th>
Expand All @@ -16,9 +16,11 @@ <h1><i class='fa fa-star'></i> Featured Datasets </h1>
<tbody>
{% for dataset in featured_datasets %}
<tr>
<td>
<td>
<div class="intable-longtext">
<h4>{{ dataset.table_name }}</h4>
<p>{{ dataset.description }}</p>
<p>{{ utils.markdown(dataset.description) | safe }}</p>
</div>
</td>
<td class="small_table">{{ dataset.database }}</td>
<td class="small_table">{{ dataset.owner }}</td>
Expand Down
13 changes: 10 additions & 3 deletions panoramix/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from datetime import datetime
from dateutil.parser import parse
import functools
import hashlib
from sqlalchemy.types import TypeDecorator, TEXT
import json

from dateutil.parser import parse
from sqlalchemy.types import TypeDecorator, TEXT
from flask import g, request, Markup
from markdown import markdown as md
import parsedatetime
import functools

from panoramix import db


Expand Down Expand Up @@ -222,3 +225,7 @@ def json_iso_dttm_ser(obj):
if isinstance(obj, datetime):
obj = obj.isoformat()
return obj


def markdown(s):
return md(s, ['markdown.extensions.tables'])
11 changes: 7 additions & 4 deletions panoramix/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re
import traceback

from flask import request, redirect, flash, Response, render_template
from flask import request, redirect, flash, Response, render_template, Markup
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
Expand Down Expand Up @@ -153,7 +153,8 @@ class TableView(PanoramixModelView, DeleteMixin):
related_views = [TableColumnInlineView, SqlMetricInlineView]
base_order = ('changed_on','desc')
description_columns = {
'offset': "Timezone offset (in hours) for this datasource"
'offset': "Timezone offset (in hours) for this datasource",
'description': Markup("Supports <a href='https://daringfireball.net/projects/markdown/'>markdown</a>"),
}

def post_add(self, table):
Expand Down Expand Up @@ -281,7 +282,8 @@ class DatasourceModelView(PanoramixModelView, DeleteMixin):
page_size = 100
base_order = ('datasource_name', 'asc')
description_columns = {
'offset': "Timezone offset (in hours) for this datasource"
'offset': "Timezone offset (in hours) for this datasource",
'description': Markup("Supports <a href='https://daringfireball.net/projects/markdown/'>markdown</a>"),
}

def post_add(self, datasource):
Expand Down Expand Up @@ -564,7 +566,8 @@ def featured_datasets(self):
featured_datasets = datasets_sqla + datasets_druid
return self.render_template(
'panoramix/featured_datasets.html',
featured_datasets=featured_datasets)
featured_datasets=featured_datasets,
utils=utils)

appbuilder.add_view_no_menu(Panoramix)
appbuilder.add_link(
Expand Down

0 comments on commit 37cbf61

Please sign in to comment.