<commit_before>#coding=utf-8
from django.db import models
from django.db.models.base import ModelBase
from django.db.models.fields import Field
from django.utils.translation import ugettext_lazy as _
from pagebase.models.fields import IntegerArrayField, AutoSlugField
from pagebase.models.utils import register


SECTIONS = (
    ('main', _('Main')),
    ('eyebrow', _('Eyebrow')),
)


class PageBaseMeta(ModelBase):
    base_fields = {}

    def __new__(cls, name, bases, attrs):
        for k, v in attrs.items():
            if isinstance(v, Field):
                cls.base_fields[k] = attrs.pop(k)
        return ModelBase.__new__(cls, name, bases, attrs)


class PageMeta(PageBaseMeta):
    """
    This is what implementing classes need to use
    """
    def __new__(cls, name, bases, attrs):
        for k, v in cls.base_fields.items():
            if k not in attrs:
                attrs[k] = cls.base_fields.pop(k)
        page_cls = ModelBase.__new__(cls, name, bases, attrs)
        # might as well register the listeners to update tree here
        register(page_cls)
        return page_cls


class PageBase(models.Model):
    __metaclass__ = PageBaseMeta
    section = models.CharField(_('section'), choices=SECTIONS, max_length=10, blank=True)
    parent = models.ForeignKey('self', verbose_name=_(u'parent'), blank=True, null=True, related_name='children')
    title = models.CharField(_('title'), max_length=500)
    slug = AutoSlugField(max_length=510, blank=True)
    position = models.IntegerField(_('position'), default=0)

    # tree denormalizarion
    level = models.PositiveIntegerField(null=True, editable=False)
    url = models.CharField(max_length=500, db_index=True, blank=True, editable=False)
    id_array = IntegerArrayField(null=True, editable=False)
    position_array = IntegerArrayField(null=True, editable=False)

    def children_or_siblings(self):
        children = self.children.all()
        if children:
            return children
        if self.level > 1:
            return self._default_manager.filter(parent=self.parent)
        return []

    def get_absolute_url(self):<commit_msg>no need to pop the base_fields<commit_after>#coding=utf-8
from django.db import models
from django.db.models.base import ModelBase
from django.db.models.fields import Field
from django.utils.translation import ugettext_lazy as _
from pagebase.models.fields import IntegerArrayField, AutoSlugField
from pagebase.models.utils import register


SECTIONS = (
    ('main', _('Main')),
    ('eyebrow', _('Eyebrow')),
)


class PageBaseMeta(ModelBase):
    base_fields = {}

    def __new__(cls, name, bases, attrs):
        for k, v in attrs.items():
            if isinstance(v, Field):
                cls.base_fields[k] = attrs.pop(k)
        return ModelBase.__new__(cls, name, bases, attrs)


class PageMeta(PageBaseMeta):
    """
    This is what implementing classes need to use
    """
    def __new__(cls, name, bases, attrs):
        for k, v in cls.base_fields.items():
            if k not in attrs:
                attrs[k] = cls.base_fields[k]
        page_cls = ModelBase.__new__(cls, name, bases, attrs)
        # might as well register the listeners to update tree here
        register(page_cls)
        return page_cls


class PageBase(models.Model):
    __metaclass__ = PageBaseMeta
    section = models.CharField(_('section'), choices=SECTIONS, max_length=10, blank=True)
    parent = models.ForeignKey('self', verbose_name=_(u'parent'), blank=True, null=True, related_name='children')
    title = models.CharField(_('title'), max_length=500)
    slug = AutoSlugField(max_length=510, blank=True)
    position = models.IntegerField(_('position'), default=0)

    # tree denormalizarion
    level = models.PositiveIntegerField(null=True, editable=False)
    url = models.CharField(max_length=500, db_index=True, blank=True, editable=False)
    id_array = IntegerArrayField(null=True, editable=False)
    position_array = IntegerArrayField(null=True, editable=False)

    def children_or_siblings(self):
        children = self.children.all()
        if children:
            return children
        if self.level > 1:
            return self._default_manager.filter(parent=self.parent)
        return []

    def get_absolute_url(self):
{'fraction_non_alphanumeric': 0.10945157526254376, 'fraction_numerical': 0.006534422403733956, 'mean_word_length': 3.4322647362978285, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6476069', 'n_tokens_mistral': 1320, 'n_tokens_neox': 1291, 'n_words': 316}