Skip to content

Commit

Permalink
In Import Keywords, separate the keyword sets with headings. (#160)
Browse files Browse the repository at this point in the history
jon-ide committed Jan 10, 2024
1 parent 0824e80 commit d6107bd
Showing 3 changed files with 38 additions and 11 deletions.
30 changes: 28 additions & 2 deletions webapp/home/templates/_macros.html
Original file line number Diff line number Diff line change
@@ -83,7 +83,33 @@
{% if form.to_import.choices %}
<tr>{{ form.to_import(style="list-style:none;") }}</tr>
{% else %}
<tr><span style="font-style: italic;">&nbsp;&nbsp;"{{ target_filename }}" contains no {{ item_name }}.<p></p></span><br></tr>
<tr><span style="font-style: italic;">&nbsp;&nbsp;"{{ source_filename }}" contains no {{ item_name }}.<p></p></span><br></tr>
{% endif %}
{% endmacro %}
{% macro import_selection_grouped(form, source_filename, option_groups, item_name) %}
<script>
function choose_options(all) {
$('input:checkbox').not(this).prop('checked', all);
}
</script>
<tr><h5>Select {{ item_name }} to import from "{{ source_filename }}":
&nbsp;&nbsp;&nbsp;&nbsp;[ <button class="link" type="button" onclick="choose_options(true); return false;">Select All</button> ]
&nbsp;&nbsp;&nbsp;&nbsp;[ <button class="link" type="button" onclick="choose_options(false); return false;">Clear All</button> ]</h5>
</tr>
{% if form.to_import.choices %}
<tr>
{% for group, options in option_groups.items() %}
<h5 style="color: #006699">{{ group }}</h5> <!-- Group header -->
{% for option in options %}
<div>
&nbsp;&nbsp;&nbsp;<input type="checkbox" name="to_import" value="{{ option[0] }}">
<label for="{{ option[0] }}">{{ option[1] }}</label>
</div>
{% endfor %}
{% endfor %}
</tr>
{% else %}
<tr><span style="font-style: italic;">&nbsp;&nbsp;"{{ source_filename }}" contains no {{ item_name }}.<p></p></span><br></tr>
{% endif %}
{% endmacro %}
{% macro import_selection_sortable(form, source_filename, item_name) %}
@@ -155,7 +181,7 @@
<tr>{{ form.to_import_sorted(style="list-style:none;") }}</tr>
{% endif %}
{% else %}
<tr><span style="font-style: italic;">&nbsp;&nbsp;"{{ target_filename }}" contains no {{ item_name }}.<p></p></span><br></tr>
<tr><span style="font-style: italic;">&nbsp;&nbsp;"{{ source_filename }}" contains no {{ item_name }}.<p></p></span><br></tr>
{% endif %}
{% endmacro %}
{% macro import_buttons(form) %}
2 changes: 1 addition & 1 deletion webapp/home/templates/import_keywords_2.html
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
<form method="POST" action="" class="form" role="form">
{{ form.csrf_token }}
<table>
{{ macros.import_selection(form, source_filename, 'keywords') }}
{{ macros.import_selection_grouped(form, source_filename, keyword_groups, 'keywords') }}<br>
{{ macros.import_buttons(form) }}
</table>
{{ macros.hidden_buttons() }}
17 changes: 9 additions & 8 deletions webapp/home/views.py
Original file line number Diff line number Diff line change
@@ -1641,8 +1641,7 @@ def import_keywords_2(filename, template, is_template):

def get_keywords_for_import(eml_node):
keyword_tuples = []
# Returns a list of tuples
# (keyword_node_id, keyword)
keyword_groups = {}
dataset_node = eml_node.find_child(names.DATASET)
if not dataset_node:
return []
@@ -1658,12 +1657,14 @@ def get_keywords_for_import(eml_node):
thesaurus_node = keyword_set_node.find_child(names.KEYWORDTHESAURUS)
thesaurus = thesaurus_node.content if thesaurus_node else ''
if thesaurus:
thesaurus = f'[{thesaurus}]'
thesaurus = f'{thesaurus}'
keyword_tuples.append((keyword_node.id, f'{keyword} {thesaurus}', keyword, thesaurus))
return [(a, b) for a, b, _, _ in keyword_tuples], \
keyword_groups[thesaurus] = keyword_groups.get(thesaurus, []) + [(keyword_node.id, keyword)]
for key in keyword_groups:
keyword_groups[key].sort(key=lambda x: x[1].lower())
return keyword_groups, \
[(a, b) for a, b, _, _ in sorted(keyword_tuples, key=lambda x: (x[3].lower(), x[2].lower()))]

# form = ImportKeywordsForm()
form = ImportItemsForm()

is_template = ast.literal_eval(is_template)
@@ -1675,9 +1676,8 @@ def get_keywords_for_import(eml_node):
source_filename = template_display_name(unquote(template))
eml_node = load_template(unquote(template))

choices, sorted_choices = get_keywords_for_import(eml_node)
keyword_groups, sorted_choices = get_keywords_for_import(eml_node)
form.to_import.choices = sorted_choices
# form.to_import.sorted_choices = sorted_choices

if request.method == 'POST' and BTN_CANCEL in request.form:
return redirect(get_back_url())
@@ -1695,7 +1695,8 @@ def get_keywords_for_import(eml_node):

# Process GET
help = get_helps(['import_keywords_2'])
return render_template('import_keywords_2.html', help=help, source_filename=source_filename, form=form)
return render_template('import_keywords_2.html', help=help, source_filename=source_filename,
keyword_groups=keyword_groups, form=form)


@home_bp.route('/import_geo_coverage', methods=['GET', 'POST'])

0 comments on commit d6107bd

Please sign in to comment.