How to use the kotti.resources.Document function in Kotti

To help you get started, we’ve selected a few Kotti examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Kotti / Kotti / kotti / testing.py View on Github external
def _populator():
    from kotti import DBSession
    from kotti.resources import Document
    from kotti.populate import populate

    populate()
    for doc in DBSession.query(Document)[1:]:
        DBSession.delete(doc)
    transaction.commit()
github Kotti / Kotti / kotti / tests.py View on Github external
def _populator():
    from kotti.populate import populate
    populate()
    for doc in DBSession.query(Document)[1:]:
        DBSession.delete(doc)
    transaction.commit()
github Kotti / Kotti / kotti / tests.py View on Github external
def test_multiple_parents_and_types(self):
        from kotti.views.util import addable_types
        # A scenario where we can add multiple types to multiple folders:
        root = get_root()
        request = DummyRequest()

        with contents_addable():
            # We should be able to add both to the child and to the parent:
            child = root['child'] = Document(title=u"Child")
            possible_parents, possible_types = addable_types(child, request)
            child_parent, root_parent = possible_parents
            self.assertEqual(child_parent['node'], child)
            self.assertEqual(root_parent['node'], root)
            self.assertEqual(child_parent['factories'], [Document, Content])
            self.assertEqual(root_parent['factories'], [Document, Content])

            document_info, node_info = possible_types
            self.assertEqual(document_info['factory'], Document)
            self.assertEqual(node_info['factory'], Content)
            self.assertEqual(document_info['nodes'], [child, root])
            self.assertEqual(node_info['nodes'], [child, root])
github Kotti / Kotti / kotti / tests.py View on Github external
def test_order_of_addable_parents(self):
        from kotti.views.edit import add_node
        # The 'add_node' view sorts the 'possible_parents' returned by
        # 'addable_types' so that the parent comes first if the
        # context we're looking at does not have any children yet.
        root = get_root()
        request = DummyRequest()

        with contents_addable():
            # The child Document does not contain any other Nodes, so it's
            # second in the 'possible_parents' list returned by 'node_add':
            child = root['child'] = Document(title=u"Child")
            info = add_node(child, request)
            first_parent, second_parent = info['possible_parents']
            self.assertEqual(first_parent['node'], root)
            self.assertEqual(second_parent['node'], child)

            # Now we add a grandchild and see that this behaviour changes:
            child['grandchild'] = Document(title=u"Grandchild")
            info = add_node(child, request)
            first_parent, second_parent = info['possible_parents']
            self.assertEqual(first_parent['node'], child)
            self.assertEqual(second_parent['node'], root)
github Kotti / Kotti / kotti / tests.py View on Github external
def test_multiple_parents_and_types(self):
        from kotti.views.util import addable_types
        # A scenario where we can add multiple types to multiple folders:
        root = get_root()
        request = DummyRequest()

        with contents_addable():
            # We should be able to add both to the child and to the parent:
            child = root['child'] = Document(title=u"Child")
            possible_parents, possible_types = addable_types(child, request)
            child_parent, root_parent = possible_parents
            self.assertEqual(child_parent['node'], child)
            self.assertEqual(root_parent['node'], root)
            self.assertEqual(child_parent['factories'], [Document, Content])
            self.assertEqual(root_parent['factories'], [Document, Content])

            document_info, node_info = possible_types
            self.assertEqual(document_info['factory'], Document)
            self.assertEqual(node_info['factory'], Content)
            self.assertEqual(document_info['nodes'], [child, root])
            self.assertEqual(node_info['nodes'], [child, root])
github Kotti / Kotti / kotti / tests.py View on Github external
# 'addable_types' so that the parent comes first if the
        # context we're looking at does not have any children yet.
        root = get_root()
        request = DummyRequest()

        with contents_addable():
            # The child Document does not contain any other Nodes, so it's
            # second in the 'possible_parents' list returned by 'node_add':
            child = root['child'] = Document(title=u"Child")
            info = add_node(child, request)
            first_parent, second_parent = info['possible_parents']
            self.assertEqual(first_parent['node'], root)
            self.assertEqual(second_parent['node'], child)

            # Now we add a grandchild and see that this behaviour changes:
            child['grandchild'] = Document(title=u"Grandchild")
            info = add_node(child, request)
            first_parent, second_parent = info['possible_parents']
            self.assertEqual(first_parent['node'], child)
            self.assertEqual(second_parent['node'], root)
github Kotti / Kotti / kotti / views / util.py View on Github external
Content.title.like(searchstring),
        Content.description.like(searchstring),
    )

    results = (
        DBSession.query(Content)
        .filter(generic_filter)
        .order_by(Content.title.asc())
        .all()
    )

    # specific result contain objects matching additional criteria
    # but must not match the generic criteria (because these objects
    # are already in the generic_results)
    document_results = DBSession.query(Document).filter(
        and_(Document.body.like(searchstring), not_(generic_filter))
    )

    for results_set in [content_with_tags([searchstring]), document_results.all()]:
        [results.append(c) for c in results_set if c not in results]

    result_dicts = []

    for result in results:
        if request.has_permission("view", result):
            result_dicts.append(
                dict(
                    name=result.name,
                    title=result.title,
                    description=result.description,
                    path=request.resource_path(result),
                )
github Kotti / Kotti / kotti / views / edit / content.py View on Github external
class DocumentSchema(ContentSchema):
    body = colander.SchemaNode(
        colander.String(),
        title=_("Body"),
        widget=RichTextWidget(
            # theme='advanced', width=790, height=500
            height=500
        ),
        missing="",
    )


class DocumentAddForm(AddFormView):
    schema_factory = DocumentSchema
    add = Document
    item_type = _("Document")


class DocumentEditForm(EditFormView):
    schema_factory = DocumentSchema


# noinspection PyPep8Naming
def FileSchema(tmpstore, title_missing=None):
    class FileSchema(ContentSchema):
        file = SchemaNode(
            FileData(),
            title=_("File"),
            widget=FileUploadWidget(tmpstore),
            validator=validate_file_size_limit,
        )
github Kotti / Kotti / kotti / alembic / versions / 57fecf5dbd62_initialize_workflow.py View on Github external
def upgrade():
    from kotti import DBSession
    from kotti import get_settings
    from kotti.resources import Document
    from kotti.workflow import get_workflow
    from kotti.workflow import reset_workflow

    is_default = get_settings()['kotti.use_workflow'] == 'kotti:workflow.zcml'
    if not is_default:
        return

    reset_workflow()
    for obj in DBSession.query(Document):
        workflow = get_workflow(obj)
        workflow.transition_to_state(obj, None, 'public')
github Kotti / Kotti / kotti / views / util.py View on Github external
Content.name.like(searchstring),
        Content.title.like(searchstring),
        Content.description.like(searchstring),
    )

    results = (
        DBSession.query(Content)
        .filter(generic_filter)
        .order_by(Content.title.asc())
        .all()
    )

    # specific result contain objects matching additional criteria
    # but must not match the generic criteria (because these objects
    # are already in the generic_results)
    document_results = DBSession.query(Document).filter(
        and_(Document.body.like(searchstring), not_(generic_filter))
    )

    for results_set in [content_with_tags([searchstring]), document_results.all()]:
        [results.append(c) for c in results_set if c not in results]

    result_dicts = []

    for result in results:
        if request.has_permission("view", result):
            result_dicts.append(
                dict(
                    name=result.name,
                    title=result.title,
                    description=result.description,
                    path=request.resource_path(result),