# Path: modeltrans/translator.py
# def translate_model(Model):
#     i18n_field = get_i18n_field(Model)
# 
#     if i18n_field is None:
#         return
# 
#     if not i18n_field.virtual_fields:
#         # This mode is required for the migration process:
#         # It needs to have a stage where we do have the TranslationField,
#         # but not the virtual fields (which would collide with the
#         # django-modeltranslation `<field>_<lang>`-fields), to be able to
#         # copy the values from the `<field>_<lang>`-fields into `i18n.<field>_<lang>`.
#         return
# 
#     validate(Model)
# 
#     add_manager(Model)
#     fields_to_translate = get_i18n_field_param(Model, i18n_field, "fields")
#     required_languages = get_i18n_field_param(Model, i18n_field, "required_languages")
#     add_virtual_fields(Model, fields_to_translate, required_languages)
#     patch_constructor(Model)
# 
#     translate_meta_ordering(Model)
# 
# Path: tests/app/models.py
# class Blog(models.Model):
#     title = models.CharField(max_length=255)
#     body = models.TextField(null=True)
# 
#     category = models.ForeignKey(Category, null=True, blank=True, on_delete=models.CASCADE)
#     site = models.ForeignKey(Site, null=True, blank=True, on_delete=models.CASCADE)
# 
#     i18n = TranslationField(fields=("title", "body"), required_languages=("nl",))
# 
#     def __str__(self):
#         return self.title
# 
# class Category(models.Model):
# 
#     name = models.CharField(max_length=255)
#     title = models.CharField(max_length=255)
# 
#     i18n = TranslationField(fields=("name", "title"))
# 
#     objects = CategoryQueryset.as_manager()
# 
#     def __str__(self):
#         return self.name


import json
import os
from django.db import connection
from modeltrans.translator import translate_model
from .app.models import Blog, Category





class CreateTestModel:
    """
    Create the database table for a one or more Models during tests.

    Helpfull if we want to use custom settings which influence the models
    created in our tests, used like this::

        class Test(TestCase):

            @override_settings(LANGUAGE_CODE='nl')
            def test_with_custom_model(self):
                class TestModel(models.Model):
                    title = models.CharField(max_length=10)

                with CreateTestModel(TestModel):
                    m = TestModel.objects.create(title='foo')

                    self.assertEquals(m.title, 'foo')
    """

    def __init__(self, *args, **kwargs):
        self.models = args
        if kwargs.get("translate", False):
            for Model in self.models:

# Path: modeltrans/translator.py
# def translate_model(Model):
#     i18n_field = get_i18n_field(Model)
# 
#     if i18n_field is None:
#         return
# 
#     if not i18n_field.virtual_fields:
#         # This mode is required for the migration process:
#         # It needs to have a stage where we do have the TranslationField,
#         # but not the virtual fields (which would collide with the
#         # django-modeltranslation `<field>_<lang>`-fields), to be able to
#         # copy the values from the `<field>_<lang>`-fields into `i18n.<field>_<lang>`.
#         return
# 
#     validate(Model)
# 
#     add_manager(Model)
#     fields_to_translate = get_i18n_field_param(Model, i18n_field, "fields")
#     required_languages = get_i18n_field_param(Model, i18n_field, "required_languages")
#     add_virtual_fields(Model, fields_to_translate, required_languages)
#     patch_constructor(Model)
# 
#     translate_meta_ordering(Model)
# 
# Path: tests/app/models.py
# class Blog(models.Model):
#     title = models.CharField(max_length=255)
#     body = models.TextField(null=True)
# 
#     category = models.ForeignKey(Category, null=True, blank=True, on_delete=models.CASCADE)
#     site = models.ForeignKey(Site, null=True, blank=True, on_delete=models.CASCADE)
# 
#     i18n = TranslationField(fields=("title", "body"), required_languages=("nl",))
# 
#     def __str__(self):
#         return self.title
# 
# class Category(models.Model):
# 
#     name = models.CharField(max_length=255)
#     title = models.CharField(max_length=255)
# 
#     i18n = TranslationField(fields=("name", "title"))
# 
#     objects = CategoryQueryset.as_manager()
# 
#     def __str__(self):
#         return self.name


# Path: tests/utils.py
import json
import os
from django.db import connection
from modeltrans.translator import translate_model
from .app.models import Blog, Category






class CreateTestModel:
    """
    Create the database table for a one or more Models during tests.

    Helpfull if we want to use custom settings which influence the models
    created in our tests, used like this::

        class Test(TestCase):

            @override_settings(LANGUAGE_CODE='nl')
            def test_with_custom_model(self):
                class TestModel(models.Model):
                    title = models.CharField(max_length=10)

                with CreateTestModel(TestModel):
                    m = TestModel.objects.create(title='foo')

                    self.assertEquals(m.title, 'foo')
    """

    def __init__(self, *args, **kwargs):
        self.models = args
        if kwargs.get("translate", False):
            for Model in self.models:

                translate_model(Model)