move timestamp formating to template filter

This commit is contained in:
GroovieGermanikus 2023-12-11 10:57:42 +01:00
parent 531bfcb4d4
commit 2d075af21b
No known key found for this signature in database
GPG Key ID: 5B6EB831A5CD2015
5 changed files with 14 additions and 19 deletions

12
app.py
View File

@ -8,6 +8,7 @@ import recent_blocks_database
import block_details_database
import config
import locale
from datetime import datetime
#
# MAIN
@ -204,3 +205,14 @@ def mapcount_filter(number: int):
print("FIELD_ERROR in template filter")
return "FIELD_ERROR"
@webapp.template_filter('timestamp')
def timestamp_filter(dt: datetime):
if dt is None:
return None
else:
try:
return dt.strftime('%a %d %H:%M:%S.%f')
except TypeError:
print("FIELD_ERROR in template filter")
return "FIELD_ERROR"

View File

@ -23,7 +23,7 @@
<td>
<div class="align-items-center">
<span class="font-monospace text-muted">
{{ tx.timestamp_formatted or '--' }}
{{ tx.utc_timestamp or '--' }}
</span>
</div>
</td>

View File

@ -67,7 +67,7 @@
</tr>
<tr>
<td class="w-100">UTC timestamp</td>
<td class="text-lg-end font-monospace"><span>{{ transaction.timestamp_formatted }}</span></td>
<td class="text-lg-end font-monospace"><span>{{ transaction.utc_timestamp | timestamp }}</span></td>
</tr>
</tbody>
</table>

View File

@ -39,7 +39,6 @@ def run_query():
for index, row in enumerate(maprows):
row['pos'] = index + 1
map_jsons_in_row(row)
map_timestamps(row)
return maprows
@ -73,18 +72,10 @@ def find_transaction_by_sig(tx_sig: str):
for row in maprows:
map_jsons_in_row(row)
map_timestamps(row)
return maprows
def map_timestamps(row):
# type datetime.datetime
dt = row['utc_timestamp']
if dt is not None:
row['timestamp_formatted'] = dt.strftime('%a %d %H:%M:%S.%f')
def map_jsons_in_row(row):
errors = []
if row["all_errors"] is None:

View File

@ -35,8 +35,6 @@ def find_transaction_details_by_sig(tx_sig: str):
if maprows:
row = maprows[0]
map_timestamps(row)
# {'transaction_id': 1039639, 'slot': 234765028, 'error': 34, 'count': 1, 'utc_timestamp': datetime.datetime(2023, 12, 8, 18, 29, 23, 861619)}
tx_slots = postgres_connection.query(
"""
@ -107,10 +105,4 @@ def invert_by_slot(rows):
inv_indx[row["slot"]].append(row)
return inv_indx
# TODO format to MON DD HH24:MI:SS.MS
def map_timestamps(row):
# type datetime.datetime
dt = row['utc_timestamp']
if dt is not None:
row['timestamp_formatted'] = dt.strftime('%a %d %H:%M:%S.%f')