mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
parent
99fba0fad3
commit
0991ea75cc
5 changed files with 11 additions and 11 deletions
|
|
@ -21,7 +21,7 @@ def cookie(key, request):
|
||||||
return request.cookies[key]
|
return request.cookies[key]
|
||||||
|
|
||||||
|
|
||||||
def timestamp(key, request):
|
def now(key, request):
|
||||||
if key == "epoch":
|
if key == "epoch":
|
||||||
return int(time.time())
|
return int(time.time())
|
||||||
elif key == "date_utc":
|
elif key == "date_utc":
|
||||||
|
|
@ -50,6 +50,6 @@ def register_magic_parameters():
|
||||||
("header", header),
|
("header", header),
|
||||||
("actor", actor),
|
("actor", actor),
|
||||||
("cookie", cookie),
|
("cookie", cookie),
|
||||||
("timestamp", timestamp),
|
("now", now),
|
||||||
("random", random),
|
("random", random),
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ Changelog
|
||||||
insert into logs
|
insert into logs
|
||||||
(user_id, timestamp)
|
(user_id, timestamp)
|
||||||
values
|
values
|
||||||
(:_actor_id, :_timestamp_datetime_utc)
|
(:_actor_id, :_now_datetime_utc)
|
||||||
|
|
||||||
This inserts the currently authenticated actor ID and the current datetime. (`#842 <https://github.com/simonw/datasette/issues/842>`__)
|
This inserts the currently authenticated actor ID and the current datetime. (`#842 <https://github.com/simonw/datasette/issues/842>`__)
|
||||||
- New :ref:`plugin_hook_register_magic_parameters` plugin hook.
|
- New :ref:`plugin_hook_register_magic_parameters` plugin hook.
|
||||||
|
|
|
||||||
|
|
@ -292,13 +292,13 @@ Available magic parameters are:
|
||||||
``_cookie_*`` - e.g. ``_cookie_lang``
|
``_cookie_*`` - e.g. ``_cookie_lang``
|
||||||
The value of the incoming cookie of that name.
|
The value of the incoming cookie of that name.
|
||||||
|
|
||||||
``_timestamp_epoch``
|
``_now_epoch``
|
||||||
The number of seconds since the Unix epoch.
|
The number of seconds since the Unix epoch.
|
||||||
|
|
||||||
``_timestamp_date_utc``
|
``_now_date_utc``
|
||||||
The date in UTC, e.g. ``2020-06-01``
|
The date in UTC, e.g. ``2020-06-01``
|
||||||
|
|
||||||
``_timestamp_datetime_utc``
|
``_now_datetime_utc``
|
||||||
The ISO 8601 datetime in UTC, e.g. ``2020-06-24T18:01:07Z``
|
The ISO 8601 datetime in UTC, e.g. ``2020-06-24T18:01:07Z``
|
||||||
|
|
||||||
``_random_chars_*`` - e.g. ``_random_chars_128``
|
``_random_chars_*`` - e.g. ``_random_chars_128``
|
||||||
|
|
@ -318,7 +318,7 @@ Here's an example configuration (this time using ``metadata.yaml`` since that pr
|
||||||
INSERT INTO messages (
|
INSERT INTO messages (
|
||||||
user_id, ip, message, datetime
|
user_id, ip, message, datetime
|
||||||
) VALUES (
|
) VALUES (
|
||||||
:_actor_id, :_request_ip, :message, :_timestamp_datetime_utc
|
:_actor_id, :_request_ip, :message, :_now_datetime_utc
|
||||||
)
|
)
|
||||||
write: true
|
write: true
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -461,7 +461,7 @@ METADATA = {
|
||||||
"queries": {
|
"queries": {
|
||||||
"𝐜𝐢𝐭𝐢𝐞𝐬": "select id, name from facet_cities order by id limit 1;",
|
"𝐜𝐢𝐭𝐢𝐞𝐬": "select id, name from facet_cities order by id limit 1;",
|
||||||
"pragma_cache_size": "PRAGMA cache_size;",
|
"pragma_cache_size": "PRAGMA cache_size;",
|
||||||
"magic_parameters": "select :_header_user_agent as user_agent, :_timestamp_datetime_utc as datetime",
|
"magic_parameters": "select :_header_user_agent as user_agent, :_now_datetime_utc as datetime",
|
||||||
"neighborhood_search": {
|
"neighborhood_search": {
|
||||||
"sql": textwrap.dedent(
|
"sql": textwrap.dedent(
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -187,9 +187,9 @@ def magic_parameters_client():
|
||||||
("_actor_id", "root"),
|
("_actor_id", "root"),
|
||||||
("_header_host", "localhost"),
|
("_header_host", "localhost"),
|
||||||
("_cookie_foo", "bar"),
|
("_cookie_foo", "bar"),
|
||||||
("_timestamp_epoch", r"^\d+$"),
|
("_now_epoch", r"^\d+$"),
|
||||||
("_timestamp_date_utc", r"^\d{4}-\d{2}-\d{2}$"),
|
("_now_date_utc", r"^\d{4}-\d{2}-\d{2}$"),
|
||||||
("_timestamp_datetime_utc", r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$"),
|
("_now_datetime_utc", r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$"),
|
||||||
("_random_chars_1", r"^\w$"),
|
("_random_chars_1", r"^\w$"),
|
||||||
("_random_chars_10", r"^\w{10}$"),
|
("_random_chars_10", r"^\w{10}$"),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue