Skip to content

Commit

Permalink
Implemented #153: Admin: Show last indexing status on the Review page
Browse files Browse the repository at this point in the history
  • Loading branch information
m-i-l committed Jun 19, 2024
1 parent 5c44630 commit f2910cf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/web/content/dynamic/searchmysite/admin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import psycopg2.extras
from searchmysite.admin.auth import login_required, admin_required
from searchmysite.db import get_db
from searchmysite.adminutils import delete_domain, delete_domain_from_solr
from searchmysite.adminutils import delete_domain, delete_domain_from_solr, get_most_recent_indexing_log_message
import config
import searchmysite.sql

Expand Down Expand Up @@ -40,14 +40,18 @@ def review():
review_form = [] # Form will be constructed from a list of dicts, where the dict will have domain, home, category, date and actions values, and actions will be a list
count = 0
for result in results:
# Construct actions list
count += 1
actions = []
name = 'domain'+str(count)
for action in actions_list:
action_id = name+action['id']
action_value = result['domain']+':'+action['value']
actions.append({'id':action_id, 'name':name, 'value':action_value, 'checked':action['checked'], 'label':action['label']})
review_form.append({'domain':result['domain'], 'home':result['home_page'], 'category':result['category'], 'date':result['domain_first_submitted'], 'actions':actions})
# Determine status of last index (or NEW if no last index)
status = get_most_recent_indexing_log_message(result['domain'])
# Append to review_form list of dicts
review_form.append({'domain':result['domain'], 'home':result['home_page'], 'category':result['category'], 'date':result['domain_first_submitted'].strftime('%d %b %Y, %H:%M'), 'status':status, 'actions':actions})
return render_template('admin/review.html', results=results, review_form=review_form)
else: # i.e. if POST
if results:
Expand Down
12 changes: 12 additions & 0 deletions src/web/content/dynamic/searchmysite/adminutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ def select_indexed_domains():
indexed_domains.append(result['domain'])
return indexed_domains

# Returns the most recent completed indexing message from the indexing log, or NEW if none
def get_most_recent_indexing_log_message(domain):
conn = get_db()
cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
cursor.execute(searchmysite.sql.sql_select_indexing_log_message, (domain,))
last_indexing_log_message = cursor.fetchone()
if last_indexing_log_message:
message = last_indexing_log_message['message']
else:
message = 'NEW'
return message

# Get the actual host URL, for use in links which need to contain the servername and protocol
# This will be 'http://127.0.0.1:5000/' if run in Flask and 'http://127.0.0.1:8080/' if run in Apache httpd + mod_wsgi
# If run behind a reverse proxy, production will also be 'http://127.0.0.1:8080/',
Expand Down
2 changes: 2 additions & 0 deletions src/web/content/dynamic/searchmysite/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@
"indexing_disabled_changed = NOW() "\
"WHERE domain = (%s);"

sql_select_indexing_log_message = "SELECT domain, message FROM tblindexinglog WHERE domain IN ((%s)) AND status = 'COMPLETE' ORDER BY timestamp DESC LIMIT 1;"


# SQL for admin/auth.py
# ---------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
<table class="table">
<thead>
<tr>
<th scope="col">Domain</th>
<th scope="col">Home</th>
<th scope="col">Site</th>
<th scope="col">Category</th>
<th scope="col">Date</th>
<th scope="col">Status</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
{% for site in review_form %}
<tr>
<td>{{ site['domain'] }}</td>
<td><a href="{{ site['home'] }}" target="_blank" rel="noopener noreferrer">{{ site['home'] }}</a></td>
<td>{{ site['domain'] }}<br/><a href="{{ site['home'] }}" target="_blank" rel="noopener noreferrer">{{ site['home'] }}</a></td>
<td>{{ site['category'] }}</td>
<td>{{ site['date'] }}</td>
<td>{{ site['status'] }}</td>
<td>
{% for action in site['actions'] %}
<div class="form-check">
Expand Down

0 comments on commit f2910cf

Please sign in to comment.