import wagtail_factories
from django.conf import settings
from wagtail.models import Locale, Site


def get_wagtail_default_site():
    for language in settings.WAGTAIL_CONTENT_LANGUAGES:
        Locale.objects.get_or_create(language_code=language[0])

    site = Site.objects.filter(is_default_site=True).first()

    if not site:
        site = wagtail_factories.SiteFactory(is_default_site=True)

    return site
