<s> import colander <EOL> import datetime <EOL> import time <EOL> import deform . widget <EOL> from persistent import Persistent <EOL> from pyramid . security import ( <EOL> Allow , <EOL> Everyone , <EOL> ) <EOL> from substanced . content import content <EOL> from substanced . folder import Folder <EOL> from substanced . property import PropertySheet <EOL> from substanced . root import Root <EOL> from substanced . schema import ( <EOL> Schema , <EOL> NameSchemaNode , <EOL> ) <EOL> from substanced . util import renamer <EOL> @ colander . deferred <EOL> def now_default ( node , kw ) : <EOL> return datetime . datetime . now ( ) <EOL> class BlogEntrySchema ( Schema ) : <EOL> name = NameSchemaNode ( <EOL> editing = lambda c , r : r . registry . content . istype ( c , '<STR_LIT>' ) <EOL> ) <EOL> title = colander . SchemaNode ( <EOL> colander . String ( ) , <EOL> ) <EOL> entry = colander . SchemaNode ( <EOL> colander . String ( ) , <EOL> widget = deform . widget . TextAreaWidget ( rows = <NUM_LIT:20> , cols = <NUM_LIT> ) , <EOL> ) <EOL> format = colander . SchemaNode ( <EOL> colander . String ( ) , <EOL> validator = colander . OneOf ( [ '<STR_LIT>' , '<STR_LIT:html>' ] ) , <EOL> widget = deform . widget . SelectWidget ( <EOL> values = [ ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT:html>' , '<STR_LIT:html>' ) ] ) , <EOL> ) <EOL> pubdate = colander . SchemaNode ( <EOL> colander . DateTime ( default_tzinfo = None ) , <EOL> default = now_default , <EOL> ) <EOL> class BlogEntryPropertySheet ( PropertySheet ) : <EOL> schema = BlogEntrySchema ( ) <EOL> @ content ( <EOL> '<STR_LIT>' , <EOL> icon = '<STR_LIT>' , <EOL> add_view = '<STR_LIT>' , <EOL> propertysheets = ( <EOL> ( '<STR_LIT>' , BlogEntryPropertySheet ) , <EOL> ) , <EOL> catalog = True , <EOL> tab_order = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) <EOL> class BlogEntry ( Folder ) : <EOL> name = renamer ( ) <EOL> def __init__ ( self , title , entry , format , pubdate ) : <EOL> Folder . __init__ ( self ) <EOL> self . title = title <EOL> self . entry = entry <EOL> self . format = format <EOL> self . pubdate = pubdate <EOL> self [ '<STR_LIT>' ] = Attachments ( ) <EOL> self [ '<STR_LIT>' ] = Comments ( ) <EOL> def __sdi_addable__ ( self , context , introspectable ) : <EOL> return False <EOL> def add_comment ( self , comment ) : <EOL> while <NUM_LIT:1> : <EOL> name = str ( time . time ( ) ) <EOL> if not name in self : <EOL> self [ '<STR_LIT>' ] [ name ] = comment <EOL> break <EOL> class CommentSchema ( Schema ) : <EOL> commenter = colander . SchemaNode ( <EOL> colander . String ( ) , <EOL> ) <EOL> text = colander . SchemaNode ( <EOL> colander . String ( ) , <EOL> ) <EOL> pubdate = colander . SchemaNode ( <EOL> colander . DateTime ( ) , <EOL> default = now_default , <EOL> ) <EOL> class CommentPropertySheet ( PropertySheet ) : <EOL> schema = CommentSchema ( ) <EOL> @ content ( <EOL> '<STR_LIT>' , <EOL> icon = '<STR_LIT>' , <EOL> add_view = '<STR_LIT>' , <EOL> propertysheets = ( <EOL> ( '<STR_LIT>' , CommentPropertySheet ) , <EOL> ) , <EOL> catalog = True , <EOL> ) <EOL> class Comment ( Persistent ) : <EOL> def __init__ ( self , commenter_name , text , pubdate ) : <EOL> self . commenter_name = commenter_name <EOL> self . text = text <EOL> self . pubdate = pubdate <EOL> def comments_columns ( folder , subobject , request , default_columnspec ) : <EOL> pubdate = getattr ( subobject , '<STR_LIT>' , None ) <EOL> if pubdate is not None : <EOL> pubdate = pubdate . isoformat ( ) <EOL> return default_columnspec + [ <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : pubdate , <EOL> '<STR_LIT>' : '<STR_LIT:date>' , <EOL> } , <EOL> ] <EOL> @ content ( <EOL> '<STR_LIT>' , <EOL> icon = '<STR_LIT>' , <EOL> columns = comments_columns , <EOL> ) <EOL> class Comments ( Folder ) : <EOL> """<STR_LIT>""" <EOL> def __sdi_addable__ ( self , context , introspectable ) : <EOL> return introspectable . get ( '<STR_LIT>' ) == '<STR_LIT>' <EOL> def attachments_columns ( folder , subobject , request , default_columnspec ) : <EOL> kb_size = None <EOL> if getattr ( subobject , '<STR_LIT>' , None ) and callable ( subobject . get_size ) : <EOL> kb_size = int ( int ( subobject . get_size ( ) ) / <NUM_LIT:1000> ) <EOL> return default_columnspec + [ <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : "<STR_LIT>" % kb_size , <EOL> } , <EOL> ] <EOL> @ content ( <EOL> '<STR_LIT>' , <EOL> icon = '<STR_LIT>' , <EOL> columns = attachments_columns , <EOL> ) <EOL> class Attachments ( Folder ) : <EOL> """<STR_LIT>""" <EOL> def __sdi_addable__ ( self , context , introspectable ) : <EOL> return introspectable . get ( '<STR_LIT>' ) == '<STR_LIT>' <EOL> class BlogSchema ( Schema ) : <EOL> """<STR_LIT>""" <EOL> title = colander . SchemaNode ( <EOL> colander . String ( ) , <EOL> missing = '<STR_LIT>' <EOL> ) <EOL> description = colander . SchemaNode ( <EOL> colander . String ( ) , <EOL> missing = '<STR_LIT>' <EOL> ) <EOL> class BlogPropertySheet ( PropertySheet ) : <EOL> schema = BlogSchema ( ) <EOL> def blog_columns ( folder , subobject , request , default_columnspec ) : <EOL> title = getattr ( subobject , '<STR_LIT:title>' , None ) <EOL> pubdate = getattr ( subobject , '<STR_LIT>' , None ) <EOL> if pubdate is not None : <EOL> pubdate = pubdate . isoformat ( ) <EOL> return default_columnspec + [ <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : title , <EOL> } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : pubdate , <EOL> '<STR_LIT>' : '<STR_LIT:date>' , <EOL> } , <EOL> ] <EOL> @ content ( <EOL> '<STR_LIT>' , <EOL> icon = '<STR_LIT>' , <EOL> propertysheets = ( <EOL> ( '<STR_LIT>' , BlogPropertySheet ) , <EOL> ) , <EOL> after_create = ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> columns = blog_columns , <EOL> ) <EOL> class Blog ( Root ) : <EOL> title = '<STR_LIT>' <EOL> description = '<STR_LIT>' <EOL> def __sdi_addable__ ( self , context , introspectable ) : <EOL> return introspectable . get ( '<STR_LIT>' ) == '<STR_LIT>' <EOL> @ property <EOL> def sdi_title ( self ) : <EOL> return self . title <EOL> @ sdi_title . setter <EOL> def sdi_title ( self , value ) : <EOL> self . title = value <EOL> def after_create_blog ( self , inst , registry ) : <EOL> acl = getattr ( self , '<STR_LIT>' , [ ] ) <EOL> acl . append ( ( Allow , Everyone , '<STR_LIT>' ) ) <EOL> self . __acl__ = acl </s>
