<commit_before>from __future__ import unicode_literals

from django.core.urlresolvers import reverse
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _

from apps.core.models import Model, TranslationMixin
from apps.domain.models import Attribute, AttributeSet

from .managers import QuestionEntityManager


@python_2_unicode_compatible
class Catalog(Model, TranslationMixin):

    title_en = models.CharField(max_length=256)
    title_de = models.CharField(max_length=256)

    class Meta:
        verbose_name = _('Catalog')
        verbose_name_plural = _('Catalogs')

    def __str__(self):
        return self.title

    @property
    def title(self):
        return self.trans('title')

    def get_absolute_url(self):
        return reverse('catalog', kwargs={'pk': self.pk})


@python_2_unicode_compatible
class Section(Model, TranslationMixin):

    catalog = models.ForeignKey(Catalog, related_name='sections')
    order = models.IntegerField(null=True)

    title_en = models.CharField(max_length=256)
    title_de = models.CharField(max_length=256)

    class Meta:
        ordering = ('order',)
        verbose_name = _('Section')
        verbose_name_plural = _('Sections')

    def __str__(self):
        return '%s / %s' % (self.catalog_title, self.title)

    def get_absolute_url(self):
        return reverse('catalog', kwargs={'pk': self.catalog.pk})

    @property
    def title(self):
        return self.trans('title')

    @property
    def catalog_title(self):
        return self.catalog.title


@python_2_unicode_compatible
class Subsection(Model, TranslationMixin):

    section = models.ForeignKey(Section, related_name='subsections')
    order = models.IntegerField(null=True)

    title_en = models.CharField(max_length=256)
    title_de = models.CharField(max_length=256)

    class Meta:
        ordering = ('order',)
        verbose_name = _('Subsection')
        verbose_name_plural = _('Subsections')

    def __str__(self):
        return '%s / %s / %s' % (self.catalog_title, self.section_title, self.title)

    def get_absolute_url(self):
        return reverse('catalog', kwargs={'pk': self.section.catalog.pk})

    @property
    def title(self):
        return self.trans('title')

    @property
    def catalog_title(self):
        return self.section.catalog.title

    @property
    def section_title(self):
        return self.section.title


class QuestionEntity(Model, TranslationMixin):

    objects = QuestionEntityManager()

    subsection = models.ForeignKey('Subsection', related_name='entities')
    order = models.IntegerField(null=True)

    title_en = models.CharField(max_length=256, null=True, blank=True)
    title_de = models.CharField(max_length=256, null=True, blank=True)

    help_en = models.TextField(null=True, blank=True)
    help_de = models.TextField(null=True, blank=True)

    class Meta:
        ordering = ('order', )
        verbose_name = _('QuestionEntity')
        verbose_name_plural = _('QuestionEntities')

    def __str__(self):
        if self.is_set:
            return self.questionset.__str__()
        else:
            return self.question.__str__()

    def get_absolute_url(self):
        return reverse('catalog', kwargs={'pk': self.subsection.section.catalog.pk})

    @property
    def title(self):
        return self.trans('title')

    @property
    def help(self):
        return self.trans('help')

    @property
    def catalog_title(self):
        return self.subsection.section.catalog.title

    @property
    def section_title(self):
        return self.subsection.section.title

    @property
    def subsection_title(self):
        return self.subsection.title

    @property
    def is_set(self):
        return hasattr(self, 'questionset')

    @property
    def has_set(self):
        return hasattr(self, 'question') and hasattr(self.question, 'questionset') and self.question.questionset

    @property
    def tag(self):
        if self.is_set:
            return self.questionset.tag
        else:
            return self.question.tag

    @property
    def is_collection(self):
        if self.is_set:
            return self.questionset.is_collection
        else:
            return self.question.is_collection


@python_2_unicode_compatible
class QuestionSet(QuestionEntity):

    attributeset = models.ForeignKey(AttributeSet, blank=True, null=True, on_delete=models.SET_NULL, related_name='questionsets')

    class Meta:
        verbose_name = _('QuestionSet')
        verbose_name_plural = _('QuestionSets')

    def __str__(self):
        return '%s / %s / %s / %s' % (self.catalog_title, self.section_title, self.subsection_title, self.title)

    @property
    def tag(self):
        return self.attributeset.tag if self.attributeset else None

    @property
    def is_collection(self):
        return self.attributeset.is_collection if self.attributeset else None


@python_2_unicode_compatible
class Question(QuestionEntity):

    WIDGET_TYPE_CHOICES = (
        ('text', 'Text'),
        ('textarea', 'Textarea'),
        ('yesno', 'Yes/No'),
        ('checkbox', 'Checkboxes'),
        ('radio', 'Radio buttons'),
        ('select', 'Select drop-down'),
        ('range', 'Range slider'),
        ('data', 'Date picker'),
    )

    questionset = models.ForeignKey('QuestionSet', blank=True, null=True, related_name='questions')

    attribute = models.ForeignKey(Attribute, blank=True, null=True, on_delete=models.SET_NULL, related_name='questions')

    text_en = models.TextField()
    text_de = models.TextField()

    widget_type = models.CharField(max_length=12, choices=WIDGET_TYPE_CHOICES)

    class Meta:
        ordering = ('subsection__section__order', 'subsection__order',  'order')
        verbose_name = _('Question')
        verbose_name_plural = _('Questions')

    def __str__(self):
        return '%s / %s / %s / %s' % (self.catalog_title, self.section_title, self.subsection_title, self.title)

    @property
    def text(self):
        return self.trans('text')

    @property
    def tag(self):<commit_msg>fix Question widget_type choices, again<commit_after>from __future__ import unicode_literals

from django.core.urlresolvers import reverse
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _

from apps.core.models import Model, TranslationMixin
from apps.domain.models import Attribute, AttributeSet

from .managers import QuestionEntityManager


@python_2_unicode_compatible
class Catalog(Model, TranslationMixin):

    title_en = models.CharField(max_length=256)
    title_de = models.CharField(max_length=256)

    class Meta:
        verbose_name = _('Catalog')
        verbose_name_plural = _('Catalogs')

    def __str__(self):
        return self.title

    @property
    def title(self):
        return self.trans('title')

    def get_absolute_url(self):
        return reverse('catalog', kwargs={'pk': self.pk})


@python_2_unicode_compatible
class Section(Model, TranslationMixin):

    catalog = models.ForeignKey(Catalog, related_name='sections')
    order = models.IntegerField(null=True)

    title_en = models.CharField(max_length=256)
    title_de = models.CharField(max_length=256)

    class Meta:
        ordering = ('order',)
        verbose_name = _('Section')
        verbose_name_plural = _('Sections')

    def __str__(self):
        return '%s / %s' % (self.catalog_title, self.title)

    def get_absolute_url(self):
        return reverse('catalog', kwargs={'pk': self.catalog.pk})

    @property
    def title(self):
        return self.trans('title')

    @property
    def catalog_title(self):
        return self.catalog.title


@python_2_unicode_compatible
class Subsection(Model, TranslationMixin):

    section = models.ForeignKey(Section, related_name='subsections')
    order = models.IntegerField(null=True)

    title_en = models.CharField(max_length=256)
    title_de = models.CharField(max_length=256)

    class Meta:
        ordering = ('order',)
        verbose_name = _('Subsection')
        verbose_name_plural = _('Subsections')

    def __str__(self):
        return '%s / %s / %s' % (self.catalog_title, self.section_title, self.title)

    def get_absolute_url(self):
        return reverse('catalog', kwargs={'pk': self.section.catalog.pk})

    @property
    def title(self):
        return self.trans('title')

    @property
    def catalog_title(self):
        return self.section.catalog.title

    @property
    def section_title(self):
        return self.section.title


class QuestionEntity(Model, TranslationMixin):

    objects = QuestionEntityManager()

    subsection = models.ForeignKey('Subsection', related_name='entities')
    order = models.IntegerField(null=True)

    title_en = models.CharField(max_length=256, null=True, blank=True)
    title_de = models.CharField(max_length=256, null=True, blank=True)

    help_en = models.TextField(null=True, blank=True)
    help_de = models.TextField(null=True, blank=True)

    class Meta:
        ordering = ('order', )
        verbose_name = _('QuestionEntity')
        verbose_name_plural = _('QuestionEntities')

    def __str__(self):
        if self.is_set:
            return self.questionset.__str__()
        else:
            return self.question.__str__()

    def get_absolute_url(self):
        return reverse('catalog', kwargs={'pk': self.subsection.section.catalog.pk})

    @property
    def title(self):
        return self.trans('title')

    @property
    def help(self):
        return self.trans('help')

    @property
    def catalog_title(self):
        return self.subsection.section.catalog.title

    @property
    def section_title(self):
        return self.subsection.section.title

    @property
    def subsection_title(self):
        return self.subsection.title

    @property
    def is_set(self):
        return hasattr(self, 'questionset')

    @property
    def has_set(self):
        return hasattr(self, 'question') and hasattr(self.question, 'questionset') and self.question.questionset

    @property
    def tag(self):
        if self.is_set:
            return self.questionset.tag
        else:
            return self.question.tag

    @property
    def is_collection(self):
        if self.is_set:
            return self.questionset.is_collection
        else:
            return self.question.is_collection


@python_2_unicode_compatible
class QuestionSet(QuestionEntity):

    attributeset = models.ForeignKey(AttributeSet, blank=True, null=True, on_delete=models.SET_NULL, related_name='questionsets')

    class Meta:
        verbose_name = _('QuestionSet')
        verbose_name_plural = _('QuestionSets')

    def __str__(self):
        return '%s / %s / %s / %s' % (self.catalog_title, self.section_title, self.subsection_title, self.title)

    @property
    def tag(self):
        return self.attributeset.tag if self.attributeset else None

    @property
    def is_collection(self):
        return self.attributeset.is_collection if self.attributeset else None


@python_2_unicode_compatible
class Question(QuestionEntity):

    WIDGET_TYPE_CHOICES = (
        ('text', 'Text'),
        ('textarea', 'Textarea'),
        ('yesno', 'Yes/No'),
        ('checkbox', 'Checkboxes'),
        ('radio', 'Radio buttons'),
        ('select', 'Select drop-down'),
        ('range', 'Range slider'),
        ('date', 'Date picker'),
    )

    questionset = models.ForeignKey('QuestionSet', blank=True, null=True, related_name='questions')

    attribute = models.ForeignKey(Attribute, blank=True, null=True, on_delete=models.SET_NULL, related_name='questions')

    text_en = models.TextField()
    text_de = models.TextField()

    widget_type = models.CharField(max_length=12, choices=WIDGET_TYPE_CHOICES)

    class Meta:
        ordering = ('subsection__section__order', 'subsection__order',  'order')
        verbose_name = _('Question')
        verbose_name_plural = _('Questions')

    def __str__(self):
        return '%s / %s / %s / %s' % (self.catalog_title, self.section_title, self.subsection_title, self.title)

    @property
    def text(self):
        return self.trans('text')

    @property
    def tag(self):
{'fraction_non_alphanumeric': 0.11243514915693904, 'fraction_numerical': 0.005188067444876783, 'mean_word_length': 3.246815834767642, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3185246', 'n_tokens_mistral': 3776, 'n_tokens_neox': 3591, 'n_words': 769}