<commit_before>from django.db import models
from django.utils.safestring import mark_safe
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.contrib.auth.models import User
from django.contrib.sites.models import Site

from django_extensions.db.fields import CreationDateTimeField
from django_extensions.db.fields import ModificationDateTimeField
from django_extensions.db.fields import AutoSlugField

from taggit.managers import TaggableManager

from positions.fields import PositionField

FORMAT_CHOICES = (
    ('html', 'html'),
    ('markdown', 'markdown'),
    ('textile', 'textile'),
    ('restructuredtext', 'restructuredtext')
)

class CommonAbstractManager(models.Manager):

    def get_active(self):
        return self.get_query_set().filter(active=True)


class TextMixin(object):
    def get_text_block(self):
        return {
            'text': self.text,
            'format': self.format,
            'render_as_template': self.render_as_template,
        }

class CommonAbstractModel(models.Model):
    """
    Common ABC for most models.
    Provides created/updated_at, and active/inactive status.
    """
    created_at = CreationDateTimeField()
    updated_at = ModificationDateTimeField()
    active = models.BooleanField(default=True, verbose_name="published")
    objects = CommonAbstractManager()

    class Meta:
        get_latest_by = 'updated_at'
        ordering = ('-updated_at', '-created_at')
        abstract = True
    
    def get_class_name(self):
        return self.__class__.__name__


class NavigationGroup(models.Model):
    title = models.CharField(max_length=255)
    
    class Meta:
        ordering = ('title',)
    
    def __unicode__(self):
        return self.title

class Navigation(TextMixin, CommonAbstractModel):
    """
    Navigation and Page combined model
    Customizations on One-To-One in implementing app
    """
    title = models.CharField(max_length=255)
    slug = AutoSlugField(editable=True, populate_from='title')
    group = models.ForeignKey(NavigationGroup, blank=True, null=True)
    parent = models.ForeignKey('self', blank=True, null=True, related_name='children')
    order = PositionField(collection='parent')
    site = models.ForeignKey(Site, related_name='pages')
    homepage = models.BooleanField(default=False)
    url = models.CharField(max_length=255, blank=True, default='', help_text='eg. link somewhere else http://awesome.com/ or /awesome/page/')
    target = models.CharField(max_length=255, blank=True, default='', help_text='eg. open link in "_blank" window')
    page_title = models.CharField(max_length=255, blank=True, default='', help_text='Optional html title')
    text = models.TextField(blank=True, default='')
    format = models.CharField(max_length=255, blank=True, default='', choices=FORMAT_CHOICES)
    render_as_template = models.BooleanField(default=False)
    template = models.CharField(max_length=255, blank=True, default='', help_text='Eg. common/awesome.html')
    view = models.CharField(max_length=255, blank=True, default='', help_text='Eg. common.views.awesome')
    seo_title = models.CharField(max_length=255, blank=True, default='', help_text='Complete html title replacement')
    seo_description = models.TextField(blank=True, default='')
    seo_keywords = models.TextField(blank=True, default='')
    inherit_blocks = models.BooleanField(default=True, verbose_name="Inherit Blocks")

    class Meta:
        unique_together = (('site', 'slug', 'parent'),)
        ordering = ['site', 'title']
        verbose_name_plural = 'Navigation'

    def __unicode__(self):
        return self._chain()
<commit_msg>Fix order bug for multisite setup<commit_after>from django.db import models
from django.utils.safestring import mark_safe
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.contrib.auth.models import User
from django.contrib.sites.models import Site

from django_extensions.db.fields import CreationDateTimeField
from django_extensions.db.fields import ModificationDateTimeField
from django_extensions.db.fields import AutoSlugField

from taggit.managers import TaggableManager

from positions.fields import PositionField

FORMAT_CHOICES = (
    ('html', 'html'),
    ('markdown', 'markdown'),
    ('textile', 'textile'),
    ('restructuredtext', 'restructuredtext')
)

class CommonAbstractManager(models.Manager):

    def get_active(self):
        return self.get_query_set().filter(active=True)


class TextMixin(object):
    def get_text_block(self):
        return {
            'text': self.text,
            'format': self.format,
            'render_as_template': self.render_as_template,
        }

class CommonAbstractModel(models.Model):
    """
    Common ABC for most models.
    Provides created/updated_at, and active/inactive status.
    """
    created_at = CreationDateTimeField()
    updated_at = ModificationDateTimeField()
    active = models.BooleanField(default=True, verbose_name="published")
    objects = CommonAbstractManager()

    class Meta:
        get_latest_by = 'updated_at'
        ordering = ('-updated_at', '-created_at')
        abstract = True
    
    def get_class_name(self):
        return self.__class__.__name__


class NavigationGroup(models.Model):
    title = models.CharField(max_length=255)
    
    class Meta:
        ordering = ('title',)
    
    def __unicode__(self):
        return self.title

class Navigation(TextMixin, CommonAbstractModel):
    """
    Navigation and Page combined model
    Customizations on One-To-One in implementing app
    """
    title = models.CharField(max_length=255)
    slug = AutoSlugField(editable=True, populate_from='title')
    group = models.ForeignKey(NavigationGroup, blank=True, null=True)
    parent = models.ForeignKey('self', blank=True, null=True, related_name='children')
    order = PositionField(collection=('parent', 'site'))
    site = models.ForeignKey(Site, related_name='pages')
    homepage = models.BooleanField(default=False)
    url = models.CharField(max_length=255, blank=True, default='', help_text='eg. link somewhere else http://awesome.com/ or /awesome/page/')
    target = models.CharField(max_length=255, blank=True, default='', help_text='eg. open link in "_blank" window')
    page_title = models.CharField(max_length=255, blank=True, default='', help_text='Optional html title')
    text = models.TextField(blank=True, default='')
    format = models.CharField(max_length=255, blank=True, default='', choices=FORMAT_CHOICES)
    render_as_template = models.BooleanField(default=False)
    template = models.CharField(max_length=255, blank=True, default='', help_text='Eg. common/awesome.html')
    view = models.CharField(max_length=255, blank=True, default='', help_text='Eg. common.views.awesome')
    seo_title = models.CharField(max_length=255, blank=True, default='', help_text='Complete html title replacement')
    seo_description = models.TextField(blank=True, default='')
    seo_keywords = models.TextField(blank=True, default='')
    inherit_blocks = models.BooleanField(default=True, verbose_name="Inherit Blocks")

    class Meta:
        unique_together = (('site', 'slug', 'parent'),)
        ordering = ['site', 'title']
        verbose_name_plural = 'Navigation'

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

{'fraction_non_alphanumeric': 0.116182014001077, 'fraction_numerical': 0.007269789983844911, 'mean_word_length': 4.3102215868477485, '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': '5860365', 'n_tokens_mistral': 2210, 'n_tokens_neox': 2128, 'n_words': 474}