kopia lustrzana https://github.com/simonw/datasette
rodzic
99fba0fad3
commit
0991ea75cc
|
@ -21,7 +21,7 @@ def cookie(key, request):
|
|||
return request.cookies[key]
|
||||
|
||||
|
||||
def timestamp(key, request):
|
||||
def now(key, request):
|
||||
if key == "epoch":
|
||||
return int(time.time())
|
||||
elif key == "date_utc":
|
||||
|
@ -50,6 +50,6 @@ def register_magic_parameters():
|
|||
("header", header),
|
||||
("actor", actor),
|
||||
("cookie", cookie),
|
||||
("timestamp", timestamp),
|
||||
("now", now),
|
||||
("random", random),
|
||||
]
|
||||
|
|
|
@ -16,7 +16,7 @@ Changelog
|
|||
insert into logs
|
||||
(user_id, timestamp)
|
||||
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>`__)
|
||||
- New :ref:`plugin_hook_register_magic_parameters` plugin hook.
|
||||
|
|
|
@ -292,13 +292,13 @@ Available magic parameters are:
|
|||
``_cookie_*`` - e.g. ``_cookie_lang``
|
||||
The value of the incoming cookie of that name.
|
||||
|
||||
``_timestamp_epoch``
|
||||
``_now_epoch``
|
||||
The number of seconds since the Unix epoch.
|
||||
|
||||
``_timestamp_date_utc``
|
||||
``_now_date_utc``
|
||||
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``
|
||||
|
||||
``_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 (
|
||||
user_id, ip, message, datetime
|
||||
) VALUES (
|
||||
:_actor_id, :_request_ip, :message, :_timestamp_datetime_utc
|
||||
:_actor_id, :_request_ip, :message, :_now_datetime_utc
|
||||
)
|
||||
write: true
|
||||
|
||||
|
|
|
@ -461,7 +461,7 @@ METADATA = {
|
|||
"queries": {
|
||||
"𝐜𝐢𝐭𝐢𝐞𝐬": "select id, name from facet_cities order by id limit 1;",
|
||||
"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": {
|
||||
"sql": textwrap.dedent(
|
||||
"""
|
||||
|
|
|
@ -187,9 +187,9 @@ def magic_parameters_client():
|
|||
("_actor_id", "root"),
|
||||
("_header_host", "localhost"),
|
||||
("_cookie_foo", "bar"),
|
||||
("_timestamp_epoch", r"^\d+$"),
|
||||
("_timestamp_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_epoch", r"^\d+$"),
|
||||
("_now_date_utc", r"^\d{4}-\d{2}-\d{2}$"),
|
||||
("_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_10", r"^\w{10}$"),
|
||||
],
|
||||
|
|
Ładowanie…
Reference in New Issue