# Path: simple_cms/contrib/translated_model/models.py
# class LocalizationTranslation(models.Model):
#     language = models.ForeignKey(Language)
#     localization = models.ForeignKey(Localization)
#     text = models.TextField()
#     
#     class Meta:
#         unique_together = ('language', 'localization')
#     
#     def __unicode__(self):
#         return u'%s' % self.text
# 
# Path: simple_cms/models.py
# class CommonAbstractModel(models.Model):
#     """
#     Common ABC for most models.
#     Provides created/updated_at, and active/inactive status.
#     """
#     created_at = CreationDateTimeField()
#     updated_at = ModificationDateTimeField()
#     active = models.BooleanField(default=True, verbose_name="published")
#     objects = CommonAbstractManager()
# 
#     class Meta:
#         get_latest_by = 'updated_at'
#         ordering = ('-updated_at', '-created_at')
#         abstract = True
# 
#     def get_class_name(self):
#         return self.__class__.__name__


from django.utils.safestring import mark_safe
from simple_cms.contrib.translated_model.models import LocalizationTranslation
from simple_cms.models import CommonAbstractModel
from django import template
from django.conf import settings


register = template.Library()

def get_default_language():
    # TODO: check on custom overrides, or future Language based default settings
    return settings.LANGUAGE_CODE

def _translate_instance(instance, code):
    try:
        translations = instance.translations.filter(language__code=code, active=True)
        if len(translations):
            # map the non empty values on to the original instance
            translation = translations[0]
            # TODO: find out how to properly obtain the base classes up to models.Model and exclude all of their fields
            # TODO: find out how to properly obtain the PK fieldname

# Path: simple_cms/contrib/translated_model/models.py
# class LocalizationTranslation(models.Model):
#     language = models.ForeignKey(Language)
#     localization = models.ForeignKey(Localization)
#     text = models.TextField()
#     
#     class Meta:
#         unique_together = ('language', 'localization')
#     
#     def __unicode__(self):
#         return u'%s' % self.text
# 
# Path: simple_cms/models.py
# class CommonAbstractModel(models.Model):
#     """
#     Common ABC for most models.
#     Provides created/updated_at, and active/inactive status.
#     """
#     created_at = CreationDateTimeField()
#     updated_at = ModificationDateTimeField()
#     active = models.BooleanField(default=True, verbose_name="published")
#     objects = CommonAbstractManager()
# 
#     class Meta:
#         get_latest_by = 'updated_at'
#         ordering = ('-updated_at', '-created_at')
#         abstract = True
# 
#     def get_class_name(self):
#         return self.__class__.__name__


# Path: simple_cms/contrib/translated_model/templatetags/translation_tags.py
from django.utils.safestring import mark_safe
from simple_cms.contrib.translated_model.models import LocalizationTranslation
from simple_cms.models import CommonAbstractModel
from django import template
from django.conf import settings



register = template.Library()

def get_default_language():
    # TODO: check on custom overrides, or future Language based default settings
    return settings.LANGUAGE_CODE

def _translate_instance(instance, code):
    try:
        translations = instance.translations.filter(language__code=code, active=True)
        if len(translations):
            # map the non empty values on to the original instance
            translation = translations[0]
            # TODO: find out how to properly obtain the base classes up to models.Model and exclude all of their fields
            # TODO: find out how to properly obtain the PK fieldname

            excluded = CommonAbstractModel._meta.get_all_field_names() + ['id']