<s> from django . db import models <EOL> from django . contrib . auth . models import User <EOL> from pygments . lexers import get_all_lexers <EOL> from pygments . styles import get_all_styles <EOL> from pygments . lexers import get_lexer_by_name <EOL> from pygments . formatters . html import HtmlFormatter <EOL> from pygments import highlight <EOL> LEXERS = [ item for item in get_all_lexers ( ) if item [ <NUM_LIT:1> ] ] <EOL> LANGUAGE_CHOICES = sorted ( [ ( item [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , item [ <NUM_LIT:0> ] ) for item in LEXERS ] ) <EOL> STYLE_CHOICES = sorted ( ( item , item ) for item in get_all_styles ( ) ) <EOL> class Snippet ( models . Model ) : <EOL> created = models . DateTimeField ( auto_now_add = True ) <EOL> title = models . CharField ( max_length = <NUM_LIT:100> , default = '<STR_LIT>' ) <EOL> code = models . TextField ( ) <EOL> linenos = models . BooleanField ( default = False ) <EOL> language = models . CharField ( choices = LANGUAGE_CHOICES , <EOL> default = '<STR_LIT>' , <EOL> max_length = <NUM_LIT:100> ) <EOL> style = models . CharField ( choices = STYLE_CHOICES , <EOL> default = '<STR_LIT>' , <EOL> max_length = <NUM_LIT:100> ) <EOL> owner = models . ForeignKey ( '<STR_LIT>' , related_name = '<STR_LIT>' ) <EOL> highlighted = models . TextField ( ) <EOL> class Meta : <EOL> ordering = ( '<STR_LIT>' , ) <EOL> def save ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> lexer = get_lexer_by_name ( self . language ) <EOL> linenos = self . linenos and '<STR_LIT>' or False <EOL> options = self . title and { '<STR_LIT:title>' : self . title } or { } <EOL> formatter = HtmlFormatter ( style = self . style , linenos = linenos , <EOL> full = True , ** options ) <EOL> self . highlighted = highlight ( self . code , lexer , formatter ) <EOL> super ( Snippet , self ) . save ( * args , ** kwargs ) </s>
