<commit_before>from django.core.exceptions import ValidationError
from django.core.validators import EMPTY_VALUES
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils.safestring import mark_safe


GLOBAL_OR_LOCAL = ("A Message can be global, or can appear on only "
                   "some pages, but not both.")
WHERE_REQUIRED = ("A Message must either be global, or specify a "
                  "URL prefix it will match.")


class MessageQuerySet(models.QuerySet):
    """
    Custom QuerySet implementing an active() method for only
    retrieving active Messages.

    """
    def active(self):
        return self.filter(is_active=True)


class MessageManager(models.Manager):
    """
    Custom manager using MessageQuerySet and implementing a query
    method for Messages which match a particular URL.

    """
    def get_queryset(self):
        return MessageQuerySet(self.model)

    def active(self):
        return self.get_queryset().active()

    def match(self, url):
        """
        Return a list of all active Messages which match the given
        URL.

        """
        return list({
            message for message in self.active() if
            message.is_global or message.match(url)
        })


@python_2_unicode_compatible
class Message(models.Model):
    """
    A message which may be displayed on some or all pages of a site.

    """
    message = models.TextField()
    is_global = models.BooleanField(
        default=False,
        help_text="If checked, this message will display on all pages."
    )
    is_active = models.BooleanField(
        default=True,
        help_text="Only active messages will be displayed."
    )
    url = models.CharField(
        "URL", max_length=255, blank=True, null=True,
        help_text="Message will be displayed on any URL which matches this."
    )

    objects = MessageManager()<commit_msg>And actually break 3.2 compatibility.<commit_after>from django.core.exceptions import ValidationError
from django.core.validators import EMPTY_VALUES
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils.safestring import mark_safe


GLOBAL_OR_LOCAL = (u"A Message can be global, or can appear on only "
                   u"some pages, but not both.")
WHERE_REQUIRED = (u"A Message must either be global, or specify a "
                  u"URL prefix it will match.")


class MessageQuerySet(models.QuerySet):
    """
    Custom QuerySet implementing an active() method for only
    retrieving active Messages.

    """
    def active(self):
        return self.filter(is_active=True)


class MessageManager(models.Manager):
    """
    Custom manager using MessageQuerySet and implementing a query
    method for Messages which match a particular URL.

    """
    def get_queryset(self):
        return MessageQuerySet(self.model)

    def active(self):
        return self.get_queryset().active()

    def match(self, url):
        """
        Return a list of all active Messages which match the given
        URL.

        """
        return list({
            message for message in self.active() if
            message.is_global or message.match(url)
        })


@python_2_unicode_compatible
class Message(models.Model):
    """
    A message which may be displayed on some or all pages of a site.

    """
    message = models.TextField()
    is_global = models.BooleanField(
        default=False,
        help_text=u"If checked, this message will display on all pages."
    )
    is_active = models.BooleanField(
        default=True,
        help_text=u"Only active messages will be displayed."
    )
    url = models.CharField(
        "URL", max_length=255, blank=True, null=True,
        help_text=u"Message will be displayed on any URL which matches this."
    )

    objects = MessageManager()
{'fraction_non_alphanumeric': 0.08049218149192515, 'fraction_numerical': 0.0030761343245321714, 'mean_word_length': 2.741131351869607, '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': '7441105', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1034, 'n_words': 359}