switch to absolute times when old enough
This commit is contained in:
@@ -848,40 +848,30 @@ def utility_processor():
|
|||||||
# Try the sane thing first
|
# Try the sane thing first
|
||||||
dt = (n - t) // 10**9
|
dt = (n - t) // 10**9
|
||||||
if dt < 1:
|
if dt < 1:
|
||||||
return "less than a second"
|
return "less than a second ago"
|
||||||
if dt < 2:
|
if dt < 2:
|
||||||
return f"1 second"
|
return f"1 second ago"
|
||||||
if dt < 60:
|
if dt < 60:
|
||||||
return f"{dt} seconds"
|
return f"{dt} seconds ago"
|
||||||
if dt < 119:
|
if dt < 119:
|
||||||
return f"1 minute"
|
return f"1 minute ago"
|
||||||
if dt < 3600:
|
if dt < 3600:
|
||||||
return f"{dt // 60} minutes"
|
return f"{dt // 60} minutes ago"
|
||||||
if dt < 3600 * 2:
|
|
||||||
return f"1 hour"
|
|
||||||
if dt < 3600 * 24:
|
if dt < 3600 * 24:
|
||||||
return f"{dt // 3600} hours"
|
return f"{dt // 3600} hours ago"
|
||||||
|
if dt < 3600 * 24 * 7:
|
||||||
|
return f"{dt // (3600 * 24)} days ago"
|
||||||
if dt < 3600 * 24 * 31:
|
if dt < 3600 * 24 * 31:
|
||||||
return f"{dt // (3600 * 24)} days"
|
return f"{dt // (3600 * 24 * 7)} weeks ago"
|
||||||
|
|
||||||
# Try some very rough estimate, whatever
|
as_datetime = datetime.fromtimestamp(t // 10**9)
|
||||||
f = lambda x: datetime.utcfromtimestamp(x // 10**9)
|
return as_datetime.strftime("%Y-%m-%d %H:%M")
|
||||||
n, t = f(n), f(t)
|
|
||||||
|
|
||||||
def f(x, y, s):
|
|
||||||
return f'{y - x} {s}{"s" if y - x > 1 else ""}'
|
|
||||||
|
|
||||||
if t.year < n.year:
|
|
||||||
return f(t.year, n.year, "year")
|
|
||||||
if t.month < n.month:
|
|
||||||
return f(t.month, n.month, "month")
|
|
||||||
assert False, "unreachable"
|
|
||||||
|
|
||||||
def format_since(t):
|
def format_since(t):
|
||||||
n = time.time_ns()
|
n = time.time_ns()
|
||||||
if n < t:
|
if n < t:
|
||||||
return "in a distant future"
|
return "in a distant future"
|
||||||
return _format_time_delta(n, t) + " ago"
|
return _format_time_delta(n, t)
|
||||||
|
|
||||||
def format_until(t):
|
def format_until(t):
|
||||||
n = time.time_ns()
|
n = time.time_ns()
|
||||||
@@ -890,7 +880,7 @@ def utility_processor():
|
|||||||
return _format_time_delta(t, n)
|
return _format_time_delta(t, n)
|
||||||
|
|
||||||
def format_time(t):
|
def format_time(t):
|
||||||
return datetime.utcfromtimestamp(t / 10**9).replace(microsecond=0)
|
return datetime.fromtimestamp(t / 10**9).replace(microsecond=0)
|
||||||
|
|
||||||
def rand_password():
|
def rand_password():
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -57,10 +57,11 @@ th, td {
|
|||||||
|
|
||||||
textarea {
|
textarea {
|
||||||
width: min(100%, 500px);
|
width: min(100%, 500px);
|
||||||
height: 15em;
|
height: 25em;
|
||||||
font-size: 1em;
|
font-size: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
input[type=text], input[type=password] {
|
input[type=text], input[type=password] {
|
||||||
width: min(100%, 20em);
|
width: min(100%, 20em);
|
||||||
font-family: monospace;
|
font-family: monospace;
|
||||||
@@ -211,8 +212,21 @@ table.form > * > tr > td, th {
|
|||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Admin */
|
/* Admin */
|
||||||
.admin_h2 {
|
.admin_h2 {
|
||||||
background-color: rgba(0,0,0,0.15);
|
background-color: rgba(0,0,0,0.15);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
main.admin {
|
||||||
|
width: 95%;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
main.admin textarea {
|
||||||
|
height: 5em;
|
||||||
|
}
|
||||||
|
.config_label {
|
||||||
|
max-width: 15em;
|
||||||
|
width: 15em;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,13 +11,18 @@
|
|||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<nav>
|
||||||
|
<div>
|
||||||
|
<span> « </span><a href="{{ url_for('index') }}">Forum Home</a>
|
||||||
|
<span> | </span><a href="{{ url_for('admin') }}">Admin panel</a>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
<main class=admin>
|
||||||
<h1>{{ title }}</h1>
|
<h1>{{ title }}</h1>
|
||||||
<p>
|
|
||||||
<span> « </span><a href="{{ url_for('index') }}">Forum Home</a>
|
|
||||||
<span> | </span><a href="{{ url_for('admin') }}">Admin panel</a>
|
|
||||||
</p>
|
|
||||||
{%- for category, msg in get_flashed_messages(True) -%}
|
{%- for category, msg in get_flashed_messages(True) -%}
|
||||||
<p class="flash {{ category }}">{{ msg }}</p>
|
<p class="flash {{ category }}">{{ msg }}</p>
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
{%- block content %}{% endblock -%}
|
{%- block content %}{% endblock -%}
|
||||||
|
</main>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -44,8 +44,8 @@
|
|||||||
<h3>Add user</h3>
|
<h3>Add user</h3>
|
||||||
<form method=post action=user/new/>
|
<form method=post action=user/new/>
|
||||||
<table>
|
<table>
|
||||||
<tr><td>Name</td><td><input type=text name=name></td></tr>
|
<tr><td class=config_label>Name</td><td><input type=text name=name></td></tr>
|
||||||
<tr><td>Password</td><td><input type=password name=password></td></tr>
|
<tr><td class=config_label>Password</td><td><input type=password name=password></td></tr>
|
||||||
</table>
|
</table>
|
||||||
<input type=submit value="Add user">
|
<input type=submit value="Add user">
|
||||||
</form>
|
</form>
|
||||||
@@ -82,11 +82,11 @@
|
|||||||
<form method=post action="forum/new/">
|
<form method=post action="forum/new/">
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Name</td>
|
<td class=config_label>Name</td>
|
||||||
<td><input type=text name=name></td>
|
<td><input type=text name=name></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Description</td>
|
<td class=config_label>Description</td>
|
||||||
<td><textarea name=description></textarea></td>
|
<td><textarea name=description></textarea></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
@@ -99,27 +99,27 @@
|
|||||||
<form action=config/edit/ method=post>
|
<form action=config/edit/ method=post>
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Server name</td>
|
<td class=config_label>Server name</td>
|
||||||
<td><input type=text name=server_name value="{{ config.server_name }}"></td>
|
<td><input type=text name=server_name value="{{ config.server_name }}"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Server description</td>
|
<td class=config_label>Server description</td>
|
||||||
<td><textarea name=server_description>{{ config.server_description }}</textarea></td>
|
<td><textarea name=server_description>{{ config.server_description }}</textarea></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Registration enabled</td>
|
<td class=config_label>Registration enabled</td>
|
||||||
<td><input name=registration_enabled type=checkbox {{ 'checked' if config.registration_enabled else '' }}></td>
|
<td><input name=registration_enabled type=checkbox {{ 'checked' if config.registration_enabled else '' }}></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Login required</td>
|
<td class=config_label>Login required</td>
|
||||||
<td><input name=login_required type=checkbox {{ 'checked' if config.login_required else '' }}></td>
|
<td><input name=login_required type=checkbox {{ 'checked' if config.login_required else '' }}></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Number of threads per page</td>
|
<td class=config_label>Number of threads per page</td>
|
||||||
<td><input type=number name=threads_per_page value="{{ config.threads_per_page }}"></td>
|
<td><input type=number name=threads_per_page value="{{ config.threads_per_page }}"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>User defined CSS file in static/ folder</td>
|
<td class=config_label>User defined CSS file in static/ folder</td>
|
||||||
<td><input type=text name=user_css value="{{ config.user_css }}"></td>
|
<td><input type=text name=user_css value="{{ config.user_css }}"></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
Reference in New Issue
Block a user