From 0991ea75cc7b265389aa8362414a305ba532d31a Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 28 Jun 2020 12:45:34 -0700 Subject: [PATCH] Renamed _timestamp to _now, refs #842, closes #871 --- datasette/default_magic_parameters.py | 4 ++-- docs/changelog.rst | 2 +- docs/sql_queries.rst | 8 ++++---- tests/fixtures.py | 2 +- tests/test_canned_queries.py | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/datasette/default_magic_parameters.py b/datasette/default_magic_parameters.py index ac7c5eac..b788fee8 100644 --- a/datasette/default_magic_parameters.py +++ b/datasette/default_magic_parameters.py @@ -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), ] diff --git a/docs/changelog.rst b/docs/changelog.rst index db51423e..55f274a8 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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 `__) - New :ref:`plugin_hook_register_magic_parameters` plugin hook. diff --git a/docs/sql_queries.rst b/docs/sql_queries.rst index aff16c1a..dd7743cf 100644 --- a/docs/sql_queries.rst +++ b/docs/sql_queries.rst @@ -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 diff --git a/tests/fixtures.py b/tests/fixtures.py index f3fdc468..d103fa35 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -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( """ diff --git a/tests/test_canned_queries.py b/tests/test_canned_queries.py index 3942dc98..2e064db1 100644 --- a/tests/test_canned_queries.py +++ b/tests/test_canned_queries.py @@ -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}$"), ],