<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.timezone import now

from model_utils.models import TimeFramedModel
from taggit.managers import TaggableManager


@python_2_unicode_compatible
class Content(TimeFramedModel):
    name = models.CharField(
        max_length=255,
    )
    description = models.TextField(
        blank=True,
    )

    tags = TaggableManager()

    class Meta:
        abstract = True

    def __str__(self):
        return self.name

    def active(self):
        return (self.start is None or self.start <= now()) and (self.end is None or self.end >= now())

    def get_absolute_url(self):
        return reverse("signage:%s_update" % self._meta.verbose_name, args=[self.pk])

    def get_displays(self):
        return Display.objects.filter(tags__name__in=self.tags.names()).distinct()


class Slide(Content):
    image = models.ImageField(
        upload_to='slides/',
    )
    duration = models.PositiveIntegerField(
        default=10,
        choices=[(i, i) for i in range(5, 65, 5)],
    )
    weight = models.SmallIntegerField(
        default=0,
        choices=[(i, i) for i in range(-10, 11)],
    )


class Video(Content):
    url = models.URLField()


@python_2_unicode_compatible
class Display(models.Model):
    name = models.CharField(
        max_length=255,
    )
    description = models.TextField(
        blank=True,
    )
    update_interval = models.PositiveIntegerField(
        default=10,
        choices=[(i, i) for i in range(10, 70, 10)],
    )

    tags = TaggableManager()

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return reverse('signage:display_update', args=[self.pk])

    def get_slides(self):
        return Slide.timeframed.filter(tags__name__in=self.tags.names()).order_by('weight').distinct()

    def get_video(self):
        return Video.timeframed.filter(tags__name__in=self.tags.names()).distinct().first()<commit_msg>Sort slides in descending order by weight<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.timezone import now

from model_utils.models import TimeFramedModel
from taggit.managers import TaggableManager


@python_2_unicode_compatible
class Content(TimeFramedModel):
    name = models.CharField(
        max_length=255,
    )
    description = models.TextField(
        blank=True,
    )

    tags = TaggableManager()

    class Meta:
        abstract = True

    def __str__(self):
        return self.name

    def active(self):
        return (self.start is None or self.start <= now()) and (self.end is None or self.end >= now())

    def get_absolute_url(self):
        return reverse("signage:%s_update" % self._meta.verbose_name, args=[self.pk])

    def get_displays(self):
        return Display.objects.filter(tags__name__in=self.tags.names()).distinct()


class Slide(Content):
    image = models.ImageField(
        upload_to='slides/',
    )
    duration = models.PositiveIntegerField(
        default=10,
        choices=[(i, i) for i in range(5, 65, 5)],
    )
    weight = models.SmallIntegerField(
        default=0,
        choices=[(i, i) for i in range(-10, 11)],
    )


class Video(Content):
    url = models.URLField()


@python_2_unicode_compatible
class Display(models.Model):
    name = models.CharField(
        max_length=255,
    )
    description = models.TextField(
        blank=True,
    )
    update_interval = models.PositiveIntegerField(
        default=10,
        choices=[(i, i) for i in range(10, 70, 10)],
    )

    tags = TaggableManager()

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return reverse('signage:display_update', args=[self.pk])

    def get_slides(self):
        return Slide.timeframed.filter(tags__name__in=self.tags.names()).order_by('-weight').distinct()

    def get_video(self):
        return Video.timeframed.filter(tags__name__in=self.tags.names()).distinct().first()
{'fraction_non_alphanumeric': 0.11006363422107, 'fraction_numerical': 0.013198208814518029, 'mean_word_length': 3.168958742632613, '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': '4073249', 'n_tokens_mistral': 1363, 'n_tokens_neox': 1283, 'n_words': 289}