<commit_before>from django.db import models
from django.template.loader import render_to_string
from django.utils import translation
from django.utils.translation import ugettext as _

import jingo
from jinja2 import Markup
from feincms.module.medialibrary.fields import MediaFileForeignKey
from feincms.module.medialibrary.models import MediaFile
from feincms.module.page.models import Page

from .forms import FeinCMSInline, MediaFileInline
from .utils import youtube_embed_url


jingo.env.install_gettext_translations(translation)

Page.register_templates(
    {
        'title': 'Content template',
        'path': 'content.html',
        'regions': (
            ('main', 'Main content area'),
            ('homepage', 'Homepage navigation'),
        ),
    },
    {
        'title': 'Home template',
        'path': 'home.html',
        'regions': (
            ('main', 'Main content area'),
        ),
    }
)


class YouTubeParagraphEntry(models.Model):
    feincms_item_editor_inline = FeinCMSInline
    title = models.CharField(max_length=255)
    subheader_2 = models.CharField(max_length=255, blank=True)
    subheader_3 = models.CharField(max_length=255, blank=True)
    text = models.TextField(help_text='HTML is allowed.')
    youtube_id = models.CharField(max_length=100)
    _l10n_fields = ['title', 'text', 'youtube_id']

    class Meta:
        abstract = True

    def render(self, **kwargs):
        return render_to_string(
            'includes/videoparagraph.html',
            {
                'title': _(self.title),
                'subheader_2': _(self.subheader_2) if self.subheader_2 else '',
                'subheader_3': _(self.subheader_3) if self.subheader_3 else '',
                'text': Markup(_(self.text)),
                'video': youtube_embed_url(
                    kwargs.get('request'), self.youtube_id)
            }
        )


class ImageParagraphEntry(models.Model):
    feincms_item_editor_inline = MediaFileInline
    image = MediaFileForeignKey(MediaFile)
    alt = models.CharField(max_length=255, blank=True, default='')
    title = models.CharField(max_length=255)
    subheader_2 = models.CharField(max_length=255, blank=True)
    subheader_3 = models.CharField(max_length=255, blank=True)
    text = models.TextField(help_text='HTML is allowed.')
    _l10n_fields = ['alt', 'title', 'text']

    class Meta:
        abstract = True

    def render(self, **kwargs):
        return render_to_string(
            'includes/imageparagraph.html',
            {
                'alt': _(self.alt) if self.alt else '',
                'title': _(self.title),
                'text': Markup(_(self.text)),
                'subheader_2': _(self.subheader_2) if self.subheader_2 else '',
                'subheader_3': _(self.subheader_3) if self.subheader_3 else '',
                'image': self.image,
            }
        )


class FAQEntry(models.Model):
    feincms_item_editor_inline = FeinCMSInline
    question = models.CharField(max_length=255)
    answer = models.TextField(help_text='HTML is allowed.')
    _l10n_fields = ['question', 'answer']

    class Meta:
        abstract = True

    def render(self, **kwargs):
        return render_to_string(
            'includes/faqentry.html',
            {
                'question': _(self.question),
                'answer': Markup(_(self.answer)),
            }
        )


class RichTextEntry(models.Model):
    feincms_item_editor_inline = FeinCMSInline
    title = models.CharField(max_length=255, blank=True)
    subheader_2 = models.CharField(max_length=255, blank=True)
    subheader_3 = models.CharField(max_length=255, blank=True)
    text = models.TextField(help_text='HTML is allowed.')
    _l10n_fields = ['text']

    class Meta:
        abstract = True

    def render(self, **kwargs):
        return render_to_string(
            'includes/richtextentry.html',
            {
                'title': _(self.title) if self.subheader_2 else '',
                'subheader_2': _(self.subheader_2) if self.subheader_2 else '',
                'subheader_3': _(self.subheader_3) if self.subheader_3 else '',
                'text': Markup(_(self.text)),
            }
        )


class QuizQuestion(models.Model):
    feincms_item_editor_inline = MediaFileInline
    image = MediaFileForeignKey(
        MediaFile,
        limit_choices_to=models.Q(type='image', categories__title='en'),
        blank=True, null=True)
    question = models.TextField(help_text='HTML is allowed.')
    correct_feedback = models.TextField(help_text='HTML is allowed.')
    incorrect_feedback = models.TextField(help_text='HTML is allowed.')
    partly_correct_feedback = models.TextField(help_text='HTML is allowed.')
    _l10n_fields = ['question', 'correct_feedback', 'incorrect_feedback',
                    'partly_correct_feedback']<commit_msg>Fix title typo<commit_after>from django.db import models
from django.template.loader import render_to_string
from django.utils import translation
from django.utils.translation import ugettext as _

import jingo
from jinja2 import Markup
from feincms.module.medialibrary.fields import MediaFileForeignKey
from feincms.module.medialibrary.models import MediaFile
from feincms.module.page.models import Page

from .forms import FeinCMSInline, MediaFileInline
from .utils import youtube_embed_url


jingo.env.install_gettext_translations(translation)

Page.register_templates(
    {
        'title': 'Content template',
        'path': 'content.html',
        'regions': (
            ('main', 'Main content area'),
            ('homepage', 'Homepage navigation'),
        ),
    },
    {
        'title': 'Home template',
        'path': 'home.html',
        'regions': (
            ('main', 'Main content area'),
        ),
    }
)


class YouTubeParagraphEntry(models.Model):
    feincms_item_editor_inline = FeinCMSInline
    title = models.CharField(max_length=255)
    subheader_2 = models.CharField(max_length=255, blank=True)
    subheader_3 = models.CharField(max_length=255, blank=True)
    text = models.TextField(help_text='HTML is allowed.')
    youtube_id = models.CharField(max_length=100)
    _l10n_fields = ['title', 'text', 'youtube_id']

    class Meta:
        abstract = True

    def render(self, **kwargs):
        return render_to_string(
            'includes/videoparagraph.html',
            {
                'title': _(self.title),
                'subheader_2': _(self.subheader_2) if self.subheader_2 else '',
                'subheader_3': _(self.subheader_3) if self.subheader_3 else '',
                'text': Markup(_(self.text)),
                'video': youtube_embed_url(
                    kwargs.get('request'), self.youtube_id)
            }
        )


class ImageParagraphEntry(models.Model):
    feincms_item_editor_inline = MediaFileInline
    image = MediaFileForeignKey(MediaFile)
    alt = models.CharField(max_length=255, blank=True, default='')
    title = models.CharField(max_length=255)
    subheader_2 = models.CharField(max_length=255, blank=True)
    subheader_3 = models.CharField(max_length=255, blank=True)
    text = models.TextField(help_text='HTML is allowed.')
    _l10n_fields = ['alt', 'title', 'text']

    class Meta:
        abstract = True

    def render(self, **kwargs):
        return render_to_string(
            'includes/imageparagraph.html',
            {
                'alt': _(self.alt) if self.alt else '',
                'title': _(self.title),
                'text': Markup(_(self.text)),
                'subheader_2': _(self.subheader_2) if self.subheader_2 else '',
                'subheader_3': _(self.subheader_3) if self.subheader_3 else '',
                'image': self.image,
            }
        )


class FAQEntry(models.Model):
    feincms_item_editor_inline = FeinCMSInline
    question = models.CharField(max_length=255)
    answer = models.TextField(help_text='HTML is allowed.')
    _l10n_fields = ['question', 'answer']

    class Meta:
        abstract = True

    def render(self, **kwargs):
        return render_to_string(
            'includes/faqentry.html',
            {
                'question': _(self.question),
                'answer': Markup(_(self.answer)),
            }
        )


class RichTextEntry(models.Model):
    feincms_item_editor_inline = FeinCMSInline
    title = models.CharField(max_length=255, blank=True)
    subheader_2 = models.CharField(max_length=255, blank=True)
    subheader_3 = models.CharField(max_length=255, blank=True)
    text = models.TextField(help_text='HTML is allowed.')
    _l10n_fields = ['text']

    class Meta:
        abstract = True

    def render(self, **kwargs):
        return render_to_string(
            'includes/richtextentry.html',
            {
                'title': _(self.title) if self.title else '',
                'subheader_2': _(self.subheader_2) if self.subheader_2 else '',
                'subheader_3': _(self.subheader_3) if self.subheader_3 else '',
                'text': Markup(_(self.text)),
            }
        )


class QuizQuestion(models.Model):
    feincms_item_editor_inline = MediaFileInline
    image = MediaFileForeignKey(
        MediaFile,
        limit_choices_to=models.Q(type='image', categories__title='en'),
        blank=True, null=True)
    question = models.TextField(help_text='HTML is allowed.')
    correct_feedback = models.TextField(help_text='HTML is allowed.')
    incorrect_feedback = models.TextField(help_text='HTML is allowed.')
    partly_correct_feedback = models.TextField(help_text='HTML is allowed.')
    _l10n_fields = ['question', 'correct_feedback', 'incorrect_feedback',
                    'partly_correct_feedback']
{'fraction_non_alphanumeric': 0.11469165036548955, 'fraction_numerical': 0.014722536806342015, 'mean_word_length': 2.7005714285714286, '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': '3197247', 'n_tokens_mistral': 3017, 'n_tokens_neox': 2876, 'n_words': 563}