Package: wagtail-mautic-integration
Wagtail Mautic IntegrationIntegration ofMauticforms in Wagtail Projects.BackgroundWe needed to allow our users to subscribe to a mailing list directly from a form rendered on a Wagtail Page.Mautic is an open-source alternative to Mailchimp and fitted our needs.The aim of this package is to render a given Mautic Form on a Wagtail page, and send the submitted data to Mautic.
Other Mautic functionalities might be added later as need arises.InstallationInstall using pippip install wagtail-mautic-integrationAddwagtailmauticto your installed apps. Make surewagtail.contrib.settingsis also added.INSTALLED_APPS = [
        ...
        "wagtailmautic",
        "wagtail.contrib.settings",
        ...
        ]Run migrationspython manage.py migrateMautic API ConfigurationThe Mautic API needs to be enabled from Mautic. Open your Mautic instance and follow the steps below to enable the Mautic
APIMautic API SetupFollow the steps below to ensure the Mautic API is enabled from the Mautic SettingsClick on the settings icon to show the available settingsClick on ConfigurationSelect API SettingsEnable API by selectingYes. If using HTTP Basic Auth (username and password for authentication), also selectYesunder Enable HTTP basic authDon't forget to Save. You can select Save and Close to Close after saving.Using OAuth 2If you did not select to use HTTP basic auth, you can set up to use OAuth as below:Click on the settings icon to show the available settingsClick on API Credentials. If the API Credentials option is not available, please follow the previous steps to enable the APISet up the credentials name and Redirect URLDon't forget to Save. After saving, a new page will be shown with your Client ID and Client Secret that you can use
for authenticationWagtail Mautic SettingsMautic Settings will be automatically added to the Wagtail Admin Menu as belowAdd in the URL for your Mautic instance (including the https://) to the Mautic Url field.You can use two methods for authentication:OAuth2 that requires client id and client secret from MauticBasic Authentication that needs username and password. To use Basic Auth, you must enable this on Mautic Configuration
as described in the previous steps aboveOAth2BasicUsageThe package provides an abstract wagtail page that uses a custom view to serve the Mautic Form.Below is a sample snippet on how you can use it on your wagtail page that you want to serve the form.Let us say you have a subscribe page, that should show a Mautic Form that your users can fill to subscribe to your mailing listin your app'smodels.py:from wagtail.models import Page

from wagtailmautic.models import BaseMauticFormPage


class MailingListSubscribePage(BaseMauticFormPage, Page):
    passCreate the Page as usual in your CMS admin.Edit the Page to add the Mautic Form IDAdd the form in your page's template<form method="POST">
        {% csrf_token %}
        {{ form }}
        <div class="field">
            <button type="submit" class="button submit-button has-no-border">Submit</button>
        </div>
    </form>The rendered page should now include a form with matching fields as setup on your Mautic form.
You can see a sample page insandbox/home/models.Submitting will send the form data to Mautic and show the thank you message that was setYou may want to override the default providedform_thank_you_landing.htmltemplate atwagtailmautic/templates/form_thank_you_landing.htmlFirst, create a templates directory in your project's root directory if it does not exist already.Inside the templates directory, create a directory with the namewagtailmauticwhose template we want to override.Inside thewagtailmauticdirectory, create a file with the same name as the template we want to override. In this case, create a file namedform_thank_you_landing.html.Edit the newform_thank_you_landing.htmltemplate as desired.