Source code for org.models.traitinfo

from onegov.org import _
from onegov.org.elements import DeleteLink, Link, LinkGroup, IFrameLink
from onegov.org.models import Organisation
from onegov.org.models.clipboard import Clipboard
from onegov.org.models.editor import Editor


from typing import Any, TYPE_CHECKING
if TYPE_CHECKING:
    from collections.abc import Iterator, Sequence
    from onegov.core.elements import Link as BaseLink
    from onegov.form import Form
    from onegov.org.request import OrgRequest
    from sqlalchemy import Column


#: Contains the messages that differ for each trait (the handling of all traits
#: is the same). New traits need to adapt the same messages as the others.
[docs] TRAIT_MESSAGES: dict[str, dict[str, str]] = { 'link': { 'name': _('Link'), 'new_page_title': _('New Link'), 'new_page_added': _('Added a new link'), 'edit_page_title': _('Edit Link'), 'move_page_title': _('Move Link'), 'delete_message': _('The link was deleted'), 'delete_button': _('Delete link'), 'delete_question': _( 'Do you really want to delete the link "${title}"?'), }, 'page': { 'name': _('Topic'), 'new_page_title': _('New Topic'), 'new_page_added': _('Added a new topic'), 'edit_page_title': _('Edit Topic'), 'move_page_title': _('Move Topic'), 'delete_message': _('The topic was deleted'), 'delete_button': _('Delete topic'), 'delete_question': _( 'Do you really want to delete the topic "${title}"?'), }, 'news': { 'name': _('News'), 'new_page_title': _('Add News'), 'new_page_added': _('Added news'), 'edit_page_title': _('Edit News'), 'delete_message': _('The news was deleted'), 'delete_button': _('Delete news'), 'delete_question': _( 'Do you really want to delete the news "${title}"?'), }, 'iframe': { 'name': _('iFrame'), 'new_page_title': _('Add iFrame'), 'new_page_added': _('Added iFrame'), 'edit_page_title': _('Edit iFrame'), 'delete_message': _('The iFrame was deleted'), 'delete_button': _('Delete iFrame'), 'delete_question': _( 'Do you really want to delete the iFrame "${title}"?'), } }
[docs] class TraitInfo: """" Typically used as a mixin for adjacency list based models, this class provides access to the trait related methods. Traits are like subtypes of models. For example, the Page model has a page trait and a link trait. Both are managed under the same tree as the same type (Page), but one is rendered as a redirect, the other as a normal page. """ if TYPE_CHECKING: # forward declare Page attributes we rely on
[docs] title: Column[str]
meta: Column[dict[str, Any]] @property def editable(self) -> bool: ... @property def deletable(self) -> bool: ... @property def url_changeable(self) -> bool: ... @property
[docs] def trait(self) -> str | None: """ Gets the trait of the page. """ return self.meta.get('trait')
@trait.setter def trait(self, trait: str | None) -> None: """ Sets the trait of the page. """ self.meta['trait'] = trait @property
[docs] def trait_messages(self) -> dict[str, dict[str, str]]: """ Returns all trait_messages. """ return TRAIT_MESSAGES
@property
[docs] def allowed_subtraits(self) -> 'Sequence[str]': """ Returns a list of traits that this page may contain. """ raise NotImplementedError
@property
[docs] def paste_target(self) -> 'TraitInfo': """ Returns the page that should be used as parent for the content pasting if paste is called on the current page (self). This is usually just self. If the paste action should put the content alongside the current page, it would be the parent. """ raise NotImplementedError
[docs] def is_supported_trait(self, trait: str) -> bool: """ Returns true if the given trait is supported by this type This doesn't mean that the trait may be added to this page, it serves as a simple sanity check, returning True if the combination of the type and the trait make any sense at all. """ raise NotImplementedError
[docs] def get_form_class( self, trait: str, action: str, request: 'OrgRequest' ) -> type['Form']: """ Returns the form class for the given trait, action. """ raise NotImplementedError