# Path: src/slim/helpers.py
# def get_default_language():
# def get_languages():
# def get_languages_keys():
# def get_languages_dict():
# def get_language_from_request(request, default=default_language):
# def admin_change_url(app_label, module_name, object_id, extra_path='',
#                      url_title=None):
# def admin_add_url(app_label, module_name, extra_path='', url_title=None):
# def smart_resolve(var, context):
# 
# Path: src/slim/monkey_patches.py
# def monkeypatch_method(cls):
#     """
#     A decorator to add a single method to an existing class::
# 
#         @monkeypatch_method(<someclass>)
#         def <newmethod>(self, [...]):
#             pass
#     """
#     def decorator(func):
#         setattr(cls, func.__name__, func)
#         return func
#     return decorator
# 
# def monkeypatch_property(cls):
#     """
#     A decorator to add a single method as a property to an existing class::
# 
#         @monkeypatch_property(<someclass>)
#         def <newmethod>(self, [...]):
#             pass
#     """
#     def decorator(func):
#         setattr(cls, func.__name__, property(func))
#         return func
#     return decorator
# 
# Path: src/slim/settings.py
# ENABLE_MONKEY_PATCHING = get_setting('ENABLE_MONKEY_PATCHING')
# 
# Path: src/slim/translations.py
# def is_primary_language(language=None):
#     """Return true if current or passed language is the primary language.
# 
#     Return true if current or passed language is the primary language for the
#     site (the primary language is defined as the first language in
#     settings.LANGUAGES).
# 
#     :param str language:
#     :return bool:
#     """
#     if not language:
#         language = translation.get_language()
# 
#     return language == default_language


from six import PY3, text_type
from django.db import models
from django.core import exceptions
from django.utils.translation import ugettext_lazy as _
from nine import versions
from ..helpers import (
    get_languages,
    default_language,
    get_languages_keys,
    admin_change_url,
    admin_add_url
)
from ..monkey_patches import monkeypatch_method, monkeypatch_property
from ..settings import ENABLE_MONKEY_PATCHING
from ..translations import is_primary_language
    from south.modelsinspector import add_introspection_rules
                translations are available for the given ``language``.
                """
                if language not in get_languages_keys():
                    return None
                if str(self.language) == str(language):
                    return self
                if str(self.original_translation.language) == str(language):
                    return self.original_translation
                try:
                    return self.original_translation.translations.get(
                        language=language
                    )
                except Exception:
                    return None


class SimpleLanguageField(models.CharField):
    """SimpleLanguageField model.

    Store language string in a ``CharField`` field.
    """

    def __init__(self, *args, **kwargs):
        """Create new field.
        Argument ``populate`` will be sent as-is to the form field.
        """
        defaults = {
            'verbose_name': _('Language'),
            'populate': None,
            'max_length': 10,

# Path: src/slim/helpers.py
# def get_default_language():
# def get_languages():
# def get_languages_keys():
# def get_languages_dict():
# def get_language_from_request(request, default=default_language):
# def admin_change_url(app_label, module_name, object_id, extra_path='',
#                      url_title=None):
# def admin_add_url(app_label, module_name, extra_path='', url_title=None):
# def smart_resolve(var, context):
# 
# Path: src/slim/monkey_patches.py
# def monkeypatch_method(cls):
#     """
#     A decorator to add a single method to an existing class::
# 
#         @monkeypatch_method(<someclass>)
#         def <newmethod>(self, [...]):
#             pass
#     """
#     def decorator(func):
#         setattr(cls, func.__name__, func)
#         return func
#     return decorator
# 
# def monkeypatch_property(cls):
#     """
#     A decorator to add a single method as a property to an existing class::
# 
#         @monkeypatch_property(<someclass>)
#         def <newmethod>(self, [...]):
#             pass
#     """
#     def decorator(func):
#         setattr(cls, func.__name__, property(func))
#         return func
#     return decorator
# 
# Path: src/slim/settings.py
# ENABLE_MONKEY_PATCHING = get_setting('ENABLE_MONKEY_PATCHING')
# 
# Path: src/slim/translations.py
# def is_primary_language(language=None):
#     """Return true if current or passed language is the primary language.
# 
#     Return true if current or passed language is the primary language for the
#     site (the primary language is defined as the first language in
#     settings.LANGUAGES).
# 
#     :param str language:
#     :return bool:
#     """
#     if not language:
#         language = translation.get_language()
# 
#     return language == default_language


# Path: src/slim/models/fields.py
from six import PY3, text_type
from django.db import models
from django.core import exceptions
from django.utils.translation import ugettext_lazy as _
from nine import versions
from ..helpers import (
    get_languages,
    default_language,
    get_languages_keys,
    admin_change_url,
    admin_add_url
)
from ..monkey_patches import monkeypatch_method, monkeypatch_property
from ..settings import ENABLE_MONKEY_PATCHING
from ..translations import is_primary_language
    from south.modelsinspector import add_introspection_rules

                translations are available for the given ``language``.
                """
                if language not in get_languages_keys():
                    return None
                if str(self.language) == str(language):
                    return self
                if str(self.original_translation.language) == str(language):
                    return self.original_translation
                try:
                    return self.original_translation.translations.get(
                        language=language
                    )
                except Exception:
                    return None


class SimpleLanguageField(models.CharField):
    """SimpleLanguageField model.

    Store language string in a ``CharField`` field.
    """

    def __init__(self, *args, **kwargs):
        """Create new field.
        Argument ``populate`` will be sent as-is to the form field.
        """
        defaults = {
            'verbose_name': _('Language'),
            'populate': None,
            'max_length': 10,

            'choices': get_languages(),