Skip to content

Commit

Permalink
Updating to 2.8
Browse files Browse the repository at this point in the history
  • Loading branch information
villanueval committed Nov 6, 2024
1 parent ccc3848 commit 35cc801
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 69 deletions.
85 changes: 51 additions & 34 deletions web_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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'})
Expand Down
75 changes: 42 additions & 33 deletions web_app/templates/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,50 @@

{% block content %}

<p style="font-size: large;"><img src="{{ url_for('static', filename='osprey_logo_200.png') }}" alt="Osprey Application Logo"> <strong>Osprey - DPO Collections Digitization Dashboard</strong> - version {{ site_ver }}</p>

{% if site_net == "internal" %}<p><strong>This is the SI-Internal instance</strong></p>{% endif %}

<p>Osprey is an open-source application and the source is hosted
at <a href="https://github.com/Smithsonian/Osprey" target="_blank" rel="noopener noreferrer" title="Opens in new window">https://github.com/Smithsonian/Osprey
<i class="small fa-solid fa-arrow-up-right-from-square"></i><span class="screen-reader-only">(link is external)</span></a></p>

<p class="w-50"><strong>Important Note:</strong> Osprey is <strong>not</strong> 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.</p>

{% if site_net == "internal" %}
<p>This is a project of the: <a href="https://sinet.sharepoint.com/sites/DPO" title="Link to the SharePoint site of the Digitization Program Office">Digitization Program Office</a>, a division of the Smithsonian's <a href="https://sinet.sharepoint.com/sites/ODT" class="bg-white" title="Link to the Office of Digital Transformation
">Office of Digital Transformation</a>.</p>
{% else %}
<p>This is a project of the: <a href="https://dpo.si.edu/" title="Link to the website of the Digitization Program Office">Digitization Program Office</a>, a division of the Smithsonian's Office of Digital Transformation.</p>
<div class="row">
<div class="col">
<p style="font-size: large;"><img src="{{ url_for('static', filename='osprey_logo_200.png') }}" alt="Osprey Application Logo"> <strong>Osprey - DPO Collections Digitization Dashboard</strong> - version {{ site_ver }}</p>
</div>
</div>

<div class="row">
<div class="col">

{% if site_net == "internal" %}<p><strong>This is the SI-Internal instance</strong></p>{% endif %}

<p>Osprey is an open-source application and the source is hosted
at <a href="https://github.com/Smithsonian/Osprey" target="_blank" rel="noopener noreferrer" title="Opens in new window">https://github.com/Smithsonian/Osprey
<i class="small fa-solid fa-arrow-up-right-from-square"></i><span class="screen-reader-only">(link is external)</span></a></p>

<p><strong>Important Note:</strong> Osprey is <strong>not</strong> 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.</p>

{% if site_net == "internal" %}
<p>This is a project of the: <a href="https://sinet.sharepoint.com/sites/DPO" title="Link to the SharePoint site of the Digitization Program Office">Digitization Program Office</a>, a division of the Smithsonian's <a href="https://sinet.sharepoint.com/sites/ODT" class="bg-white" title="Link to the Office of Digital Transformation
">Office of Digital Transformation</a> (formerly a division of the Office of the Chief Information Officer).</p>
{% else %}
<p>This is a project of the: <a href="https://dpo.si.edu/" title="Link to the website of the Digitization Program Office">Digitization Program Office</a>, a division of the Smithsonian's Office of Digital Transformation.</p>

{% endif %}
</div>
<div class="col">
{% if site_net == "internal" %}
<p>There is an API available (JSON). Please contact Luis J. Villanueva, DPO, for an API key.</p>
{% endif %}

<br><br>

<p>Special thanks to:</p>
<ul>
<li>OCIO for hosting our servers and supporting the infrastructure we use in our projects</li>
<li>The DAMS team for sharing their data</li>
<li>The Osprey (<em>Pandion haliaetus</em>) silhouette image is from Phylopic (<a href="https://www.phylopic.org/images/8353477c-dc5d-44b6-ab3c-9d0cdf4d64f7/pandion-haliaetus">link to source</a>)</li>
</ul>
</div>
</div>

{% endif %}

<br><br>

{% if site_net == "internal" %}
<p>There is an API available (JSON). Please contact Luis J. Villanueva, DPO, for an API key.</p>
{% endif %}

<br><br>

<p>Special thanks to:</p>
<ul>
<li>OCIO for hosting our servers and supporting the infrastructure we use in our projects</li>
<li>The DAMS team for sharing their data</li>
<li>The Osprey (<em>Pandion haliaetus</em>) silhouette image is from Phylopic (<a href="https://www.phylopic.org/images/8353477c-dc5d-44b6-ab3c-9d0cdf4d64f7/pandion-haliaetus">link to source</a>)</li>
</ul>

<br>

{% endblock %}
2 changes: 1 addition & 1 deletion web_app/templates/file.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h1 class="navbar-brand navtitle">Details of {{ file_details.file_name }}</h1>
<div class="col">
<p style="text-align: right;">
<a class="btn btn-primary btn-sm{% if file_details.prev_id %}" href="{{ url_for('file', file_id=file_details.prev_id) }}{% else %} disabled" href="#{% endif %}" role="button">
<i class="fa-solid fa-chevron-left"></i> Prev File</a>
<i class="fa-solid fa-chevron-left"></i> Prev File</a>&nbsp;
<a class="btn btn-primary btn-sm{% if file_details.next_id %}" href="{{ url_for('file', file_id=file_details.next_id) }}{% else %} disabled" href="#{% endif %}" role="button">
Next File <i class="fa-solid fa-chevron-right"></i></a>
<br><small>(by alphabetical order)</small>
Expand Down
2 changes: 1 addition & 1 deletion web_app/templates/new_project.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ <h4>File checks:</h4>
<div class="mb-3">
<label for="p_unitstaff" class="form-label">Unit Staff<br>
<small>(Who will have access to QC the project? Comma-separated SI usernames, without the @si.edu part.)</small></label>
<input class="form-control" type="text" name="p_unitstaff" id="p_unitstaff">
<input class="form-control" type="text" name="p_unitstaff" id="p_unitstaff" disabled>
</div>
<div class="mb-3">
<label for="p_manager" class="form-label">Project Manager</label>
Expand Down

0 comments on commit 35cc801

Please sign in to comment.