<commit_before>from django.db import models
from pygments.lexers import get_all_lexers
from pygments.styles import get_all_styles

LEXERS = [item for item in get_all_lexers() if item[1]]
LANGUAGE_CHOICES = sorted([(item[1][0], item[0]) for item in LEXERS])
STYLE_CHOICES = sorted((item, item) for item in get_all_styles())


class Snippet(models.Model):
    """
    Model containing a code snippet.

    Fields:
    created - Creation date autopoplulated with now.
    title - User provided title for the snippet.
    code - Code text making up the body of the snippet.
    linenos - Boolean for displaying/hiding line numbers in the snippet.
    language - Coding language of the snippet.
    style - Pygmentize formatting style for the snippet.
    """
    created = models.DateTimeField(auto_now_add=True)
    title = models.CharField(max_length=100, blank=True, default='')
    code = models.TextField()
    linenos = models.BooleanField(default=True)
    language = models.CharField(choices=LANGUAGE_CHOICES, default='python', max_length=100)
    style = models.CharField(choices=STYLE_CHOICES, default='friendly', max_length=100)

    class Meta:
        """
        Provides field to use for ordering upon data retrieval.
        """
        ordering = ('created',)<commit_msg>Added string representation for Snippets with titles<commit_after>from django.db import models
from pygments.lexers import get_all_lexers
from pygments.styles import get_all_styles

LEXERS = [item for item in get_all_lexers() if item[1]]
LANGUAGE_CHOICES = sorted([(item[1][0], item[0]) for item in LEXERS])
STYLE_CHOICES = sorted((item, item) for item in get_all_styles())


class Snippet(models.Model):
    """
    Model containing a code snippet.

    Fields:
    created - Creation date autopoplulated with now.
    title - User provided title for the snippet.
    code - Code text making up the body of the snippet.
    linenos - Boolean for displaying/hiding line numbers in the snippet.
    language - Coding language of the snippet.
    style - Pygmentize formatting style for the snippet.
    """
    created = models.DateTimeField(auto_now_add=True)
    title = models.CharField(max_length=100, blank=True, default='')
    code = models.TextField()
    linenos = models.BooleanField(default=True)
    language = models.CharField(choices=LANGUAGE_CHOICES, default='python', max_length=100)
    style = models.CharField(choices=STYLE_CHOICES, default='friendly', max_length=100)

    def __str__(self):
        if self.title:
            return self.title
        else:
            return self

    class Meta:
        """
        Provides field to use for ordering upon data retrieval.
        """
        ordering = ('created',)
{'fraction_non_alphanumeric': 0.09147685525349009, 'fraction_numerical': 0.009551800146950772, 'mean_word_length': 3.561139028475712, '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': '2836805', 'n_tokens_mistral': 841, 'n_tokens_neox': 773, 'n_words': 250}