<commit_before># -*- coding: utf-8 -*-
from django.db import models
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django.core.exceptions import ValidationError
from django.contrib.redirects.models import Redirect

from taggit.managers import TaggableManager
from googl.short import GooglUrlShort

from opps.core.models import Publishable, BaseBox, BaseConfig


class Article(Publishable):
    title = models.CharField(_(u"Title"), max_length=140, db_index=True)
    headline = models.TextField(_(u"Headline"), blank=True)
    slug = models.SlugField(
        _(u"URL"),
        db_index=True,
        max_length=150,
        unique=True,
    )
    short_title = models.CharField(
        _(u"Short title"),
        max_length=140,
        null=True, blank=False,
    )
    short_url = models.URLField(
        _("Short URL"),
        null=True, blank=False,
    )
    channel = models.ForeignKey(
        'channels.Channel',
        verbose_name=_(u"Channel"),
    )
    channel_name = models.CharField(
        _(u"Channel name"),
        max_length=140,
        null=True, blank=False,
        db_index=True,
    )
    child_class = models.CharField(
        _(u'Child class'),
        max_length=30,
        null=True, blank=False,
        db_index=True
    )
    main_image = models.ForeignKey(
        'images.Image',
        null=True, blank=False,
        on_delete=models.SET_NULL,
        verbose_name=_(u'Main Image'),
    )
    images = models.ManyToManyField(
        'images.Image',
        null=True, blank=True,
        related_name='article_images',
        through='articles.ArticleImage',
    )
    sources = models.ManyToManyField(
        'sources.Source',
        null=True, blank=True,
        through='articles.ArticleSource',
    )
    tags = TaggableManager(blank=True)

    def __unicode__(self):
        return self.get_absolute_url()

    class Meta:
        ordering = ['-date_available', ]

    def save(self, *args, **kwargs):
        if not self.short_url:
            self.short_url = GooglUrlShort(self.get_http_absolute_url())\
                .short()
        self.channel_name = self.channel.name
        self.child_class = self.__class__.__name__
        super(Article, self).save(*args, **kwargs)

    def get_absolute_url(self):
        return "/{0}/{1}".format(self.channel.long_slug, self.slug)

    def get_http_absolute_url(self):
        return "http://{0}/{1}".format(self.channel, self.slug)
    get_http_absolute_url.short_description = 'URL'

    def recommendation(self):
        return Article.objects.filter(tags__in=self.tags.all()).exclude(
            pk=self.pk)[:10]


class Post(Article):
    content = models.TextField(_(u"Content"))
    albums = models.ManyToManyField(
        'articles.Album',
        null=True, blank=True,
        related_name='post_albums',
    )

    def all_images(self):
        imgs = [i for i in self.images.filter(
            published=True, date_available__lte=timezone.now())]

        imgs += [i for a in self.album.filter(
            published=True, date_available__lte=timezone.now())
            for i in a.images.filter(published=True,
                                     date_available__lte=timezone.now())]
        return imgs

<commit_msg>Fix filed name, album to albums on article type post<commit_after># -*- coding: utf-8 -*-
from django.db import models
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django.core.exceptions import ValidationError
from django.contrib.redirects.models import Redirect

from taggit.managers import TaggableManager
from googl.short import GooglUrlShort

from opps.core.models import Publishable, BaseBox, BaseConfig


class Article(Publishable):
    title = models.CharField(_(u"Title"), max_length=140, db_index=True)
    headline = models.TextField(_(u"Headline"), blank=True)
    slug = models.SlugField(
        _(u"URL"),
        db_index=True,
        max_length=150,
        unique=True,
    )
    short_title = models.CharField(
        _(u"Short title"),
        max_length=140,
        null=True, blank=False,
    )
    short_url = models.URLField(
        _("Short URL"),
        null=True, blank=False,
    )
    channel = models.ForeignKey(
        'channels.Channel',
        verbose_name=_(u"Channel"),
    )
    channel_name = models.CharField(
        _(u"Channel name"),
        max_length=140,
        null=True, blank=False,
        db_index=True,
    )
    child_class = models.CharField(
        _(u'Child class'),
        max_length=30,
        null=True, blank=False,
        db_index=True
    )
    main_image = models.ForeignKey(
        'images.Image',
        null=True, blank=False,
        on_delete=models.SET_NULL,
        verbose_name=_(u'Main Image'),
    )
    images = models.ManyToManyField(
        'images.Image',
        null=True, blank=True,
        related_name='article_images',
        through='articles.ArticleImage',
    )
    sources = models.ManyToManyField(
        'sources.Source',
        null=True, blank=True,
        through='articles.ArticleSource',
    )
    tags = TaggableManager(blank=True)

    def __unicode__(self):
        return self.get_absolute_url()

    class Meta:
        ordering = ['-date_available', ]

    def save(self, *args, **kwargs):
        if not self.short_url:
            self.short_url = GooglUrlShort(self.get_http_absolute_url())\
                .short()
        self.channel_name = self.channel.name
        self.child_class = self.__class__.__name__
        super(Article, self).save(*args, **kwargs)

    def get_absolute_url(self):
        return "/{0}/{1}".format(self.channel.long_slug, self.slug)

    def get_http_absolute_url(self):
        return "http://{0}/{1}".format(self.channel, self.slug)
    get_http_absolute_url.short_description = 'URL'

    def recommendation(self):
        return Article.objects.filter(tags__in=self.tags.all()).exclude(
            pk=self.pk)[:10]


class Post(Article):
    content = models.TextField(_(u"Content"))
    albums = models.ManyToManyField(
        'articles.Album',
        null=True, blank=True,
        related_name='post_albums',
    )

    def all_images(self):
        imgs = [i for i in self.images.filter(
            published=True, date_available__lte=timezone.now())]

        imgs += [i for a in self.albums.filter(
            published=True, date_available__lte=timezone.now())
            for i in a.images.filter(published=True,
                                     date_available__lte=timezone.now())]
        return imgs


{'fraction_non_alphanumeric': 0.11680265941372016, 'fraction_numerical': 0.006346328195829556, 'mean_word_length': 2.585590465872156, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4590478', 'n_tokens_mistral': 2082, 'n_tokens_neox': 2020, 'n_words': 381}