<commit_before>from datetime import datetime

from django.db import models
from django.contrib.auth.models import User
from taggit.managers import TaggableManager

from blahhg.managers import LiveEntryManager


class BlahhgEntry(models.Model):
    """
    A blog entry.
    """
    LIVE_STATUS = 1
    DRAFT_STATUS = 2
    HIDDEN_STATUS = 3
    STATUS_CHOICES = (
        (LIVE_STATUS, 'Live'),
        (DRAFT_STATUS, 'Draft'),
        (HIDDEN_STATUS, 'Hidden'),
    )
    
    # Metadata.
    author = models.ForeignKey(User)
    enable_comments = models.BooleanField(
        default=True,
    )
    pub_date = models.DateTimeField(
        u'Date posted',
        default=datetime.today
    )
    status = models.IntegerField(
        choices=STATUS_CHOICES,
        default=LIVE_STATUS,
        help_text=u'Only entries with "live" status will be displayed publicly.'
    )
    title = models.CharField(
        max_length=140,
    )
    slug = models.SlugField(
        unique=True,
        help_text='Used in the URL of the entry. Must be unique.'
    )
    
    # The actual entry bits.
    body = models.TextField()
    body_html = models.TextField(
        editable=False,
        blank=True,
    )
    excerpt = models.TextField(
        blank=True,
        null=True,
    )
    excerpt_html = models.TextField(
        editable=False,
        blank=True,
        null=True,
    )
    
    # Tagging.
    tags = TaggableManager()
    
    # Managers
    live = LiveEntryManager()
    objects = models.Manager()
    
    class Meta:
        get_latest_by = 'pub_date'
        ordering = ['-pub_date']
        verbose_name = 'Entry'
        verbose_name_plural = 'Entries'
    
    class Admin:
        date_hierarchy = 'pub_date'
        fields = (
            ('Metadata', { 'fields':
                ('title', 'slug', 'pub_date', 'author', 'status', 'enable_comments') }),
            ('Entry', { 'fields':
                ('excerpt', 'body') }),
            ('Tags', { 'fields':
                ('tags',) }),
            )
        list_display = ('title', 'pub_date', 'author', 'status', 'enable_comments')
        list_filter = ('status',)
    
    def __unicode__(self):
        return self.title
    
    #TODO use markdown here
    def save(self):
        if self.excerpt:
            self.excerpt_html = self.excerpt
        self.body_html = self.body
        super(BlahhgEntry, self).save()
    
    #TODO clean this up
    def get_absolute_url(self):
        return ('coltrane_entry_detail', (), {
            'year': self.pub_date.strftime('%Y'),
            'month': self.pub_date.strftime('%b').lower(),
            'day': self.pub_date.strftime('%d'),
            'slug': self.slug
        })
    get_absolute_url = models.permalink(get_absolute_url)
    
    def _next_previous_helper(self, direction):
        return getattr(self, 'get_%s_by_pub_date' % direction)(status__exact=self.LIVE_STATUS)
    
    def get_next(self):
        """
        Returns the next Entry with "live" status by ``pub_date``, if
        there is one, or ``None`` if there isn't.
        
        In public-facing templates, use this method instead of
        ``get_next_by_pub_date``, because ``get_next_by_pub_date``
        does not differentiate entry status.
        
        """<commit_msg>Added markdown for body and excerpts.<commit_after>from datetime import datetime
import markdown

from django.db import models
from django.contrib.auth.models import User
from taggit.managers import TaggableManager

from blahhg.managers import LiveEntryManager


class BlahhgEntry(models.Model):
    """
    A blog entry.
    """
    LIVE_STATUS = 1
    DRAFT_STATUS = 2
    HIDDEN_STATUS = 3
    STATUS_CHOICES = (
        (LIVE_STATUS, 'Live'),
        (DRAFT_STATUS, 'Draft'),
        (HIDDEN_STATUS, 'Hidden'),
    )
    
    # Metadata.
    author = models.ForeignKey(User)
    enable_comments = models.BooleanField(
        default=True,
    )
    pub_date = models.DateTimeField(
        u'Date posted',
        default=datetime.today
    )
    status = models.IntegerField(
        choices=STATUS_CHOICES,
        default=LIVE_STATUS,
        help_text=u'Only entries with "live" status will be displayed publicly.'
    )
    title = models.CharField(
        max_length=140,
    )
    slug = models.SlugField(
        unique=True,
        help_text='Used in the URL of the entry. Must be unique.'
    )
    
    # The actual entry bits.
    body = models.TextField()
    body_html = models.TextField(
        editable=False,
        blank=True,
    )
    excerpt = models.TextField(
        blank=True,
        null=True,
    )
    excerpt_html = models.TextField(
        editable=False,
        blank=True,
        null=True,
    )
    
    # Tagging.
    tags = TaggableManager()
    
    # Managers
    live = LiveEntryManager()
    objects = models.Manager()
    
    class Meta:
        get_latest_by = 'pub_date'
        ordering = ['-pub_date']
        verbose_name = 'Entry'
        verbose_name_plural = 'Entries'
    
    class Admin:
        date_hierarchy = 'pub_date'
        fields = (
            ('Metadata', { 'fields':
                ('title', 'slug', 'pub_date', 'author', 'status', 'enable_comments') }),
            ('Entry', { 'fields':
                ('excerpt', 'body') }),
            ('Tags', { 'fields':
                ('tags',) }),
            )
        list_display = ('title', 'pub_date', 'author', 'status', 'enable_comments')
        list_filter = ('status',)
    
    def __unicode__(self):
        return self.title
    
    #TODO use markdown here
    def save(self):
        if self.excerpt:
            self.excerpt_html = markdown.markdown(self.excerpt)
        self.body_html = markdown.markdown(self.body)
        super(BlahhgEntry, self).save()
    
    #TODO clean this up
    def get_absolute_url(self):
        return ('coltrane_entry_detail', (), {
            'year': self.pub_date.strftime('%Y'),
            'month': self.pub_date.strftime('%b').lower(),
            'day': self.pub_date.strftime('%d'),
            'slug': self.slug
        })
    get_absolute_url = models.permalink(get_absolute_url)
    
    def _next_previous_helper(self, direction):
        return getattr(self, 'get_%s_by_pub_date' % direction)(status__exact=self.LIVE_STATUS)
    
    def get_next(self):
        """
        Returns the next Entry with "live" status by ``pub_date``, if
        there is one, or ``None`` if there isn't.
        
        In public-facing templates, use this method instead of
        ``get_next_by_pub_date``, because ``get_next_by_pub_date``
        does not differentiate entry status.
        
        """
{'fraction_non_alphanumeric': 0.11518873576992211, 'fraction_numerical': 0.0017974835230677051, 'mean_word_length': 2.13621418506341, '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': '6563983', 'n_tokens_mistral': 2101, 'n_tokens_neox': 2041, 'n_words': 451}