Skip to content

Allow publishing of updates to live pages to be optional#61

Open
SociologicalReview wants to merge 5 commits into
nm-packages:releasefrom
SociologicalReview:removeAutoPublish01
Open

Allow publishing of updates to live pages to be optional#61
SociologicalReview wants to merge 5 commits into
nm-packages:releasefrom
SociologicalReview:removeAutoPublish01

Conversation

@SociologicalReview
Copy link
Copy Markdown

In the current version of generate_qr_code in wagtail_qrcode/wagtail_hooks.py the last two lines cause draft changes to live pages to be automatically published:

def generate_qr_code(request, page):
    """Add a QR code to the page."""

    # dont try to generate a qrcode if the page does not inherit from QRCodeMixin
    if is_qrcode_instance(page):
        collection = create_collection("QR Codes")

        qrc = WagtailQrCode(page, collection)

        svg, document = qrc.build()

        page.qr_code_svg = svg
        page.qr_code_eps = document

        rev = page.save_revision()

        if page.live:
            rev.publish()

It is quite common for someone to draft changes to a page but want to hold off on publishing them, for example, if they are gradually updating a page or needing approval from another editor. Generally, it would be up to the page editor to choose when to publish a page rather than this being enforced in code.

This update introduces a setting, WAGTAIL_QR_CODE_AUTO_PUBLISH_UPDATES, which allows this behaviour to be optional.

  • If set to False, the default behaviour, pages are not automatically published after editing.
  • If set to True, the pages are published, as in the original version.

The default is taken as False as this is more in line with common procedure.

def generate_qr_code(request, page):
    """Add a QR code to the page."""

    # dont try to generate a qrcode if the page does not inherit from QRCodeMixin
    if is_qrcode_instance(page):
        collection = create_collection("QR Codes")

        qrc = WagtailQrCode(page, collection)

        svg, document = qrc.build()

        page.qr_code_svg = svg
        page.qr_code_eps = document

        rev = page.save_revision()

        if (
            page.live
            and getattr(settings, "WAGTAIL_QR_CODE_AUTO_PUBLISH_UPDATES", False) == True
        ):
            rev.publish()

This references issue #60

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant