<s> from django . db import models <EOL> from django . conf import settings <EOL> from django . template . defaultfilters import slugify <EOL> from django . contrib . contenttypes import generic <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from niwi . utils import get_url_data , cacheable <EOL> from niwi . web . forms import LEXER_CHOICES <EOL> from niwi . contrib . db . fields import CreationDateTimeField , ModificationDateTimeField <EOL> import datetime , uuid <EOL> STATUS_CHOICES = ( <EOL> ( '<STR_LIT>' , u'<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , u'<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , u'<STR_LIT>' ) , <EOL> ) <EOL> def slugify_uniquely ( value , model , slugfield = "<STR_LIT>" ) : <EOL> suffix = <NUM_LIT:0> <EOL> potential = base = slugify ( value ) <EOL> if len ( potential ) == <NUM_LIT:0> : <EOL> potential = '<STR_LIT:null>' <EOL> while True : <EOL> if suffix : <EOL> potential = "<STR_LIT:->" . join ( [ base , str ( suffix ) ] ) <EOL> if not model . objects . filter ( ** { slugfield : potential } ) . count ( ) : <EOL> return potential <EOL> suffix += <NUM_LIT:1> <EOL> class Page ( models . Model ) : <EOL> slug = models . SlugField ( max_length = <NUM_LIT:100> , unique = True , db_index = True , editable = True , blank = True ) <EOL> title = models . CharField ( max_length = <NUM_LIT> , db_index = True ) <EOL> content = models . TextField ( ) <EOL> markup = models . BooleanField ( default = False ) <EOL> status = models . CharField ( max_length = <NUM_LIT> , choices = STATUS_CHOICES , db_index = True , default = '<STR_LIT>' ) <EOL> owner = models . ForeignKey ( '<STR_LIT>' , related_name = '<STR_LIT>' , null = True , default = None , blank = True ) <EOL> created_date = CreationDateTimeField ( editable = True ) <EOL> modified_date = ModificationDateTimeField ( editable = True ) <EOL> class Meta : <EOL> db_table = '<STR_LIT>' <EOL> @ models . permalink <EOL> def get_absolute_url ( self ) : <EOL> return ( '<STR_LIT>' , ( ) , { '<STR_LIT>' : self . slug } ) <EOL> def save ( self , * args , ** kwargs ) : <EOL> if not self . slug : <EOL> self . slug = slugify_uniquely ( self . title , self . __class__ ) <EOL> super ( Page , self ) . save ( * args , ** kwargs ) <EOL> def __unicode__ ( self ) : <EOL> return u"<STR_LIT>" % ( self . title ) <EOL> class Post ( models . Model ) : <EOL> slug = models . SlugField ( max_length = <NUM_LIT:100> , unique = True , db_index = True , editable = True , blank = True ) <EOL> title = models . CharField ( max_length = <NUM_LIT> , db_index = True , blank = True ) <EOL> content = models . TextField ( ) <EOL> markup = models . BooleanField ( default = False ) <EOL> owner = models . ForeignKey ( '<STR_LIT>' , related_name = '<STR_LIT>' , null = True , default = None , blank = True ) <EOL> status = models . CharField ( max_length = <NUM_LIT> , choices = STATUS_CHOICES , db_index = True , default = '<STR_LIT>' ) <EOL> tags = models . CharField ( max_length = <NUM_LIT:200> , blank = True , null = True , default = '<STR_LIT>' , db_index = True ) <EOL> created_date = CreationDateTimeField ( editable = True ) <EOL> modified_date = ModificationDateTimeField ( editable = True ) <EOL> class Meta : <EOL> db_table = '<STR_LIT>' <EOL> def __unicode__ ( self ) : <EOL> return u"<STR_LIT>" % ( self . title ) <EOL> def save ( self , * args , ** kwargs ) : <EOL> if not self . slug : <EOL> self . slug = slugify_uniquely ( self . title , self . __class__ ) <EOL> super ( Post , self ) . save ( * args , ** kwargs ) <EOL> @ models . permalink <EOL> def get_absolute_url ( self ) : <EOL> return ( '<STR_LIT>' , ( ) , { '<STR_LIT>' : self . slug } ) <EOL> class PostAttachment ( models . Model ) : <EOL> post = models . ForeignKey ( '<STR_LIT>' , related_name = '<STR_LIT>' ) <EOL> slug = models . SlugField ( max_length = <NUM_LIT:200> , unique = True , db_index = True , editable = True , blank = True ) <EOL> name = models . CharField ( max_length = <NUM_LIT> , db_index = True , blank = True ) <EOL> file = models . FileField ( max_length = <NUM_LIT> , upload_to = "<STR_LIT>" , <EOL> serialize = False , editable = True , blank = True ) <EOL> class Bookmark ( models . Model ) : <EOL> title = models . CharField ( max_length = <NUM_LIT> , blank = True ) <EOL> slug = models . SlugField ( max_length = <NUM_LIT:100> , unique = True , db_index = True , editable = True , blank = True ) <EOL> url = models . CharField ( max_length = <NUM_LIT:1000> , db_index = True ) <EOL> tags = models . CharField ( max_length = <NUM_LIT:1000> , db_index = True , blank = True , default = '<STR_LIT>' ) <EOL> owner = models . ForeignKey ( '<STR_LIT>' , related_name = '<STR_LIT>' , blank = True , null = True ) <EOL> created_date = models . DateTimeField ( auto_now_add = True ) <EOL> modified_date = models . DateTimeField ( auto_now_add = True ) <EOL> public = models . BooleanField ( default = True ) <EOL> def __unicode__ ( self ) : <EOL> return u"<STR_LIT>" % ( self . title ) <EOL> class Meta : <EOL> db_table = '<STR_LIT>' <EOL> def save ( self , * args , ** kwargs ) : <EOL> if not self . title : <EOL> self . title , body = get_url_data ( self . url ) <EOL> if not self . slug : <EOL> self . slug = slugify_uniquely ( self . title , self . __class__ ) <EOL> super ( Bookmark , self ) . save ( * args , ** kwargs ) <EOL> def __unicode__ ( self ) : <EOL> return self . slug <EOL> @ models . permalink <EOL> def get_absolute_url ( self ) : <EOL> return ( '<STR_LIT>' , ( ) , { '<STR_LIT>' : self . slug } ) <EOL> class Paste ( models . Model ) : <EOL> text = models . TextField ( ) <EOL> lexer = models . CharField ( max_length = <NUM_LIT:5> ) <EOL> title = models . CharField ( max_length = <NUM_LIT:100> , blank = True ) <EOL> group = models . CharField ( max_length = <NUM_LIT:100> , blank = True ) <EOL> created = models . DateTimeField ( auto_now_add = True ) <EOL> def __unicode__ ( self ) : <EOL> return u"<STR_LIT>" % ( self . title ) <EOL> class Meta : <EOL> db_table = '<STR_LIT>' </s>
