<commit_before>from django.template.defaultfilters import slugify
from django.contrib.sites.models import Site
from django.contrib.auth.models import User
from django.conf import settings
from django.db import models

from taggit.managers import TaggableManager

from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter


#site = Site.objects.all()[0]

class Snipt(models.Model):
    """An individual Snipt."""

    user     = models.ForeignKey(User)

    title    = models.CharField(max_length=255)
    description = models.TextField(blank=True, null=True)
    slug     = models.SlugField(max_length=255, blank=True)
    tags     = TaggableManager()

    lexer    = models.CharField(max_length=50)
    code     = models.TextField()
    stylized = models.TextField()
    line_count = models.IntegerField(blank=True, null=True, default=None)

    key      = models.CharField(max_length=100)
    public   = models.BooleanField(default=False)
    
    # TODO Set back to True for production!
    created  = models.DateTimeField(auto_now_add=False, editable=False)
    modified = models.DateTimeField(auto_now=False, editable=False)

    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = slugify(self.title)[:50]

        return super(Snipt, self).save(*args, **kwargs)

    def __unicode__(self):
        return self.title

    def get_absolute_url(self):
        return "/%s/%s/" % (self.user.username, self.slug)

    #TODO This needs to be deprecated - render stylized version on save
    def get_stylized(self):
        if self.stylized == '':
            self.stylized = highlight(self.code,
                                      get_lexer_by_name(self.lexer, encoding='UTF-8'),
                                      HtmlFormatter())
            self.save()
            return self.stylized
        else:
            return self.stylized

    #TODO This needs to be deprecated - render line count on save
    def get_line_count(self):
        if not self.line_count:
            self.line_count = len(self.code.split('\n'))
            self.save()
            return self.line_count
        else:
            return self.line_count

    #def get_embed_url(self):
        #return 'http%s://%s/embed/%s/' % ('s' if settings.USE_HTTPS else '',
                                          #site.domain,
                                          #self.key)

    @property
    def lexer_name(self):<commit_msg>Revert back now that db is populated<commit_after>from django.template.defaultfilters import slugify
from django.contrib.sites.models import Site
from django.contrib.auth.models import User
from django.conf import settings
from django.db import models

from taggit.managers import TaggableManager

from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter


site = Site.objects.all()[0]

class Snipt(models.Model):
    """An individual Snipt."""

    user     = models.ForeignKey(User)

    title    = models.CharField(max_length=255)
    description = models.TextField(blank=True, null=True)
    slug     = models.SlugField(max_length=255, blank=True)
    tags     = TaggableManager()

    lexer    = models.CharField(max_length=50)
    code     = models.TextField()
    stylized = models.TextField()
    line_count = models.IntegerField(blank=True, null=True, default=None)

    key      = models.CharField(max_length=100)
    public   = models.BooleanField(default=False)
    
    # TODO Set back to True for production!
    created  = models.DateTimeField(auto_now_add=False, editable=False)
    modified = models.DateTimeField(auto_now=False, editable=False)

    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = slugify(self.title)[:50]

        return super(Snipt, self).save(*args, **kwargs)

    def __unicode__(self):
        return self.title

    def get_absolute_url(self):
        return "/%s/%s/" % (self.user.username, self.slug)

    #TODO This needs to be deprecated - render stylized version on save
    def get_stylized(self):
        if self.stylized == '':
            self.stylized = highlight(self.code,
                                      get_lexer_by_name(self.lexer, encoding='UTF-8'),
                                      HtmlFormatter())
            self.save()
            return self.stylized
        else:
            return self.stylized

    #TODO This needs to be deprecated - render line count on save
    def get_line_count(self):
        if not self.line_count:
            self.line_count = len(self.code.split('\n'))
            self.save()
            return self.line_count
        else:
            return self.line_count

    def get_embed_url(self):
        return 'http%s://%s/embed/%s/' % ('s' if settings.USE_HTTPS else '',
                                          site.domain,
                                          self.key)

    @property
    def lexer_name(self):
{'fraction_non_alphanumeric': 0.09852707006369427, 'fraction_numerical': 0.005971337579617835, 'mean_word_length': 2.334439283344393, '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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3705860', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1435, 'n_words': 341}