How to use the kotti.resources.Content 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 / tests.py View on Github external
def _create_contents(self, root):
        # root -> a --> aa
        #         |
        #         \ --> ab
        #         |
        #         \ --> ac --> aca
        #               |
        #               \ --> acb
        a = root['a'] = Content()
        aa = root['a']['aa'] = Content()
        ab = root['a']['ab'] = Content()
        ac = root['a']['ac'] = Content()
        aca = ac['aca'] = Content()
        acb = ac['acb'] = Content()
        return a, aa, ab, ac, aca, acb
github Kotti / Kotti / kotti / tests.py View on Github external
def _create_contents(self, root):
        # root -> a --> aa
        #         |
        #         \ --> ab
        #         |
        #         \ --> ac --> aca
        #               |
        #               \ --> acb
        a = root['a'] = Content()
        aa = root['a']['aa'] = Content()
        ab = root['a']['ab'] = Content()
        ac = root['a']['ac'] = Content()
        aca = ac['aca'] = Content()
        acb = ac['acb'] = Content()
        return a, aa, ab, ac, aca, acb
github Kotti / Kotti / kotti / tests.py View on Github external
def _create_contents(self, root):
        # root -> a --> aa
        #         |
        #         \ --> ab
        #         |
        #         \ --> ac --> aca
        #               |
        #               \ --> acb
        a = root['a'] = Content()
        aa = root['a']['aa'] = Content()
        ab = root['a']['ab'] = Content()
        ac = root['a']['ac'] = Content()
        aca = ac['aca'] = Content()
        acb = ac['acb'] = Content()
        return a, aa, ab, ac, aca, acb
github Kotti / Kotti / kotti / tests.py View on Github external
def _create_contents(self, root):
        # root -> a --> aa
        #         |
        #         \ --> ab
        #         |
        #         \ --> ac --> aca
        #               |
        #               \ --> acb
        a = root['a'] = Content()
        aa = root['a']['aa'] = Content()
        ab = root['a']['ab'] = Content()
        ac = root['a']['ac'] = Content()
        aca = ac['aca'] = Content()
        acb = ac['acb'] = Content()
        return a, aa, ab, ac, aca, acb
github Kotti / Kotti / kotti / workflow.py View on Github external
def reset_workflow(objs=None, purge_existing=False):
    if objs is None:
        objs = DBSession.query(Content)
    for obj in objs:
        if purge_existing:
            obj.state = None
        workflow = get_workflow(obj)
        if workflow is not None:
            workflow.reset(obj)
    transaction.commit()
github Kotti / Kotti / kotti / events.py View on Github external
def reset_content_owner(event):
    """Reset the owner of the content from the deleted owner.

    :param event: event that triggered this handler.
    :type event: :class:`UserDeleted`
    """

    contents = DBSession.query(Content).filter(Content.owner == event.object.name).all()
    for content in contents:
        content.owner = None
github Kotti / Kotti / kotti / resources.py View on Github external
unmodified Kotti installations).
    """

    #: Primary key column in the DB
    #: (:class:`sqlalchemy.types.Integer`)
    id = Column(ForeignKey(Content.id), primary_key=True)
    #: Body text of the Document
    #: (:class:`sqlalchemy.types.Unicode`)
    body = Column(UnicodeText())
    #: MIME type of the Document
    #: (:class:`sqlalchemy.types.String`)
    mime_type = Column(String(30))

    #: type_info is a class attribute
    #: (:class:`~kotti.resources.TypeInfo`)
    type_info = Content.type_info.copy(
        name="Document",
        title=_("Document"),
        add_view="add_document",
        addable_to=["Document"],
    )

    def __init__(
        self, body: Optional[str] = "", mime_type: Optional[str] = "text/html", **kwargs
    ):

        super(Document, self).__init__(**kwargs)

        self.body = body
        self.mime_type = mime_type

github Kotti / Kotti / kotti / views / util.py View on Github external
def default_search_content(search_term, request=None):

    # noinspection PyUnresolvedReferences
    searchstring = "%{0}%".format(search_term)

    # generic_filter can be applied to all Node (and subclassed) objects
    generic_filter = or_(
        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:
github Kotti / Kotti / kotti / resources.py View on Github external
self.mimetype = mimetype
        self.size = size
        self.data = data

    def copy(self, **kwargs) -> "File":
        """ Same as `Content.copy` with additional data support.  ``data`` needs
        some special attention, because we don't want the same depot file to be
        assigned to multiple content nodes.
        """
        _copy = super(SaveDataMixin, self).copy(**kwargs)
        _copy.data = self.data.file.read()
        return _copy


@implementer(IFile)
class File(SaveDataMixin, Content):
    """File adds some attributes to :class:`~kotti.resources.Content` that are
       useful for storing binary data.
    """

    #: Primary key column in the DB
    #: (:class:`sqlalchemy.types.Integer`)
    id = Column(ForeignKey(Content.id), primary_key=True)

    type_info = Content.type_info.copy(
        name="File",
        title=_("File"),
        add_view="add_file",
        addable_to=["Document"],
        selectable_default_views=[],
        uploadable_mimetypes=["*"],
    )