All Projects → cfpb → wagtail-sharing

cfpb / wagtail-sharing

Licence: CC0-1.0 license
Easier sharing of Wagtail drafts

Programming Languages

python
139335 projects - #7 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to wagtail-sharing

Reddit Wallpaper Changer
Reddit Wallpaper Changer
Stars: ✭ 96 (+108.7%)
Mutual labels:  wagtail
Wagalytics
A Google Analytics dashboard in your Wagtail admin
Stars: ✭ 176 (+282.61%)
Mutual labels:  wagtail
wagtailenforcer
The Wagtail arm of the law - enforce security protocols on your Wagtail site
Stars: ✭ 43 (-6.52%)
Mutual labels:  wagtail
Awesome Wagtail
A curated list of awesome packages, articles, and other cool resources from the Wagtail community.
Stars: ✭ 1,527 (+3219.57%)
Mutual labels:  wagtail
Django Salesman
Headless e-commerce framework for Django.
Stars: ✭ 157 (+241.3%)
Mutual labels:  wagtail
django-hyper-editor
Django Integration of Hyper Editor
Stars: ✭ 29 (-36.96%)
Mutual labels:  wagtail
Wagtail Geo Widget
Wagtail-Geo-Widget is the complete map solution for your Wagtail site.
Stars: ✭ 90 (+95.65%)
Mutual labels:  wagtail
wagtaildraftail
🐦📝🍸 Draft.js editor for Wagtail, built upon Draftail and draftjs_exporter
Stars: ✭ 23 (-50%)
Mutual labels:  wagtail
Consumerfinance.gov
Django project protecting American consumers
Stars: ✭ 164 (+256.52%)
Mutual labels:  wagtail
digihel
City of Helsinki Digital Helsinki Wagtail CMS
Stars: ✭ 19 (-58.7%)
Mutual labels:  wagtail
Wagtail Pipit
Pipit is a Wagtail CMS boilerplate which aims to provide an easy and modern developer workflow with a React-rendered frontend.
Stars: ✭ 109 (+136.96%)
Mutual labels:  wagtail
Wagtailmedia
A Wagtail module for managing video and audio files within the admin
Stars: ✭ 128 (+178.26%)
Mutual labels:  wagtail
freeturn
Freelance mission control
Stars: ✭ 50 (+8.7%)
Mutual labels:  wagtail
Wagtailtrans
A Wagtail add-on for supporting multilingual sites
Stars: ✭ 103 (+123.91%)
Mutual labels:  wagtail
vagrant-wagtail-develop
A script to painlessly set up a Vagrant environment for development of Wagtail
Stars: ✭ 36 (-21.74%)
Mutual labels:  wagtail
Wagtail Personalisation
Rule-based personalisation for Wagtail CMS
Stars: ✭ 96 (+108.7%)
Mutual labels:  wagtail
wagtailcommonblocks
Common StreamField blocks for Wagtail
Stars: ✭ 40 (-13.04%)
Mutual labels:  wagtail
WF-website
Website for Western Friend, part of the Religious Society of Friends
Stars: ✭ 34 (-26.09%)
Mutual labels:  wagtail
wagtail-redirect-importer
Note: This library is now included in Wagtail 2.10, use the builtin version instead of this.
Stars: ✭ 15 (-67.39%)
Mutual labels:  wagtail
wagtail-headless-preview
Previews for headless Wagtail setups
Stars: ✭ 99 (+115.22%)
Mutual labels:  wagtail
Build Status

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.contrib.modeladmin is also required and must be included in your list of installed apps.

The code examples below assume that you are using the latest 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)))

Sharing sites

The Wagtail admin now contains a new section under Settings called Sharing Sites that allows users to define how they would like to expose latest page revisions.

Sharing sites

No sharing sites exist by default. A sharing site must be manually created for each Wagtail Site to make its latest revisions shareable. Each sharing site is defined by a unique hostname and port number. Important: configuring your sharing sites improperly could expose draft/private content publicly. Be careful when setting them up!

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.

New sharing site with site: "localhost [default]", hostname: "sharing.localhost", port: "8000"

Your latest page revisions (including drafts) should now be available at http://sharing.localhost:8000.

Banners

Pages viewed on a wagtail-sharing shared site have a simple banner added to them to remind reviewers that the current published content may differ from the content they are viewing.

Banner

This behavior can be disabled by setting settings.WAGTAILSHARING_BANNER = False. The banner template can be overridden by providing an alternate template file at wagtailsharing/banner.html similar to how wagtailadmin template overrides are supported.

Sharing links

A page's sharing URL can be retrieved by passing its Page instance to wagtailsharing.helpers.get_sharing_url. This method returns None if no shared sites are configured or if the specified page is not routable to a shared site.

Shared pages will also have a new dropdown menu option that links to this sharing URL from the Wagtail page explorer.

Dropdown with sharing link

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.

before_serve_shared_page

Called before the latest revision of the page is about to be served, just before its serve() method is called. Like before_serve_page this hook is passed the page object, the request object, and the args and kwargs that will be passed to the page's serve() method. If the callable returns an HttpResponse, that response will be returned immediately to the user.

This hook could be useful for limiting sharing to only certain page types or for modifying a page's contents when it is shared.

from wagtail import hooks

@hooks.register('before_serve_shared_page')
def modify_shared_title(page, request, args, kwargs):
    page.title += ' (Shared)'

after_serve_shared_page

Called after the page's serve() method is called but before the response is returned to the user. This hook is passed the page object and the response object returned by serve(). If the callable returns an HttpResponse, that response will be returned immediately to the user.

This hook could be useful for directly modifying the response content, for example by adding custom headers or altering the generated HTML. This hook is used to implement the notification banner described above.

from wagtail import hooks

@hooks.register('after_serve_shared_page')
def add_custom_header(page, response):
    response['Wagtail-Is-Shared'] = '1'

Mixins

ShareableRoutablePageMixin

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.7+
  • Django 3.0+
  • Wagtail 2.15+

It should be compatible with all intermediate versions, as well. If you find that it is not, please file an issue.

Open source licensing info

  1. TERMS
  2. LICENSE
  3. CFPB Source Code Policy
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].