From 35cc8018214d9d3f928aeee6fcbd0f18b19ae74f Mon Sep 17 00:00:00 2001 From: "Luis J. Villanueva" Date: Wed, 6 Nov 2024 10:45:21 -0500 Subject: [PATCH] Updating to 2.8 --- web_app/app.py | 85 ++++++++++++++++++------------ web_app/templates/about.html | 75 ++++++++++++++------------ web_app/templates/file.html | 2 +- web_app/templates/new_project.html | 2 +- 4 files changed, 95 insertions(+), 69 deletions(-) diff --git a/web_app/app.py b/web_app/app.py index 1e72d18..722ddbf 100644 --- a/web_app/app.py +++ b/web_app/app.py @@ -103,8 +103,8 @@ def newroute(route, *args, **kwargs): password=settings.password, database=settings.database, port=settings.port, - autocommit=True, - wait_timeout=600) + autocommit=True, + connection_timeout=600) conn.time_zone = '-04:00' cur = conn.cursor(dictionary=True) except mysql.connector.Error as err: @@ -154,6 +154,8 @@ def sys_error(e): def run_query(query, parameters=None, return_val=True): logger.info("parameters: {}".format(parameters)) logger.info("query: {}".format(query)) + # Check connection to DB and reconnect if needed + conn.ping(reconnect=True, attempts=3, delay=1) # Run query if parameters is None: results = cur.execute(query) @@ -165,11 +167,13 @@ def run_query(query, parameters=None, return_val=True): return data else: return True - + def query_database_insert(query, parameters, return_res=False): logger.info("query: {}".format(query)) logger.info("parameters: {}".format(parameters)) + # Check connection to DB and reconnect if needed + conn.ping(reconnect=True, attempts=3, delay=1) # Run query data = False try: @@ -616,11 +620,17 @@ def dashboard_f(project_alias=None, folder_id=None, tab=None, page=None): return render_template('error.html', error_msg=error_msg, project_alias=project_alias, site_env=site_env, site_net=site_net, site_ver=site_ver, analytics_code=settings.analytics_code), 400 - + # Check if project exists if project_alias_exists(project_alias) is False: - error_msg = "Project was not found." - return render_template('error.html', error_msg=error_msg, + # Check if project alias in list of redirects + try: + if project_alias_exists(settings.proj_redirect[project_alias]): + logger.info("project_alias_redirect: {}".format(project_alias)) + return redirect(url_for('dashboard', project_alias=settings.proj_redirect[project_alias])) + except KeyError: + error_msg = "Project was not found." + return render_template('error.html', error_msg=error_msg, project_alias=project_alias, site_env=site_env, site_net=site_net, site_ver=site_ver, analytics_code=settings.analytics_code), 404 @@ -1124,13 +1134,20 @@ def dashboard(project_alias=None, folder_id=None): project_stats = {} # Check if project exists - project_id = project_alias_exists(project_alias) - if project_id is False: - error_msg = "Project was not found." - return render_template('error.html', error_msg=error_msg, project_alias=project_alias, - site_env=site_env, site_net=site_net, site_ver=site_ver, + if project_alias_exists(project_alias) is False: + # Check if project alias in list of redirects + try: + if project_alias_exists(settings.proj_redirect[project_alias]): + logger.info("project_alias_redirect: {}".format(project_alias)) + return redirect(url_for('dashboard', project_alias=settings.proj_redirect[project_alias])) + except KeyError: + error_msg = "Project was not found." + return render_template('error.html', error_msg=error_msg, + project_alias=project_alias, site_env=site_env, site_net=site_net, site_ver=site_ver, analytics_code=settings.analytics_code), 404 + project_id = project_alias_exists(project_alias) + logger.info("project_id: {}".format(project_id)) logger.info("project_alias: {}".format(project_alias)) if current_user.is_authenticated: @@ -2212,29 +2229,29 @@ def create_new_project(): " (%(project_id)s, %(user_id)s)"), {'project_id': project_id, 'user_id': '101'}) - if p_unitstaff != '': - unitstaff = p_unitstaff.split(',') - logger.info("unitstaff: {}".format(p_unitstaff)) - logger.info("len_unitstaff: {}".format(len(unitstaff))) - if len(unitstaff) > 0: - for staff in unitstaff: - staff_user_id = run_query("SELECT user_id FROM users WHERE username = %(username)s", - {'username': staff.strip()}) - if len(staff_user_id) == 1: - user_project = query_database_insert(("INSERT INTO qc_projects (project_id, user_id) VALUES " - " (%(project_id)s, %(user_id)s)"), - {'project_id': project_id, - 'user_id': staff_user_id[0]['user_id']}) - else: - user_project = query_database_insert(("INSERT INTO users (username, user_active, is_admin) VALUES " - " (%(username)s, 'T', 'F')"), - {'username': staff.strip()}) - get_user_project = run_query(("SELECT user_id FROM users WHERE username = %(username)s"), - {'username': staff.strip()}) - user_project = query_database_insert(("INSERT INTO qc_projects (project_id, user_id) VALUES " - " (%(project_id)s, %(user_id)s)"), - {'project_id': project_id, - 'user_id': get_user_project[0]['user_id']}) + # if p_unitstaff != '': + # unitstaff = p_unitstaff.split(',') + # logger.info("unitstaff: {}".format(p_unitstaff)) + # logger.info("len_unitstaff: {}".format(len(unitstaff))) + # if len(unitstaff) > 0: + # for staff in unitstaff: + # staff_user_id = run_query("SELECT user_id FROM users WHERE username = %(username)s", + # {'username': staff.strip()}) + # if len(staff_user_id) == 1: + # user_project = query_database_insert(("INSERT INTO qc_projects (project_id, user_id) VALUES " + # " (%(project_id)s, %(user_id)s)"), + # {'project_id': project_id, + # 'user_id': staff_user_id[0]['user_id']}) + # else: + # user_project = query_database_insert(("INSERT INTO users (username, user_active, is_admin) VALUES " + # " (%(username)s, 'T', 'F')"), + # {'username': staff.strip()}) + # get_user_project = run_query(("SELECT user_id FROM users WHERE username = %(username)s"), + # {'username': staff.strip()}) + # user_project = query_database_insert(("INSERT INTO qc_projects (project_id, user_id) VALUES " + # " (%(project_id)s, %(user_id)s)"), + # {'project_id': project_id, + # 'user_id': get_user_project[0]['user_id']}) fcheck_query = ("INSERT INTO projects_settings (project_id, project_setting, settings_value) VALUES " " (%(project_id)s, 'project_checks', %(value)s)") fcheck_insert = query_database_insert(fcheck_query, {'project_id': project_id, 'value': 'unique_file'}) diff --git a/web_app/templates/about.html b/web_app/templates/about.html index 830126c..aa0a46b 100644 --- a/web_app/templates/about.html +++ b/web_app/templates/about.html @@ -8,41 +8,50 @@ {% block content %} -

Osprey Application Logo Osprey - DPO Collections Digitization Dashboard - version {{ site_ver }}

- - {% if site_net == "internal" %}

This is the SI-Internal instance

{% endif %} - -

Osprey is an open-source application and the source is hosted - at https://github.com/Smithsonian/Osprey - (link is external)

-

Important Note: Osprey is not a permanent system of record. This system - provides a convenient way to see the products of digitization projects in a timely fashion. Do not link to specific - pages or images since they will go away without notice.

- - {% if site_net == "internal" %} -

This is a project of the: Digitization Program Office, a division of the Smithsonian's Office of Digital Transformation.

- {% else %} -

This is a project of the: Digitization Program Office, a division of the Smithsonian's Office of Digital Transformation.

+
+
+

Osprey Application Logo Osprey - DPO Collections Digitization Dashboard - version {{ site_ver }}

+
+
+ +
+
+ + {% if site_net == "internal" %}

This is the SI-Internal instance

{% endif %} + +

Osprey is an open-source application and the source is hosted + at https://github.com/Smithsonian/Osprey + (link is external)

+ +

Important Note: Osprey is not a permanent system of record. This system + provides a convenient way to see the products of digitization projects in a timely fashion. Do not link to specific + pages or images since they will go away without notice.

+ + {% if site_net == "internal" %} +

This is a project of the: Digitization Program Office, a division of the Smithsonian's Office of Digital Transformation (formerly a division of the Office of the Chief Information Officer).

+ {% else %} +

This is a project of the: Digitization Program Office, a division of the Smithsonian's Office of Digital Transformation.

+ + {% endif %} +
+
+ {% if site_net == "internal" %} +

There is an API available (JSON). Please contact Luis J. Villanueva, DPO, for an API key.

+ {% endif %} + +

+ +

Special thanks to:

+
    +
  • OCIO for hosting our servers and supporting the infrastructure we use in our projects
  • +
  • The DAMS team for sharing their data
  • +
  • The Osprey (Pandion haliaetus) silhouette image is from Phylopic (link to source)
  • +
+
+
- {% endif %} - -

- - {% if site_net == "internal" %} -

There is an API available (JSON). Please contact Luis J. Villanueva, DPO, for an API key.

- {% endif %} - -

- -

Special thanks to:

- -
{% endblock %} diff --git a/web_app/templates/file.html b/web_app/templates/file.html index d65edcb..4fdbefe 100644 --- a/web_app/templates/file.html +++ b/web_app/templates/file.html @@ -25,7 +25,7 @@

Details of {{ file_details.file_name }}

- Prev File + Prev File  Next File
(by alphabetical order) diff --git a/web_app/templates/new_project.html b/web_app/templates/new_project.html index bf067f3..bc50c46 100644 --- a/web_app/templates/new_project.html +++ b/web_app/templates/new_project.html @@ -91,7 +91,7 @@

File checks:

- +