<s> import re <EOL> from django . core . exceptions import ValidationError <EOL> from django . db import models <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from taggit . models import Tag <EOL> try : <EOL> import Stemmer <EOL> except ImportError : <EOL> Stemmer = None <EOL> class TagKeyword ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> tag = models . ForeignKey ( Tag , related_name = '<STR_LIT>' ) <EOL> keyword = models . CharField ( max_length = <NUM_LIT:30> ) <EOL> stem = models . CharField ( max_length = <NUM_LIT:30> ) <EOL> def __unicode__ ( self ) : <EOL> return "<STR_LIT>" % ( self . keyword , self . tag . name ) <EOL> def save ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> language = kwargs . pop ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not self . pk and not self . stem and Stemmer : <EOL> stemmer = Stemmer . Stemmer ( language ) <EOL> self . stem = stemmer . stemWord ( self . keyword ) <EOL> super ( TagKeyword , self ) . save ( * args , ** kwargs ) <EOL> def validate_regex ( value ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> re . compile ( value ) <EOL> except Exception : <EOL> raise ValidationError ( '<STR_LIT>' ) <EOL> class TagRegex ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> tag = models . ForeignKey ( Tag , related_name = '<STR_LIT>' ) <EOL> name = models . CharField ( max_length = <NUM_LIT:30> ) <EOL> regex = models . CharField ( <EOL> max_length = <NUM_LIT> , <EOL> validators = [ validate_regex ] , <EOL> help_text = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> ) <EOL> def __unicode__ ( self ) : <EOL> return self . name <EOL> def save ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . full_clean ( ) <EOL> super ( TagRegex , self ) . save ( * args , ** kwargs ) </s>
