Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-ide committed Sep 18, 2024
2 parents 336f5c8 + 6e10313 commit 7a250be
Show file tree
Hide file tree
Showing 33 changed files with 93 additions and 156 deletions.
14 changes: 13 additions & 1 deletion webapp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import daiquiri.formatter

from flask import Flask
from flask import Flask, g
from flask_bootstrap import Bootstrap
from flask_login import LoginManager
from flask_migrate import Migrate
Expand All @@ -40,6 +40,18 @@

app = Flask(__name__)
app.config.from_object(Config)

# The following makes the badge_data variable available to all templates
# Formerly, it was passed in the session, but that caused problems with
# the size of the session cookie. This is a better solution.
# And the beauty of it is that it is available in all templates without
# having to pass it in the render_template call, and it works with redirects
# as well without having to pass it in the url, which leads to urls that are
# too long.
@app.context_processor
def inject_badge_data():
return dict(badge_data=getattr(g, 'badge_data', None))

bootstrap = Bootstrap(app)
login = LoginManager(app)
login.login_view = 'auth.login'
Expand Down
14 changes: 8 additions & 6 deletions webapp/home/check_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from dataclasses import dataclass

from flask import (
Blueprint, Flask, url_for, request, session, current_app
Blueprint, Flask, url_for, request, session, current_app, g
)

import webapp.home.utils.load_and_save
Expand All @@ -37,6 +37,7 @@
from webapp.home.exceptions import EMLFileNotFound
import webapp.auth.user_data as user_data
from webapp.home.check_data_table_contents import check_date_time_attribute
import webapp.home.views as views

app = Flask(__name__)
home = Blueprint('home', __name__, template_folder='templates')
Expand Down Expand Up @@ -1642,9 +1643,9 @@ def init_section_links_found(section_links_found):
for key, value in section_links_found.items():
name = section_to_name(key)
if name and not empty_subtree(eml_node, name):
session[key + '_status'] = 'green'
views.badge_data[key + '_status'] = 'green'
else:
session[key + '_status'] = 'white'
views.badge_data[key + '_status'] = 'white'

def severity_to_status(severity):
if severity == EvalSeverity.OK:
Expand Down Expand Up @@ -1685,6 +1686,7 @@ def find_node_ids(link):
section_links_found = {}
node_links_found = {}
init_section_links_found(section_links_found)
views.badge_data = {}

for entry in evaluation:
severity = entry.severity
Expand All @@ -1706,10 +1708,10 @@ def find_node_ids(link):
name = section_to_name(key)
if name and empty_subtree(eml_node, name):
color = 'white'
session[key + '_status'] = color
views.badge_data[key + '_status'] = color

for key, value in node_links_found.items():
session[key + '_status'] = severity_to_status(value)

views.badge_data[key + '_status'] = severity_to_status(value)

g.badge_data = views.badge_data

20 changes: 10 additions & 10 deletions webapp/home/templates/_macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,22 +198,22 @@ <h5 style="color: #006699">{{ group }}</h5> <!-- Group header -->
{% macro contents_menu_item(url, style, hidden_name, display_name, is_non_saving) %}
{{ button_link(url, 'nav_link', style, hidden_name, display_name, is_non_saving) }}
{% endmacro %}
{% macro contents_menu_item_with_status(url, style, hidden_name, display_name, is_non_saving, badge) %}
{{ contents_menu_item_with_status_left(url, style, hidden_name, display_name, is_non_saving, badge) }}
{% macro contents_menu_item_with_status(url, style, hidden_name, display_name, is_non_saving, badge, badge_data) %}
{{ contents_menu_item_with_status_left(url, style, hidden_name, display_name, is_non_saving, badge, badge_data) }}
{% endmacro %}
{% macro contents_menu_item_with_status_right(url, style, hidden_name, display_name, is_non_saving, badge) %}
{% macro contents_menu_item_with_status_right(url, style, hidden_name, display_name, is_non_saving, badge, badge_data) %}
{{ button_link(url, 'nav_link', style, hidden_name, display_name, is_non_saving) }}
{% set badge_status = badge + '_status' %}
&nbsp;<div class="nav_link {{ session[badge_status] }}_circle"></div><br>
&nbsp;<div class="nav_link {{ badge_data[badge_status] }}_circle"></div><br>
{% endmacro %}
{% macro contents_menu_item_with_status_left(url, style, hidden_name, display_name, is_non_saving, badge) %}
{% macro contents_menu_item_with_status_left(url, style, hidden_name, display_name, is_non_saving, badge, badge_data) %}
{% set badge_status = badge + '_status' %}
{% if session[badge_status] == 'yellow' or session[badge_status] == 'red' %}
{% if badge_data[badge_status] == 'yellow' or badge_data[badge_status] == 'red' %}
{% set url_string = '/eml/check_metadata?' + badge %}
<a class="no-underline" href="{{ url_string }}">
{% endif %}
<div class="{{ session[badge_status] }}_circle nav_link" title="Click for errors/warnings" style="margin-right: 3px;"></div>
{% if session[badge_status] == 'yellow' or session[badge_status] == 'red' %}
<div class="{{ badge_data[badge_status] }}_circle nav_link" title="Click for errors/warnings" style="margin-right: 3px;"></div>
{% if badge_data[badge_status] == 'yellow' or badge_data[badge_status] == 'red' %}
</a>
{% endif %}
{{ button_link(url, 'nav_link', style, hidden_name, display_name, is_non_saving) }}<br>
Expand Down Expand Up @@ -481,11 +481,11 @@ <h5>Or select a template to import from:</h5>
});
</script>
{% endmacro %}
{% macro page_heading_with_status_popup(page_heading, node_id, tooltip, session, help_btn, inner_help_btn) %}
{% macro page_heading_with_status_popup(page_heading, node_id, tooltip, badge_data, help_btn, inner_help_btn) %}
<div class="col-md-10 badged_page_header" style="padding-left: 0;width:100%;border:0px solid red;">
{% set node_id = node_id.split("|")[0] %}
{% set node_status = node_id + '_status' %}
{{ local_status_badge_with_popup(session[node_status], tooltip) }}
{{ local_status_badge_with_popup(badge_data[node_status], tooltip) }}
<div class="whitespace"></div>
<table class="right_justified" style="height:0px;margin-top:0px;margin-bottom: 0px;"><tr>
<td><h2>{{ page_heading }}</h2></td>
Expand Down
38 changes: 19 additions & 19 deletions webapp/home/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -346,25 +346,25 @@
{% if page == 'manage_data_usage' %}{% set manage_data_usage_style = current %}{% endif %}

{# Handle clicks on the main Contents menu.#}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='res.title'), title_style, 'hidden_title', 'Title', ns.is_non_saving, 'title') }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='dt.data_table_select'), data_table_style, 'hidden_data_tables', 'Data Tables', ns.is_non_saving, 'data_tables') }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='rp.creator_select'), creator_style, 'hidden_creators', 'Creators', ns.is_non_saving, 'creators') }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='rp.contact_select'), contact_style, 'hidden_contacts', 'Contacts', ns.is_non_saving, 'contacts') }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='rp.associated_party_select'), associated_party_style, 'hidden_associated_parties', 'Associated Parties', ns.is_non_saving, 'associated_parties') }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='rp.metadata_provider_select'), metadata_provider_style, 'hidden_metadata_providers', 'Metadata Providers', ns.is_non_saving, 'metadata_providers') }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='res.abstract'), abstract_style, 'hidden_abstract', 'Abstract', ns.is_non_saving, 'abstract') }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='res.keyword_select'), keyword_style, 'hidden_keywords', 'Keywords', ns.is_non_saving, 'keywords') }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='res.intellectual_rights'), intellectual_rights_style, 'hidden_intellectual_rights', 'Intellectual Rights', ns.is_non_saving, 'intellectual_rights') }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='cov.geographic_coverage_select'), geographic_coverage_style, 'hidden_geographic_coverage', 'Geographic Coverage', ns.is_non_saving, 'geographic_coverage') }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='cov.temporal_coverage_select'), temporal_coverage_style, 'hidden_temporal_coverage', 'Temporal Coverage', ns.is_non_saving, 'temporal_coverage') }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='cov.taxonomic_coverage_select'), taxonomic_coverage_style, 'hidden_taxonomic_coverage', 'Taxonomic Coverage', ns.is_non_saving, 'taxonomic_coverage') }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='maint.maintenance'), maintenance_style, 'hidden_maintenance', 'Maintenance', ns.is_non_saving, 'maintenance') }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='rp.publisher'), publisher_style, 'hidden_publisher', 'Publisher', ns.is_non_saving, 'publisher') }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='res.publication_info'), publication_info_style, 'hidden_publication_info', 'Publication Info', ns.is_non_saving, 'publication_info') }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='md.method_step_select'), method_step_style, 'hidden_methods', 'Methods', ns.is_non_saving, 'methods') }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='proj.project'), project_style, 'hidden_project', 'Project', ns.is_non_saving, 'project') }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='ent.other_entity_select'), other_entity_style, 'hidden_other_entities', 'Other Entities', ns.is_non_saving, 'other_entities') }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='res.data_package_id'), data_package_id_style, 'hidden_data_package_id', 'Data Package ID', ns.is_non_saving, 'data_package_id') }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='res.title'), title_style, 'hidden_title', 'Title', ns.is_non_saving, 'title', badge_data) }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='dt.data_table_select'), data_table_style, 'hidden_data_tables', 'Data Tables', ns.is_non_saving, 'data_tables', badge_data) }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='rp.creator_select'), creator_style, 'hidden_creators', 'Creators', ns.is_non_saving, 'creators', badge_data) }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='rp.contact_select'), contact_style, 'hidden_contacts', 'Contacts', ns.is_non_saving, 'contacts', badge_data) }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='rp.associated_party_select'), associated_party_style, 'hidden_associated_parties', 'Associated Parties', ns.is_non_saving, 'associated_parties', badge_data) }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='rp.metadata_provider_select'), metadata_provider_style, 'hidden_metadata_providers', 'Metadata Providers', ns.is_non_saving, 'metadata_providers', badge_data) }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='res.abstract'), abstract_style, 'hidden_abstract', 'Abstract', ns.is_non_saving, 'abstract', badge_data) }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='res.keyword_select'), keyword_style, 'hidden_keywords', 'Keywords', ns.is_non_saving, 'keywords', badge_data) }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='res.intellectual_rights'), intellectual_rights_style, 'hidden_intellectual_rights', 'Intellectual Rights', ns.is_non_saving, 'intellectual_rights', badge_data) }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='cov.geographic_coverage_select'), geographic_coverage_style, 'hidden_geographic_coverage', 'Geographic Coverage', ns.is_non_saving, 'geographic_coverage', badge_data) }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='cov.temporal_coverage_select'), temporal_coverage_style, 'hidden_temporal_coverage', 'Temporal Coverage', ns.is_non_saving, 'temporal_coverage', badge_data) }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='cov.taxonomic_coverage_select'), taxonomic_coverage_style, 'hidden_taxonomic_coverage', 'Taxonomic Coverage', ns.is_non_saving, 'taxonomic_coverage', badge_data) }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='maint.maintenance'), maintenance_style, 'hidden_maintenance', 'Maintenance', ns.is_non_saving, 'maintenance', badge_data) }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='rp.publisher'), publisher_style, 'hidden_publisher', 'Publisher', ns.is_non_saving, 'publisher', badge_data) }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='res.publication_info'), publication_info_style, 'hidden_publication_info', 'Publication Info', ns.is_non_saving, 'publication_info', badge_data) }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='md.method_step_select'), method_step_style, 'hidden_methods', 'Methods', ns.is_non_saving, 'methods', badge_data) }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='proj.project'), project_style, 'hidden_project', 'Project', ns.is_non_saving, 'project', badge_data) }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='ent.other_entity_select'), other_entity_style, 'hidden_other_entities', 'Other Entities', ns.is_non_saving, 'other_entities', badge_data) }}
{{ macros.contents_menu_item_with_status(url_for('home.edit', page='res.data_package_id'), data_package_id_style, 'hidden_data_package_id', 'Data Package ID', ns.is_non_saving, 'data_package_id', badge_data) }}
<hr class="nav_link" style="border-top: 1px solid lightgray" width="100px" align="left">
<a class="nav_link {{ session['check_metadata_status'] }}_circle" href="{{ url_for('home.check_metadata') }}"></a>&nbsp;
<a class="nav_link" style={{ check_metadata_style }}; href="{{ url_for('home.edit', page='home.check_metadata') }}" title="Edit">Check Metadata</a>&nbsp;
Expand Down
4 changes: 3 additions & 1 deletion webapp/home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

from flask import (
Blueprint, flash, render_template, redirect, request, url_for,
session, jsonify, send_file
session, jsonify, send_file, g
)

from flask_login import (
Expand Down Expand Up @@ -157,6 +157,8 @@
help_dict = {}
keywords = {}

badge_data = {}

AUTH_TOKEN_FLASH_MSG = 'Authorization to access data was denied. This can be caused by a login timeout. Please log out, log back in, and try again.'


Expand Down
2 changes: 1 addition & 1 deletion webapp/views/coverage/templates/geographic_coverage.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<td style="vertical-align:middle;padding-top: 12px;">
{% set node_id = node_id %}
{% set node_status = node_id + '_status' %}
{{ macros.local_status_badge_with_popup(session[node_status], tooltip) }}
{{ macros.local_status_badge_with_popup(badge_data[node_status], tooltip) }}
</td>
<td style="width:3%"></td>
<td><h2>Geographic Coverage</h2></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<table>
<td style="vertical-align:middle;padding-top: 12px;">
{% set node_status = 'geographic_coverage_status' %}
{{ macros.local_status_badge_with_popup(session[node_status], tooltip, gc_list | length) }}
{{ macros.local_status_badge_with_popup(badge_data[node_status], tooltip, gc_list | length) }}
</td>
<td style="width:3%"></td>
<td><h2>Geographic Coverage{% if entity_name %} for Data Entity: {{ entity_name }}{% endif %}</h2></td>
Expand Down Expand Up @@ -45,7 +45,7 @@
<td>
{% set node_id = gc_entry.id.split("|")[0] %}
{% set node_status = node_id + '_status' %}
{{ macros.status_badge_with_popup(session[node_status], gc_entry.tooltip) }}
{{ macros.status_badge_with_popup(badge_data[node_status], gc_entry.tooltip) }}
{{ gc_entry.geographic_description }}</td>
<td>{{ gc_entry.label }}</td>
{{ macros.up_down_arrow(gc_entry.id, gc_entry.upval) }}
Expand Down
2 changes: 1 addition & 1 deletion webapp/views/coverage/templates/taxonomic_coverage.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<td style="vertical-align:middle;padding-top: 12px;">
{% set node_id = node_id %}
{% set node_status = node_id + '_status' %}
{{ macros.local_status_badge_with_popup(session[node_status], tooltip) }}
{{ macros.local_status_badge_with_popup(badge_data[node_status], tooltip) }}
</td>
<td style="width:3%"></td>
<td><h2>Taxonomic Coverage</h2></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<table>
<td style="vertical-align:middle;padding-top: 12px;">
{% set node_status = 'taxonomic_coverage_status' %}
{% if session[node_status] != 'white' %}
{{ macros.local_status_badge_with_popup(session[node_status], tooltip, txc_list | length) }}
{% if badge_data[node_status] != 'white' %}
{{ macros.local_status_badge_with_popup(badge_data[node_status], tooltip, txc_list | length) }}
</td>
<td style="width:3%">
{% endif %}
Expand All @@ -38,7 +38,7 @@
<td>
{% set node_id = txc_entry.id.split("|")[0] %}
{% set node_status = node_id + '_status' %}
{{ macros.status_badge_with_popup(session[node_status], txc_entry.tooltip) }}
{{ macros.status_badge_with_popup(badge_data[node_status], txc_entry.tooltip) }}
{{ txc_entry.label }}</td>
{{ macros.up_down_arrow(txc_entry.id, txc_entry.upval) }}
{{ macros.up_down_arrow(txc_entry.id, txc_entry.downval) }}
Expand Down
4 changes: 2 additions & 2 deletions webapp/views/coverage/templates/temporal_coverage_select.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<table>
<td style="vertical-align:middle;padding-top: 12px;">
{% set node_status = 'temporal_coverage_status' %}
{{ macros.local_status_badge_with_popup(session[node_status], tooltip, tc_list | length) }}
{{ macros.local_status_badge_with_popup(badge_data[node_status], tooltip, tc_list | length) }}
</td>
<td style="width:3%"></td>
<td><h2>Temporal Coverage{% if entity_name %} for Data Entity: {{ entity_name }}{% endif %}</h2></td>
Expand All @@ -35,7 +35,7 @@
<td>
{% set node_id = tc_entry.id.split("|")[0] %}
{% set node_status = node_id + '_status' %}
{{ macros.status_badge_with_popup(session[node_status], tc_entry.tooltip) }}
{{ macros.status_badge_with_popup(badge_data[node_status], tc_entry.tooltip) }}
{{ tc_entry.begin_date }}</td>
<td>{{ tc_entry.end_date }}</td>
{{ macros.up_down_arrow(tc_entry.id, tc_entry.upval) }}
Expand Down
1 change: 1 addition & 0 deletions webapp/views/data_tables/load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,7 @@ def add_node_if_missing(parent_node, child_name):
old_size_node.content = new_size_node.content
old_records_node.content = new_records_node.content
old_md5_node.content = new_md5_node.content
old_md5_node.attributes = new_md5_node.attributes
old_field_delimiter_node.content = new_field_delimiter_node.content

# record delimiter node is not required, so may be missing
Expand Down
Loading

0 comments on commit 7a250be

Please sign in to comment.