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

from opps.core.models.publishable import Publishable



class Channel(Publishable):

    name = models.CharField(_(u"Name"), max_length=60, unique=True)
    slug = models.SlugField(u"URL", max_length=150, unique=True,
            db_index=True)
    description = models.CharField(_(u"Description"),
            max_length=255, null=True, blank=True)
    position = models.IntegerField(_(u"Position"), default=1)
    channel = models.ForeignKey('self', related_name='subchannel',
            null=True, blank=True)

    class Meta:
        app_label = 'core'

    def __unicode__(self):
        if self.channel:
            return "%s/%s" % (self.channel, self.slug)
        return "%s/%s" % (self.site.domain, self.slug)

    def clean(self):

        try:
            channel_exist_domain = Channel.objects.filter(slug=self.slug,
                    site__domain=self.site.domain)
            channel_home = Channel.objects.filter(site__domain=self.site.domain,
                    channel=None, published=True)
        except ObjectDoesNotExist:
            return False

        if len(channel_exist_domain) >= 1 and not self.pk:
            raise ValidationError('Slug exist in domain!')

        if not self.channel and len(channel_home) >= 1 and not self.pk:
            raise ValidationError('Exist home channel published!')
<commit_msg>Create slug name on channel models core, return slug URL string use on URLs<commit_after># -*- coding: utf-8 -*-
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.core.exceptions import ValidationError, ObjectDoesNotExist

from opps.core.models.publishable import Publishable



class Channel(Publishable):

    name = models.CharField(_(u"Name"), max_length=60, unique=True)
    slug = models.SlugField(u"URL", max_length=150, unique=True,
            db_index=True)
    description = models.CharField(_(u"Description"),
            max_length=255, null=True, blank=True)
    position = models.IntegerField(_(u"Position"), default=1)
    channel = models.ForeignKey('self', related_name='subchannel',
            null=True, blank=True)

    class Meta:
        app_label = 'core'

    def slug_name(self):
        return "{0}/{1}".format(self.channel, self.slug).replace(self.site.domain, '')

    def __unicode__(self):
        if self.channel:
            return "%s/%s" % (self.channel, self.slug)
        return "%s/%s" % (self.site.domain, self.slug)

    def clean(self):

        try:
            channel_exist_domain = Channel.objects.filter(slug=self.slug,
                    site__domain=self.site.domain)
            channel_home = Channel.objects.filter(site__domain=self.site.domain,
                    channel=None, published=True)
        except ObjectDoesNotExist:
            return False

        if len(channel_exist_domain) >= 1 and not self.pk:
            raise ValidationError('Slug exist in domain!')

        if not self.channel and len(channel_home) >= 1 and not self.pk:
            raise ValidationError('Exist home channel published!')

{'fraction_non_alphanumeric': 0.11152073732718894, 'fraction_numerical': 0.007987711213517665, 'mean_word_length': 2.876190476190476, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6409094', 'n_tokens_mistral': 974, 'n_tokens_neox': 935, 'n_words': 218}