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

Add example DataSet keys to Data Source page #485

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions common/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ def init_datasource(database, logger, queue, name):
"""
pass

def get_datasource_example_keys(db, modules, dataset_type):
"""
Get example keys for a datasource
"""
from common.lib.dataset import DataSet
example_dataset_key = db.fetchone("SELECT key from datasets WHERE type = %s and is_finished = True and num_rows > 0 LIMIT 1", (dataset_type,))
if example_dataset_key:
example_dataset = DataSet(db=db, key=example_dataset_key["key"], modules=modules)
return example_dataset.get_columns()
return []

def strip_tags(html, convert_newlines=True):
"""
Strip HTML from a string
Expand Down
12 changes: 12 additions & 0 deletions webtool/templates/data-overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ <h3>Metadata</h3>
</dd>
</div>
{% endif %}
{% if example_keys %}
<div class="fullwidth">
<dt>DataSet keys</dt>
<dd>
<ul class="nobullet">
{% for key in example_keys %}
<span class="inline-label property-badge">{{ key }}</span>
{% endfor %}
</ul>
</dd>
</div>
{% endif %}
</dl>
</div>
{% else %}
Expand Down
8 changes: 7 additions & 1 deletion webtool/views/views_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from webtool.views.views_dataset import create_dataset, show_results

from common.config_manager import ConfigWrapper
from common.lib.helpers import get_datasource_example_keys
config = ConfigWrapper(config, user=current_user, request=request)

csv.field_size_limit(1024 * 1024 * 1024)
Expand Down Expand Up @@ -129,6 +130,7 @@ def data_overview(datasource=None):
daily_counts = None
references = None
labels = None
example_keys = None

if datasource:

Expand Down Expand Up @@ -156,6 +158,10 @@ def data_overview(datasource=None):
if hasattr(worker_class, "is_from_zeeschuimer"):
labels.append("zeeschuimer")

# Get example keys for the datasource
if datasource_id not in ["upload"]: # ignore upload as keys are variable
example_keys = get_datasource_example_keys(db=db, modules=fourcat_modules, dataset_type=datasource_id + "-search")

# Get daily post counts for local datasource to display in a graph
if is_local == "local":

Expand Down Expand Up @@ -185,7 +191,7 @@ def data_overview(datasource=None):

references = worker_class.references if hasattr(worker_class, "references") else None

return render_template('data-overview.html', datasources=datasources, datasource_id=datasource_id, description=description, labels=labels, total_counts=total_counts, daily_counts=daily_counts, github_url=github_url, references=references)
return render_template('data-overview.html', datasources=datasources, datasource_id=datasource_id, description=description, labels=labels, total_counts=total_counts, daily_counts=daily_counts, github_url=github_url, references=references, example_keys=example_keys)

@app.route('/get-boards/<string:datasource>/')
@login_required
Expand Down