<commit_before>"""

drylinks.mixins.py
==================

Model mixins for django-link-utils.
Use & combine those to add basic fields & functionality to your custom
Link objects.

"""
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.functional import lazy


class HtmlAttrsMixin(models.Model):
    """
    Common options that can be applied to a Link, LinkType or LinkCategory.

    :css_classes:   Set of classes than can be used when generating the html
                    markup for this object

    """
    css_classes = models.CharField(
        max_length=256,
        verbose_name=_('CSS Classes'),
        blank=True,
    )

    class Meta:
        abstract = True


class LinkHtmlAttrsMixin(HtmlAttrsMixin):
    """
    Common options than can be applied to an individual Link object.

    :target_blank:  Whether or not this link should open in a new tab/window
                    (generated <a> element will include a "target="blank"
                    attribute)
    :title:         The title attribute of this link.

    """
    target_blank = models.BooleanField(
        default=False,
        verbose_name=_('Open in a new window / tab'),
    )
    title = models.CharField(
        max_length=512,
        verbose_name=_('Title'),
        blank=True,
    )

    class Meta:
        abstract = True


class ExternalUrlMixin(models.Model):
    """
    A basic mixin providing a single URLField to store external urls.

    :url:       Django validated URLField.

    """
    url = models.URLField(
        verbose_name=_('URL'),
    )

    class Meta:
        abstract = True


def get_choices():
    return [('foo', 'bar')]


class InternalUrlMixin(ExternalUrlMixin):
    """
    A mixin providing internal links based on a set of models.

    Classes implementing this mixin need to define a QUERYSET field, which
    must be an iterable of available models.

    """

    def __init__(self, *args, **kwargs):
        super(InternalUrlMixin, self).__init__(*args, **kwargs)
        self._meta.get_field_by_name('url')[0]._choices = lazy(
            get_choices, list
        )()

    class Meta:
        abstract = True


class IconMixin(models.Model):
    """
    Provide an icon field to subclasses.

    :icon: An image associated to this link object. Could be used for an actual 
        icon, a clickable image, etc...

    """
    icon = models.ImageField(
        upload_to='drylinks/icons',
        verbose_name=_('Icon'),
        blank=True, null=True,
    )

    class Meta:
        abstract = True<commit_msg>move make choice into class<commit_after>"""

drylinks.mixins.py
==================

Model mixins for django-link-utils.
Use & combine those to add basic fields & functionality to your custom
Link objects.

"""
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.functional import lazy


class HtmlAttrsMixin(models.Model):
    """
    Common options that can be applied to a Link, LinkType or LinkCategory.

    :css_classes:   Set of classes than can be used when generating the html
                    markup for this object

    """
    css_classes = models.CharField(
        max_length=256,
        verbose_name=_('CSS Classes'),
        blank=True,
    )

    class Meta:
        abstract = True


class LinkHtmlAttrsMixin(HtmlAttrsMixin):
    """
    Common options than can be applied to an individual Link object.

    :target_blank:  Whether or not this link should open in a new tab/window
                    (generated <a> element will include a "target="blank"
                    attribute)
    :title:         The title attribute of this link.

    """
    target_blank = models.BooleanField(
        default=False,
        verbose_name=_('Open in a new window / tab'),
    )
    title = models.CharField(
        max_length=512,
        verbose_name=_('Title'),
        blank=True,
    )

    class Meta:
        abstract = True


class ExternalUrlMixin(models.Model):
    """
    A basic mixin providing a single URLField to store external urls.

    :url:       Django validated URLField.

    """
    url = models.URLField(
        verbose_name=_('URL'),
    )

    class Meta:
        abstract = True


class InternalUrlMixin(ExternalUrlMixin):
    """
    A mixin providing internal links based on a set of models.

    Classes implementing this mixin need to define a QUERYSET field, which
    must be an iterable of available models.

    """

    def __init__(self, *args, **kwargs):
        super(InternalUrlMixin, self).__init__(*args, **kwargs)
        self._meta.get_field_by_name('url')[0]._choices = lazy(
            self.get_choices, list
        )()

    class Meta:
        abstract = True

    @staticmethod
    def get_choices():
        return [('foo', 'bar')]


class IconMixin(models.Model):
    """
    Provide an icon field to subclasses.

    :icon: An image associated to this link object. Could be used for an actual 
        icon, a clickable image, etc...

    """
    icon = models.ImageField(
        upload_to='drylinks/icons',
        verbose_name=_('Icon'),
        blank=True, null=True,
    )

    class Meta:
        abstract = True
{'fraction_non_alphanumeric': 0.09511077158135982, 'fraction_numerical': 0.00267379679144385, 'mean_word_length': 2.4184073107049606, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2439490', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1457, 'n_words': 488}