Skip to content

Commit

Permalink
Casi andando tags
Browse files Browse the repository at this point in the history
  • Loading branch information
germankay committed Jan 7, 2025
1 parent 683b570 commit 5e10cbe
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ckanext/superset/blueprints/superset.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,17 @@ def create_dataset(chart_id):
# Obtener los grupos disponibles
groups_available = tk.get_action('group_list')({'user': current_user.name}, {'all_fields': True})

# Obtener Tags disponibles de cada chart
tags_available = tk.get_action('tag_list')({'user': current_user.name}, {'all_fields': True})

if not tags_available:
log.warning(f"No tags found for chart {superset_chart.data.get('slice_name', 'unknown')}")

if request.method == 'GET':
extra_vars = {
'superset_chart': superset_chart,
'groups_available': groups_available,
'tags_available': tags_available,
}
return tk.render('superset/create-dataset.html', extra_vars)

Expand All @@ -78,6 +85,15 @@ def create_dataset(chart_id):
if invalid_groups:
raise tk.ValidationError(f"Invalid group IDs: {', '.join(invalid_groups)}")

# Obtener los Tags seleccionados del formulario
selected_tags = request.form.getlist('ckan_tags[]')
# Convertir los tags seleccionados a una lista de diccionarios
tags = [{"name": tag} for tag in selected_tags]

# Validar si hay tags
if not tags:
log.warning(f"No valid tags provided for the dataset {ckan_dataset_name}. Tags will be empty.")

# Crear el dataset
action = tk.get_action("package_create")
context = {'user': current_user.name}
Expand All @@ -89,6 +105,7 @@ def create_dataset(chart_id):
'private': request.form.get('ckan_dataset_private') == 'on',
'extras': [{'key': 'superset_chart_id', 'value': chart_id}],
'groups': [{"id": group_id} for group_id in selected_group_ids],
'tags': tags,
}
pkg = action(context, data)

Expand Down
16 changes: 16 additions & 0 deletions ckanext/superset/templates/superset/create-dataset.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ <h2>Create CKAN dataset from Superset dataset</h2>
</div>
</div>

<!-- Tags -->
<div class="form-group">
<label for="ckan_dataset_tags">Tags</label>
<i class="fa fa-info-circle" data-toggle="tooltip" title="Selecciona los Tags que deseas asociar con este dataset."></i>
<div class="checkbox-group">
{% for tag in tags_available %}
<div class="form-check">
<input class="form-check-input" type="checkbox" id="tag_{{ tag.id }}" name="ckan_tags[]" value="{{ tag.id }}">
<label class="form-check-label" for="tag_{{ tag.id }}">
{{ tag.name }}
</label>
</div>
{% endfor %}
</div>
</div>

<!-- CKAN notes/description -->
<div class="form-group">
<label for="ckan_dataset_notes">Dataset description</label>
Expand Down

0 comments on commit 5e10cbe

Please sign in to comment.