Skip to content

Commit

Permalink
Adding owner to sqlatables and changing some of the formatting using …
Browse files Browse the repository at this point in the history
…DataTables
  • Loading branch information
Michelle Thomas committed Dec 16, 2015
1 parent 30df7be commit 6155ff8
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 14 deletions.
27 changes: 27 additions & 0 deletions panoramix/migrations/versions/2591d77e9831_user_id.py
@@ -0,0 +1,27 @@
"""user_id
Revision ID: 2591d77e9831
Revises: 12d55656cbca
Create Date: 2015-12-15 17:02:45.128709
"""

# revision identifiers, used by Alembic.
revision = '2591d77e9831'
down_revision = '12d55656cbca'

from alembic import op
import sqlalchemy as sa


def upgrade():
with op.batch_alter_table('tables') as batch_op:
batch_op.add_column(sa.Column('user_id', sa.Integer()))
batch_op.create_foreign_key('user_id', 'ab_user', ['user_id'], ['id'])


def downgrade():
with op.batch_alter_table('tables'):
op.drop_constraint(None, 'tables', type_='foreignkey')
op.drop_column('tables', 'user_id')

2 changes: 2 additions & 0 deletions panoramix/models.py
Expand Up @@ -229,6 +229,8 @@ class SqlaTable(Model, Queryable, AuditMixinNullable):
default_endpoint = Column(Text)
database_id = Column(Integer, ForeignKey('dbs.id'), nullable=False)
is_featured = Column(Boolean, default=False)
user_id = Column(Integer, ForeignKey('ab_user.id'))
owner = relationship('User', backref='tables', foreign_keys=[user_id])
database = relationship(
'Database', backref='tables', foreign_keys=[database_id])
offset = Column(Integer, default=0)
Expand Down
13 changes: 6 additions & 7 deletions panoramix/static/featured_datasets.css
Expand Up @@ -4,15 +4,14 @@
margin-bottom: 20px;
}

.data-title{
font-size: 26px;
font-weight: strong;
.small_table {
width: 170px;
}

table {
border-bottom: 1px solid #dddddd;
#data-title{
font-size: 20px;
}

td {
vertical-align: middle;
#dataset-table {
border-bottom: 1px solid #dddddd;
}
20 changes: 17 additions & 3 deletions panoramix/templates/panoramix/featured_datasets.html
Expand Up @@ -4,24 +4,38 @@
<div class="main-text">
Featured Datasets
</div>
<table class = "table table-hover">
<table class = "table table-hover" id="dataset-table">
<thead>
<tr>
<th>Table</th>
<th>Database</th>
<th>Owner</th>
<th></th>
</tr>
</thead>
<tbody>
{% for dataset in featured_datasets %}
<tr>
<td>
<a href='{{ dataset.default_endpoint }}' class="data-title">{{ dataset.table_name }}</a>
<div id="data-title">{{ dataset.table_name }}</div>
</br> {{ dataset.description }}
</td>
<td>{{ dataset.database }}</td>
<td class="small_table">{{ dataset.database }}</td>
<td class="small_table">{{ dataset.owner }}</td>
<td class="small_table"><button type="button" class="btn btn-primary" href="{{ dataset.default_endpoint }}">Visualize it!</button></td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

{% block tail %}
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.10/css/dataTables.bootstrap.min.css" />
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function() {
$('#dataset-table').DataTable();
} );
</script>
{% endblock %}
16 changes: 12 additions & 4 deletions panoramix/views.py
Expand Up @@ -59,6 +59,14 @@ class TableColumnInlineView(CompactCRUDMixin, PanoramixModelView):
}
appbuilder.add_view_no_menu(TableColumnInlineView)

appbuilder.add_link(
"Featured Datasets",
href='/panoramix/featured_datasets',
category='Sources',
category_icon='fa-table',
icon="fa-star")



class ColumnInlineView(CompactCRUDMixin, PanoramixModelView):
datamodel = SQLAInterface(models.Column)
Expand Down Expand Up @@ -140,8 +148,8 @@ class TableView(PanoramixModelView, DeleteMixin):
list_columns = ['table_link', 'database', 'changed_by', 'changed_on_']
add_columns = ['table_name', 'database', 'default_endpoint', 'offset']
edit_columns = [
'table_name', 'is_featured', 'database', 'description', 'main_dttm_col',
'default_endpoint', 'offset']
'table_name', 'is_featured', 'database', 'description', 'owner',
'main_dttm_col', 'default_endpoint', 'offset']
related_views = [TableColumnInlineView, SqlMetricInlineView]
base_order = ('changed_on','desc')
description_columns = {
Expand Down Expand Up @@ -539,8 +547,8 @@ def show_traceback(self):
art=ascii_art.error), 500

@has_access
@expose("/datasets", methods=['GET'])
def datasets(self):
@expose("/featured_datasets", methods=['GET'])
def featured_datasets(self):
session = db.session()
datasets_sqla = (session.query(models.SqlaTable)
.filter_by(is_featured=True).all())
Expand Down

0 comments on commit 6155ff8

Please sign in to comment.