# Path: feincms3/utils.py
# class ChoicesCharField(models.CharField):
#     """
#     ``models.CharField`` with choices, which makes the migration framework
#     always ignore changes to ``choices``, ever.
#     """
# 
#     def __init__(self, *args, **kwargs):
#         kwargs.setdefault("choices", [("", "")])  # Non-empty choices for get_*_display
#         super().__init__(*args, **kwargs)
# 
#     def deconstruct(self):
#         name, path, args, kwargs = super().deconstruct()
#         kwargs["choices"] = [("", "")]
#         return name, "django.db.models.CharField", args, kwargs
# 
# def validation_error(error, *, field, exclude, **kwargs):
#     """
#     Return a validation error that is associated with a particular field if it
#     isn't excluded from validation.
# 
#     See https://github.com/django/django/commit/e8c056c31 for some background.
#     """
#     return ValidationError(
#         error if field in (exclude or ()) else {field: error}, **kwargs
#     )


import warnings
from django.conf import settings
from django.core.checks import Warning
from django.db import models
from django.db.models import Q, signals
from django.utils.translation import activate, get_language, gettext_lazy as _
from tree_queries.fields import TreeNodeForeignKey
from feincms3.utils import ChoicesCharField, validation_error

    @staticmethod
    def fill_template_key_choices(sender, **kwargs):
        """
        Fills in the choices for ``menu`` from the ``MENUS`` class variable.
        This method is a receiver of Django's ``class_prepared`` signal.
        """
        if issubclass(sender, TemplateMixin) and not sender._meta.abstract:
            field = sender._meta.get_field("template_key")
            field.choices = [(t.key, t.title) for t in sender.TEMPLATES]
            field.default = sender.TEMPLATES[0].key
            sender.TEMPLATES_DICT = {t.key: t for t in sender.TEMPLATES}

            warnings.warn(
                f"{sender._meta.label} uses the TemplateMixin."
                " It is recommended to use the PageTypeMixin and TemplateType"
                " from feincms3.applications even if you're not planning to use"
                " any apps.",
                DeprecationWarning,
            )


signals.class_prepared.connect(TemplateMixin.fill_template_key_choices)


class LanguageMixin(models.Model):
    """
    Pages may come in varying languages. ``LanguageMixin`` helps with that.
    """


# Path: feincms3/utils.py
# class ChoicesCharField(models.CharField):
#     """
#     ``models.CharField`` with choices, which makes the migration framework
#     always ignore changes to ``choices``, ever.
#     """
# 
#     def __init__(self, *args, **kwargs):
#         kwargs.setdefault("choices", [("", "")])  # Non-empty choices for get_*_display
#         super().__init__(*args, **kwargs)
# 
#     def deconstruct(self):
#         name, path, args, kwargs = super().deconstruct()
#         kwargs["choices"] = [("", "")]
#         return name, "django.db.models.CharField", args, kwargs
# 
# def validation_error(error, *, field, exclude, **kwargs):
#     """
#     Return a validation error that is associated with a particular field if it
#     isn't excluded from validation.
# 
#     See https://github.com/django/django/commit/e8c056c31 for some background.
#     """
#     return ValidationError(
#         error if field in (exclude or ()) else {field: error}, **kwargs
#     )


# Path: feincms3/mixins.py
import warnings
from django.conf import settings
from django.core.checks import Warning
from django.db import models
from django.db.models import Q, signals
from django.utils.translation import activate, get_language, gettext_lazy as _
from tree_queries.fields import TreeNodeForeignKey
from feincms3.utils import ChoicesCharField, validation_error


    @staticmethod
    def fill_template_key_choices(sender, **kwargs):
        """
        Fills in the choices for ``menu`` from the ``MENUS`` class variable.
        This method is a receiver of Django's ``class_prepared`` signal.
        """
        if issubclass(sender, TemplateMixin) and not sender._meta.abstract:
            field = sender._meta.get_field("template_key")
            field.choices = [(t.key, t.title) for t in sender.TEMPLATES]
            field.default = sender.TEMPLATES[0].key
            sender.TEMPLATES_DICT = {t.key: t for t in sender.TEMPLATES}

            warnings.warn(
                f"{sender._meta.label} uses the TemplateMixin."
                " It is recommended to use the PageTypeMixin and TemplateType"
                " from feincms3.applications even if you're not planning to use"
                " any apps.",
                DeprecationWarning,
            )


signals.class_prepared.connect(TemplateMixin.fill_template_key_choices)


class LanguageMixin(models.Model):
    """
    Pages may come in varying languages. ``LanguageMixin`` helps with that.
    """


    language_code = ChoicesCharField(