"""Comment sheet."""
from colander import deferred
from substanced.util import find_service
from adhocracy_core.interfaces import ISheet
from adhocracy_core.interfaces import ISheetReferenceAutoUpdateMarker
from adhocracy_core.interfaces import SheetToSheet
from adhocracy_core.sheets import add_sheet_to_registry
from adhocracy_core.schema import MappingSchema
from adhocracy_core.schema import Integer
from adhocracy_core.schema import PostPool
from adhocracy_core.schema import Reference
from adhocracy_core.schema import Text
from adhocracy_core.sheets import sheet_meta
# TODO add post_pool validator
comment_meta = sheet_meta._replace(isheet=IComment,
schema_class=CommentSchema)
@deferred
def deferred_default_comment_count(node: MappingSchema, kw: dict) -> str:
"""Return comment_count of the current `context` resource."""
context = kw['context']
catalogs = find_service(context, 'catalogs')
return catalogs.get_index_value(context, 'comments')
commentable_meta = sheet_meta._replace(
isheet=ICommentable,
schema_class=CommentableSchema,
editable=False,
creatable=False,
)
[docs]def includeme(config):
"""Register sheets."""
add_sheet_to_registry(comment_meta, config.registry)
add_sheet_to_registry(commentable_meta, config.registry)