Source code for adhocracy_core.sheets.document

"""Sheets to store a document."""
from adhocracy_core.interfaces import ISheet
from adhocracy_core.interfaces import ISheetReferenceAutoUpdateMarker
from adhocracy_core.interfaces import SheetToSheet
from adhocracy_core.sheets import sheet_meta
from adhocracy_core.sheets import add_sheet_to_registry
from adhocracy_core.sheets.subresources import ISubResources
from adhocracy_core.schema import MappingSchema
from adhocracy_core.schema import UniqueReferences
from adhocracy_core.schema import Text


[docs]class IDocument(ISubResources): """Marker interface for the document sheet."""
[docs]class ISection(ISheet, ISheetReferenceAutoUpdateMarker): """Marker interface for the section sheet."""
[docs]class IParagraph(ISection): """Marker interface for the paragraph sheet."""
[docs]class DocumentElementsReference(SheetToSheet): """Document elements reference.""" source_isheet = IDocument source_isheet_field = 'elements' target_isheet = ISection
[docs]class DocumentSchema(MappingSchema): """Document sheet data structure. `elements`: structural subelements like sections """ elements = UniqueReferences(reftype=DocumentElementsReference)
document_meta = sheet_meta._replace(isheet=IDocument, schema_class=DocumentSchema, )
[docs]class ParagraphSchema(MappingSchema): """Paragraph Section sheet data structure. `content`: Text `documents`: Documents referencing this paragraph """ text = Text() documents = UniqueReferences(reftype=DocumentElementsReference, readonly=True, backref=True)
paragraph_meta = sheet_meta._replace(isheet=IParagraph, schema_class=ParagraphSchema)
[docs]def includeme(config): """Register sheets.""" add_sheet_to_registry(document_meta, config.registry) add_sheet_to_registry(paragraph_meta, config.registry)