Easier sharing of Wagtail drafts
Project description
wagtail-sharing
Easier sharing of Wagtail drafts.
Wagtail Sharing makes it easier to share Wagtail draft content for review by users who don’t have access to the Wagtail admin site. It allows you to define an alternate hostname and/or port on which to expose the latest revision of all of your Wagtail pages.
For example, let’s say your Wagtail site is running on http://mysite.com. You’ve created a draft page at slug /path/to/draft, but haven’t yet published it. Wagtail Sharing lets you expose that draft page at some other domain, for example http://sharing.mysite.com/path/to/draft.
In another use case, you might have a published page at http://mysite.com/already/published/page, and you’ve made some draft changes. Wagtail Sharing lets you expose those draft changes at http://sharing.mysite.com/already/published/page while still keeping the same published content at your regular domain.
These examples obviously work best when you have some method of restricting access to http://sharing.mysite.com, for example by only exposing that subdomain on a private network.
Wagtail Sharing lets you create separate sharing sites for each Wagtail Site you have defined. It also supports a configurable visual banner on shared pages to remind reviewers that content may differ from your published site.
This new logic only applies to GET requests. Other HTTP methods like POST defer to standard Wagtail handling.
Setup
Install the package using pip:
$ pip install wagtail-sharing
Add wagtailsharing as an installed app in your Django settings:
# in settings.py
INSTALLED_APPS = (
...
'wagtailsharing',
...
)
wagtail.snippets is also required and must be included in your list of installed apps.
The code examples below assume that you are using a recent Wagtail version (3.0+).
Run migrations to create required database tables:
$ python manage.py migrate wagtailsharing
Replace use of Wagtail’s catch-all URL pattern:
# in urls.py
-from wagtail import urls as wagtail_urls
+from wagtailsharing import urls as wagtailsharing_urls
...
-urlpatterns.append(url(r'', include(wagtail_urls)))
+urlpatterns.append(url(r'', include(wagtailsharing_urls)))
Creating a new sharing site
After following the setup steps above, you should be able to create a new sharing site to use this functionality in a local Django development server. Let’s assume that you are running your local development server on the default port 8000, and that pages there are being served at http://localhost:8000. We want to create a new sharing site at http://sharing.localhost:8000 at which latest page revisions will be exposed.
To simulate accessing your site on a different hostname, you’ll need to loosen Django’s default security settings that only allow access on localhost. Edit your settings file (e.g. myproject/settings/local.py) to add the following:
ALLOWED_HOSTS = ['*']
Verify that you can access your local server at http://sharing.localhost:8000. You should see the same content there as on http://localhost:8000, as you haven’t enabled wagtail-sharing for the default site yet.
To do so, in the Wagtail admin, under Settings, Sharing Sites, create a new sharing site for the default site, with hostname sharing.localhost and port 8000.
Your latest page revisions (including drafts) should now be available at http://sharing.localhost:8000.
Hooks
As with normal page serving, the serving of shared pages continues to respect Wagtail’s built-in before_serve_page hook.
This project adds these additional hooks:
before_route_page
Called when routing, before a page’s route() method is called. This hook is passed the request and the page that will have route() called on it. If the callable returns an HttpResponse, that response will be returned immediately to the user.
This hook allows for any necessary customization of Wagtail’s built-in routing behavior, for example to support ShareableRoutablePageMixin.
Mixins
By default, Wagtail’s RoutablePageMixin is not compatible with Wagtail-Sharing, instead you need to use ShareableRoutablePageMixin in order to view share draft content fields on routable pages.
ShareableRoutablePageMixin is used exactly the same way as RoutablePageMixin:
from wagtail.fields import RichTextField
from wagtail.models import Page
from wagtail.contrib.routable_page.models import route
from wagtailsharing.models import ShareableRoutablePageMixin
class EventIndexPage(ShareableRoutablePageMixin, Page):
intro = RichTextField()
@route(r'^$')
def current_events(self, request):
# …
@route(r'^past/$')
def past_events(self, request):
# …
Compatibility
This project has been tested for compatibility with:
Python 3.9+
Django 3.2+
Wagtail 5.1+ (see past releases for older Wagtail support)
It should be compatible with all intermediate versions, as well. If you find that it is not, please file an issue.
Testing
Running project unit tests requires tox:
$ tox
To run the test app interactively, run:
$ tox -e interactive
Now you can visit http://localhost:8000/admin/ in a browser and log in with admin / changeme.
Open source licensing info
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file wagtail-sharing-2.12.1.tar.gz
.
File metadata
- Download URL: wagtail-sharing-2.12.1.tar.gz
- Upload date:
- Size: 18.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b3e5dae312b2c35916dabc8afc21884582cfe5407b279944435efbba266eba1 |
|
MD5 | c1e2f2348a056a608d65b817b7ccd3d5 |
|
BLAKE2b-256 | cd48d1be34759512bd6e4161178b2d78cc50d87b0231a2cdd369e52d16239adc |
File details
Details for the file wagtail_sharing-2.12.1-py3-none-any.whl
.
File metadata
- Download URL: wagtail_sharing-2.12.1-py3-none-any.whl
- Upload date:
- Size: 25.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 189f2dd8e6862f3ef8eaff8b4df954c19b2a14f9848a49ef51e8abfaa5ae9847 |
|
MD5 | b5e8cb32ee39f11020ff9f69f194b44f |
|
BLAKE2b-256 | 56a205bc35a59188a48fe8f080c691f0c5304f72570006d69a3bd982286138e4 |