<s> from iblogengine import IBlog <EOL> from zope . interface import implements <EOL> from axiom import item , store , attributes , sequence <EOL> from epsilon . extime import Time <EOL> class Post ( item . Item ) : <EOL> typeName = "<STR_LIT>" <EOL> schemaVersion = <NUM_LIT:1> <EOL> id = attributes . integer ( indexed = True , allowNone = False ) <EOL> created = attributes . timestamp ( indexed = True ) <EOL> modified = attributes . timestamp ( indexed = True ) <EOL> title = attributes . text ( indexed = True , allowNone = False ) <EOL> author = attributes . text ( indexed = True , allowNone = False ) <EOL> category = attributes . text ( indexed = True ) <EOL> content = attributes . text ( indexed = True ) <EOL> def __init__ ( self , ** kw ) : <EOL> now = Time ( ) <EOL> kw . update ( { '<STR_LIT>' : now , <EOL> '<STR_LIT>' : now } ) <EOL> super ( Post , self ) . __init__ ( ** kw ) <EOL> def setModified ( self ) : <EOL> self . modified = Time ( ) <EOL> class Blog ( item . Item , item . InstallableMixin ) : <EOL> implements ( IBlog ) <EOL> typeName = "<STR_LIT>" <EOL> schemaVersion = <NUM_LIT:1> <EOL> posts = attributes . reference ( ) <EOL> next_id = attributes . integer ( default = <NUM_LIT:0> ) <EOL> def __init__ ( self , ** kw ) : <EOL> super ( Blog , self ) . __init__ ( ** kw ) <EOL> self . posts = sequence . List ( store = self . store ) <EOL> post = Post ( store = self . store , <EOL> id = self . getNextId ( ) , <EOL> author = u'<STR_LIT>' , <EOL> title = u'<STR_LIT>' , <EOL> category = u'<STR_LIT>' , <EOL> content = u'<STR_LIT>' ) <EOL> self . addNewPost ( post ) <EOL> def installOn ( self , other ) : <EOL> super ( Blog , self ) . installOn ( other ) <EOL> other . powerUp ( self , IBlog ) <EOL> def addNewPost ( self , post ) : <EOL> assert post . id == self . next_id , "<STR_LIT>" % ( post . id , self . next_id ) <EOL> self . posts . append ( post ) <EOL> self . next_id += <NUM_LIT:1> <EOL> def getPosts ( self , how_many = None ) : <EOL> """<STR_LIT>""" <EOL> if how_many is None or how_many > self . next_id : <EOL> how_many = self . next_id <EOL> return ( self . getOne ( self . next_id - id - <NUM_LIT:1> ) for id in range ( how_many ) ) <EOL> def getOne ( self , id ) : <EOL> return self . posts [ id ] <EOL> def getNextId ( self ) : <EOL> return self . next_id <EOL> def initialize ( storename ) : <EOL> s = store . Store ( storename ) <EOL> s . findOrCreate ( Blog ) . installOn ( s ) <EOL> return s </s>
