Created
August 30, 2015 22:12
-
-
Save tseaver/4857cac66e274c9b3117 to your computer and use it in GitHub Desktop.
SubstanceD: demonstrate bug in 'config.add_propertysheet'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import colander | |
from substanced.content import content | |
from substanced.file import File as BaseFile | |
from substanced.file import FilePropertiesSchema | |
from substanced.property import PropertySheet | |
from substanced.schema import NameSchemaNode | |
class EditingType(object): | |
def __init__(self, typename): | |
self._typename = typename | |
def __call__(self, context, request): | |
return request.registry.content.istype(context, self._typename) | |
class BillSchema(FilePropertiesSchema): | |
name = NameSchemaNode( | |
editing=EditingType('Bill'), | |
) | |
posted_date = colander.SchemaNode( | |
colander.Date(), | |
missing=None, | |
default=None, | |
) | |
due_date = colander.SchemaNode( | |
colander.Date(), | |
missing=None, | |
default=None, | |
) | |
paid_date = colander.SchemaNode( | |
colander.Date(), | |
missing=None, | |
default=None, | |
) | |
class BillPropertySheet(PropertySheet): | |
schema = BillSchema() | |
@content( | |
'Bill', | |
icon='glyphicon glyphicon-file', | |
add_view='add_bill', | |
) | |
class Bill(BaseFile): | |
pass | |
class ContractSchema(FilePropertiesSchema): | |
name = NameSchemaNode( | |
editing=EditingType('Contract'), | |
) | |
status = colander.SchemaNode( | |
colander.String(), | |
default='DRAFT', | |
widget=deform.widget.RadioChoiceWidget( | |
values=( | |
('DRAFT', 'Draft'), | |
('SIGNED', 'Final'), | |
('EXPIRED', 'Expired'), | |
) | |
) | |
) | |
signed_date = colander.SchemaNode( | |
colander.Date(), | |
missing=None, | |
default=None, | |
) | |
class ContractPropertySheet(PropertySheet): | |
schema = ContractSchema() | |
@content( | |
'Contract', | |
icon='glyphicon glyphicon-file', | |
add_view='add_contract', | |
) | |
class Contract(BaseFile): | |
pass | |
class InvoiceSchema(FilePropertiesSchema): | |
name = NameSchemaNode( | |
editing=EditingType('Invoice'), | |
) | |
posted_date = colander.SchemaNode( | |
colander.Date(), | |
missing=None, | |
default=None, | |
) | |
paid_date = colander.SchemaNode( | |
colander.Date(), | |
missing=None, | |
default=None, | |
) | |
class InvoicePropertySheet(PropertySheet): | |
schema = InvoiceSchema() | |
@content( | |
'Invoice', | |
icon='glyphicon glyphicon-file', | |
add_view='add_invoice', | |
) | |
class Invoice(BaseFile): | |
pass | |
def includeme(config): # pragma: no cover | |
config.add_propertysheet('Basic', BillPropertySheet, Bill) | |
config.add_propertysheet('Basic', ContractPropertySheet, Contract) | |
config.add_propertysheet('Basic', InvoicePropertySheet, Invoice) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment