from django.core.urlresolvers import reverse
from django.db import models
from django.utils.encoding import python_2_unicode_compatible

from cms.models.fields import PlaceholderField
from cms.utils import get_language_from_request
from cms.utils.urlutils import admin_reverse

from hvad.models import TranslatableModel, TranslatedFields


def dynamic_placeholder_1(instance):
    return instance.char_1


def dynamic_placeholder_2(instance):
    return instance.char_2


@python_2_unicode_compatible
class Example1(models.Model):
    char_1 = models.CharField(u'char_1', max_length=255)
    char_2 = models.CharField(u'char_2', max_length=255)
    char_3 = models.CharField(u'char_3', max_length=255)
    char_4 = models.CharField(u'char_4', max_length=255)
    date_field = models.DateField(null=True)
    placeholder = PlaceholderField('placeholder')

    static_admin_url = ''

    def __init__(self, *args, **kwargs):
        super(Example1, self).__init__(*args, **kwargs)

    def callable_item(self, request):
        return self.char_1

    def __str__(self):
        return self.char_1

    def get_absolute_url(self):
        return reverse("example_detail", args=(self.pk,))

    def get_draft_url(self):
        return self.get_absolute_url()

    def get_public_url(self):
        return '/public/view/'

    def set_static_url(self, request):
        language = get_language_from_request(request)
        if self.pk:
            self.static_admin_url = admin_reverse('placeholderapp_example1_edit_field', args=(self.pk, language))
        return self.pk

    def dynamic_url(self, request):
        language = get_language_from_request(request)
        return admin_reverse('placeholderapp_example1_edit_field', args=(self.pk, language))


class TwoPlaceholderExample(models.Model):
    char_1 = models.CharField(u'char_1', max_length=255)
    char_2 = models.CharField(u'char_2', max_length=255)
    char_3 = models.CharField(u'char_3', max_length=255)
    char_4 = models.CharField(u'char_4', max_length=255)
    placeholder_1 = PlaceholderField('placeholder_1', related_name='p1')
    placeholder_2 = PlaceholderField('placeholder_2', related_name='p2')


class DynamicPlaceholderSlotExample(models.Model):
    char_1 = models.CharField(u'char_1', max_length=255)
    char_2 = models.CharField(u'char_2', max_length=255)
    placeholder_1 = PlaceholderField(dynamic_placeholder_1, related_name='dynamic_pl_1')
    placeholder_2 = PlaceholderField(dynamic_placeholder_2, related_name='dynamic_pl_2')


@python_2_unicode_compatible
class CharPksExample(models.Model):
    char_1 = models.CharField(u'char_1', max_length=255)
    slug = models.SlugField(u'char_1', max_length=255, primary_key=True)
    placeholder_1 = PlaceholderField('placeholder_1', related_name='charpk_p1')

    def __str__(self):
        return "%s - %s" % (self.char_1, self.pk)


@python_2_unicode_compatible
class MultilingualExample1(TranslatableModel):
    translations = TranslatedFields(
        char_1=models.CharField(u'char_1', max_length=255),
        char_2=models.CharField(u'char_2', max_length=255),
    )
    placeholder_1 = PlaceholderField('placeholder_1')

    def __str__(self):
        return self.char_1

    def get_absolute_url(self):
        return reverse("detail_multi", args=(self.pk,))

[((544, 587), 'django.db.models.CharField', 'models.CharField', (['u"""char_1"""'], {'max_length': '(255)'}), "(u'char_1', max_length=255)\n", (560, 587), False, 'from django.db import models\n'), ((601, 644), 'django.db.models.CharField', 'models.CharField', (['u"""char_2"""'], {'max_length': '(255)'}), "(u'char_2', max_length=255)\n", (617, 644), False, 'from django.db import models\n'), ((658, 701), 'django.db.models.CharField', 'models.CharField', (['u"""char_3"""'], {'max_length': '(255)'}), "(u'char_3', max_length=255)\n", (674, 701), False, 'from django.db import models\n'), ((715, 758), 'django.db.models.CharField', 'models.CharField', (['u"""char_4"""'], {'max_length': '(255)'}), "(u'char_4', max_length=255)\n", (731, 758), False, 'from django.db import models\n'), ((776, 803), 'django.db.models.DateField', 'models.DateField', ([], {'null': '(True)'}), '(null=True)\n', (792, 803), False, 'from django.db import models\n'), ((822, 853), 'cms.models.fields.PlaceholderField', 'PlaceholderField', (['"""placeholder"""'], {}), "('placeholder')\n", (838, 853), False, 'from cms.models.fields import PlaceholderField\n'), ((1811, 1854), 'django.db.models.CharField', 'models.CharField', (['u"""char_1"""'], {'max_length': '(255)'}), "(u'char_1', max_length=255)\n", (1827, 1854), False, 'from django.db import models\n'), ((1868, 1911), 'django.db.models.CharField', 'models.CharField', (['u"""char_2"""'], {'max_length': '(255)'}), "(u'char_2', max_length=255)\n", (1884, 1911), False, 'from django.db import models\n'), ((1925, 1968), 'django.db.models.CharField', 'models.CharField', (['u"""char_3"""'], {'max_length': '(255)'}), "(u'char_3', max_length=255)\n", (1941, 1968), False, 'from django.db import models\n'), ((1982, 2025), 'django.db.models.CharField', 'models.CharField', (['u"""char_4"""'], {'max_length': '(255)'}), "(u'char_4', max_length=255)\n", (1998, 2025), False, 'from django.db import models\n'), ((2046, 2098), 'cms.models.fields.PlaceholderField', 'PlaceholderField', (['"""placeholder_1"""'], {'related_name': '"""p1"""'}), "('placeholder_1', related_name='p1')\n", (2062, 2098), False, 'from cms.models.fields import PlaceholderField\n'), ((2119, 2171), 'cms.models.fields.PlaceholderField', 'PlaceholderField', (['"""placeholder_2"""'], {'related_name': '"""p2"""'}), "('placeholder_2', related_name='p2')\n", (2135, 2171), False, 'from cms.models.fields import PlaceholderField\n'), ((2238, 2281), 'django.db.models.CharField', 'models.CharField', (['u"""char_1"""'], {'max_length': '(255)'}), "(u'char_1', max_length=255)\n", (2254, 2281), False, 'from django.db import models\n'), ((2295, 2338), 'django.db.models.CharField', 'models.CharField', (['u"""char_2"""'], {'max_length': '(255)'}), "(u'char_2', max_length=255)\n", (2311, 2338), False, 'from django.db import models\n'), ((2359, 2427), 'cms.models.fields.PlaceholderField', 'PlaceholderField', (['dynamic_placeholder_1'], {'related_name': '"""dynamic_pl_1"""'}), "(dynamic_placeholder_1, related_name='dynamic_pl_1')\n", (2375, 2427), False, 'from cms.models.fields import PlaceholderField\n'), ((2448, 2516), 'cms.models.fields.PlaceholderField', 'PlaceholderField', (['dynamic_placeholder_2'], {'related_name': '"""dynamic_pl_2"""'}), "(dynamic_placeholder_2, related_name='dynamic_pl_2')\n", (2464, 2516), False, 'from cms.models.fields import PlaceholderField\n'), ((2597, 2640), 'django.db.models.CharField', 'models.CharField', (['u"""char_1"""'], {'max_length': '(255)'}), "(u'char_1', max_length=255)\n", (2613, 2640), False, 'from django.db import models\n'), ((2652, 2713), 'django.db.models.SlugField', 'models.SlugField', (['u"""char_1"""'], {'max_length': '(255)', 'primary_key': '(True)'}), "(u'char_1', max_length=255, primary_key=True)\n", (2668, 2713), False, 'from django.db import models\n'), ((2734, 2793), 'cms.models.fields.PlaceholderField', 'PlaceholderField', (['"""placeholder_1"""'], {'related_name': '"""charpk_p1"""'}), "('placeholder_1', related_name='charpk_p1')\n", (2750, 2793), False, 'from cms.models.fields import PlaceholderField\n'), ((3129, 3162), 'cms.models.fields.PlaceholderField', 'PlaceholderField', (['"""placeholder_1"""'], {}), "('placeholder_1')\n", (3145, 3162), False, 'from cms.models.fields import PlaceholderField\n'), ((1144, 1186), 'django.core.urlresolvers.reverse', 'reverse', (['"""example_detail"""'], {'args': '(self.pk,)'}), "('example_detail', args=(self.pk,))\n", (1151, 1186), False, 'from django.core.urlresolvers import reverse\n'), ((1377, 1411), 'cms.utils.get_language_from_request', 'get_language_from_request', (['request'], {}), '(request)\n', (1402, 1411), False, 'from cms.utils import get_language_from_request\n'), ((1625, 1659), 'cms.utils.get_language_from_request', 'get_language_from_request', (['request'], {}), '(request)\n', (1650, 1659), False, 'from cms.utils import get_language_from_request\n'), ((1675, 1752), 'cms.utils.urlutils.admin_reverse', 'admin_reverse', (['"""placeholderapp_example1_edit_field"""'], {'args': '(self.pk, language)'}), "('placeholderapp_example1_edit_field', args=(self.pk, language))\n", (1688, 1752), False, 'from cms.utils.urlutils import admin_reverse\n'), ((3262, 3302), 'django.core.urlresolvers.reverse', 'reverse', (['"""detail_multi"""'], {'args': '(self.pk,)'}), "('detail_multi', args=(self.pk,))\n", (3269, 3302), False, 'from django.core.urlresolvers import reverse\n'), ((1468, 1545), 'cms.utils.urlutils.admin_reverse', 'admin_reverse', (['"""placeholderapp_example1_edit_field"""'], {'args': '(self.pk, language)'}), "('placeholderapp_example1_edit_field', args=(self.pk, language))\n", (1481, 1545), False, 'from cms.utils.urlutils import admin_reverse\n'), ((2998, 3041), 'django.db.models.CharField', 'models.CharField', (['u"""char_1"""'], {'max_length': '(255)'}), "(u'char_1', max_length=255)\n", (3014, 3041), False, 'from django.db import models\n'), ((3058, 3101), 'django.db.models.CharField', 'models.CharField', (['u"""char_2"""'], {'max_length': '(255)'}), "(u'char_2', max_length=255)\n", (3074, 3101), False, 'from django.db import models\n')]