Skip to content

Settings models

These models are responsible for storing settings that are configured by a user.

graph TD


A[LocaleSynchronization] --> B[wagtail.Locale]

style B stroke-dasharray: 5 5

LocaleSynchronization

Bases: Model

Stores the "Sync from" setting that users can add to Locales.

This tells Wagtail Localize to synchronise the contents of the 'sync_from' Locale to the 'locale' Locale.

Attributes:

Name Type Description
locale ForeignKey to Locale

The destination Locale of the synchronisation

sync_from ForeignKey to Locale

The source Locale of the synchronisation

Source code in wagtail_localize/models.py
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
@register_locale_component(
    heading=gettext_lazy("Synchronise content from another locale"),
    help_text=gettext_lazy(
        "Choose a locale to synchronise content from. "
        "Any existing and future content authored in the selected locale will "
        "be automatically copied to this one."
    ),
)
class LocaleSynchronization(models.Model):
    """
    Stores the "Sync from" setting that users can add to Locales.

    This tells Wagtail Localize to synchronise the contents of the 'sync_from' Locale to the 'locale' Locale.

    Attributes:
        locale (ForeignKey to Locale): The destination Locale of the synchronisation
        sync_from (ForeignKey to Locale): The source Locale of the synchronisation
    """

    locale = models.OneToOneField(
        "wagtailcore.Locale", on_delete=models.CASCADE, related_name="+"
    )
    sync_from = models.ForeignKey(
        "wagtailcore.Locale", on_delete=models.CASCADE, related_name="+"
    )

    base_form_class = LocaleSynchronizationModelForm

    def __str__(self):
        return f"LocaleSynchronization: {self.locale_id}, {self.sync_from_id}"

    def sync_trees(self, *, page_index=None):
        from .synctree import synchronize_tree

        background.enqueue(
            synchronize_tree,
            args=[self.sync_from, self.locale],
            kwargs={"page_index": page_index},
        )