|
@@ -405,3 +405,79 @@ There are probably three places in your code, which have to be changed:
|
|
|
1. Creation: Instead of using `strftime("%d %b %Y %H:%M")`, you can now store the datetime directly in the "data" field. We've implemented a new helper `wagtail.utils.timestamps.ensure_utc()`, which ensures the correct timezone (UTC).
|
|
|
2. Display: To display the timestamp in the user's timezone and format with a `LogFormatter`, we've created utils to parse (`wagtail.utils.timestamps.parse_datetime_localized()`) and render (`wagtail.utils.timestamps.render_timestamp()`) those timestamps. Look at the existing formatters [here](https://github.com/wagtail/wagtail/blob/main/wagtail/wagtail_hooks.py).
|
|
|
3. Migration: You can use the code of the above migration ([source](https://github.com/wagtail/wagtail/blob/main/wagtail/migrations/0088_fix_log_entry_json_timestamps.py)) as a guideline to migrate your existing timestamps in the database.
|
|
|
+
|
|
|
+### Header searching now relies on data attributes
|
|
|
+
|
|
|
+Previously the header search relied on inline scripts and a `window.headerSearch` global to activate the behaviour. This has now changed to a data attributes approach and the window global usage will be removed in a future major release.
|
|
|
+
|
|
|
+If you are using the documented Wagtail [viewsets](viewsets_reference), Snippets or `ModelAdmin` approaches to building custom admin views, there should be no change required.
|
|
|
+
|
|
|
+If you are using the shared header template include for a custom search integration, here's how to adopt the new approach.
|
|
|
+
|
|
|
+#### Header include before
|
|
|
+
|
|
|
+```html+django
|
|
|
+{% extends "wagtailadmin/base.html" %}
|
|
|
+{% load wagtailadmin_tags %}
|
|
|
+{% block extra_js %}
|
|
|
+ {{ block.super }}
|
|
|
+ <script>
|
|
|
+ window.headerSearch = {
|
|
|
+ url: "{% url 'myapp:search_results' %}",
|
|
|
+ termInput: '#id_q',
|
|
|
+ targetOutput: '#my-results',
|
|
|
+ };
|
|
|
+ </script>
|
|
|
+{% endblock %}
|
|
|
+{% block content %}
|
|
|
+ {% include "wagtailadmin/shared/header.html" with title="my title" search_url="myapp:index" %}
|
|
|
+ ... other content
|
|
|
+{% endblock %}
|
|
|
+```
|
|
|
+
|
|
|
+#### Header include after
|
|
|
+
|
|
|
+Note: No need for `extra_js` usage at all.
|
|
|
+
|
|
|
+```html+django
|
|
|
+{% extends "wagtailadmin/base.html" %}
|
|
|
+{% load wagtailadmin_tags %}
|
|
|
+{% block content %}
|
|
|
+ {% url 'myapp:search_results' as search_results_url %}
|
|
|
+ {% include "wagtailadmin/shared/header.html" with title="my title" search_url="myapp:index" search_results_url=search_results_url search_target="#my-results" %}
|
|
|
+ ... other content
|
|
|
+{% endblock %}
|
|
|
+```
|
|
|
+
|
|
|
+Alternatively, if you have customisations that manually declare or override `window.headerSearch`, here's how to adopt the new approach.
|
|
|
+
|
|
|
+#### Manual usage before
|
|
|
+
|
|
|
+```html
|
|
|
+<script>
|
|
|
+ window.headerSearch = {
|
|
|
+ url: '{{ my_async_results_url }}',
|
|
|
+ termInput: '#id_q',
|
|
|
+ targetOutput: '#some-results',
|
|
|
+ };
|
|
|
+</script>
|
|
|
+<form role="search">
|
|
|
+ <input type="text" name="q" id="id_q" />
|
|
|
+</form>
|
|
|
+<div id="some-results"></div>
|
|
|
+```
|
|
|
+
|
|
|
+#### Manual usage after
|
|
|
+
|
|
|
+```html
|
|
|
+<form
|
|
|
+ role="search"
|
|
|
+ data-controller="w-swap"
|
|
|
+ data-action="change->w-swap#searchLazy input->w-swap#searchLazy"
|
|
|
+ data-w-swap-src-value="{{ my_async_results_url }}"
|
|
|
+ data-w-swap-target-value="#some-results"
|
|
|
+>
|
|
|
+ <input type="text" name="q" data-w-swap-target="input" id="id_q" data-w-swap-target="input" />
|
|
|
+</form>
|
|
|
+<div id="some-results"></div>
|
|
|
+```
|