org.models.extensions ===================== .. py:module:: org.models.extensions Attributes ---------- .. autoapisummary:: org.models.extensions.FILE_URL_RE Classes ------- .. autoapisummary:: org.models.extensions.SupportsExtendForm org.models.extensions.ContentExtension org.models.extensions.AccessExtension org.models.extensions.CoordinatesExtension org.models.extensions.VisibleOnHomepageExtension org.models.extensions.ContactExtension org.models.extensions.ContactHiddenOnPageExtension org.models.extensions.PeopleShownOnMainPageExtension org.models.extensions.NewsletterExtension org.models.extensions.PersonWithFunction org.models.extensions.PersonLinkExtension org.models.extensions.ResourceValidationExtension org.models.extensions.PublicationExtension org.models.extensions.PushNotificationExtension org.models.extensions.HoneyPotExtension org.models.extensions.ImageExtension org.models.extensions.GeneralFileLinkExtension org.models.extensions.SidebarLinksExtension org.models.extensions.SidebarContactLinkExtension org.models.extensions.DeletableContentExtension org.models.extensions.InlinePhotoAlbumExtension Functions --------- .. autoapisummary:: org.models.extensions.json_to_links org.models.extensions._files_observer org.models.extensions._content_file_link_observer Module Contents --------------- .. py:class:: SupportsExtendForm Bases: :py:obj:`Protocol` Base class for protocol classes. Protocol classes are defined as:: class Proto(Protocol): def meth(self) -> int: ... Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing). For example:: class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto(Protocol[T]): def meth(self) -> T: ... .. py:method:: extend_form(form_class: type[onegov.form.types.FormT], request: onegov.org.request.OrgRequest) -> type[onegov.form.types.FormT] .. py:function:: json_to_links(text: str | None = None) -> list[tuple[str | None, str | None]] .. py:class:: ContentExtension Extends classes based on :class:`onegov.core.orm.mixins.ContentMixin` with custom data that is stored in either 'meta' or 'content'. .. py:attribute:: meta :type: sqlalchemy.Column[dict[str, Any]] .. py:property:: content_extensions :type: collections.abc.Iterator[type[ContentExtension]] Returns all base classes of the current class which themselves have ``ContentExtension`` as baseclass. .. py:method:: with_content_extensions(form_class: type[onegov.form.types.FormT], request: onegov.org.request.OrgRequest, extensions: collections.abc.Iterable[type[SupportsExtendForm]] | None = None) -> type[onegov.form.types.FormT] Takes the given form and request and extends the form with all content extensions in the order in which they occur in the base class list. In other words, extends the forms with all used extension-fields. .. py:method:: extend_form(form_class: type[onegov.form.types.FormT], request: onegov.org.request.OrgRequest) -> type[onegov.form.types.FormT] :abstractmethod: Must be implemented by each ContentExtension. Takes the form class without extension and adds the required fields to it. .. py:class:: AccessExtension Bases: :py:obj:`ContentExtension` Extends any class that has a meta dictionary field with the ability to set one of the following access levels: * 'public' - The default, the model is listed and accessible. * 'private' - Neither listed nor accessible, except administrators and editors. * 'member' - Neither listed nor accessible except administrators, editors and members. * 'secret' - Not listed, but available for anyone that knows the URL. * 'mtan' - The model is listed but only accessible once an mTAN has been sent to the person and entered correctly. * 'secret_mtan' - Not listed and only accessible once an mTAN has been sent to the person and entered correctly. see :func:`onegov.core.security.rules.has_permission_not_logged_in` .. py:attribute:: access :type: onegov.core.orm.mixins.dict_property[str] .. py:method:: extend_form(form_class: type[onegov.form.types.FormT], request: onegov.org.request.OrgRequest) -> type[onegov.form.types.FormT] Must be implemented by each ContentExtension. Takes the form class without extension and adds the required fields to it. .. py:class:: CoordinatesExtension Bases: :py:obj:`ContentExtension`, :py:obj:`onegov.gis.CoordinatesMixin` Extends any class that has a data dictionary field with the ability to add coordinates to it. .. py:method:: extend_form(form_class: type[onegov.form.types.FormT], request: onegov.org.request.OrgRequest) -> type[onegov.form.types.FormT] Must be implemented by each ContentExtension. Takes the form class without extension and adds the required fields to it. .. py:class:: VisibleOnHomepageExtension Bases: :py:obj:`ContentExtension` Extends any class that has a meta dictionary field with the ability to a boolean indicating if the page should be shown on the homepage or not. .. py:attribute:: is_visible_on_homepage :type: onegov.core.orm.mixins.dict_property[bool | None] .. py:method:: extend_form(form_class: type[onegov.form.types.FormT], request: onegov.org.request.OrgRequest) -> type[onegov.form.types.FormT] Must be implemented by each ContentExtension. Takes the form class without extension and adds the required fields to it. .. py:class:: ContactExtension Bases: :py:obj:`ContentExtension` Extends any class that has a content dictionary field with a simple contacts field, that can optionally be inherited from another topic. .. py:attribute:: contact :type: onegov.core.orm.mixins.dict_property[str | None] .. py:attribute:: inherit_contact :type: onegov.core.orm.mixins.dict_property[bool] .. py:attribute:: contact_inherited_from :type: onegov.core.orm.mixins.dict_property[int | None] .. py:property:: contact_html :type: markupsafe.Markup | None .. py:method:: extend_form(form_class: type[onegov.form.types.FormT], request: onegov.org.request.OrgRequest) -> type[onegov.form.types.FormT] Must be implemented by each ContentExtension. Takes the form class without extension and adds the required fields to it. .. py:class:: ContactHiddenOnPageExtension Bases: :py:obj:`ContentExtension` Extends any class that has a content dictionary field with a simple contacts field. .. py:attribute:: hide_contact :type: onegov.core.orm.mixins.dict_property[bool] .. py:method:: extend_form(form_class: type[onegov.form.types.FormT], request: onegov.org.request.OrgRequest) -> type[onegov.form.types.FormT] Must be implemented by each ContentExtension. Takes the form class without extension and adds the required fields to it. .. py:class:: PeopleShownOnMainPageExtension Bases: :py:obj:`ContentExtension` Extends any class that has a content dictionary field with a simple contacts field where people will be shown on bottom of main page. Note: Feature limited to org and town6 .. py:attribute:: show_people_on_main_page :type: onegov.core.orm.mixins.dict_property[bool] .. py:method:: extend_form(form_class: type[onegov.form.types.FormT], request: onegov.org.request.OrgRequest) -> type[onegov.form.types.FormT] Must be implemented by each ContentExtension. Takes the form class without extension and adds the required fields to it. .. py:class:: NewsletterExtension Bases: :py:obj:`ContentExtension` Extends classes based on :class:`onegov.core.orm.mixins.ContentMixin` with custom data that is stored in either 'meta' or 'content'. .. py:attribute:: text_in_newsletter :type: onegov.core.orm.mixins.dict_property[bool] .. py:method:: extend_form(form_class: type[onegov.form.types.FormT], request: onegov.org.request.OrgRequest) -> type[onegov.form.types.FormT] Must be implemented by each ContentExtension. Takes the form class without extension and adds the required fields to it. .. py:class:: PersonWithFunction Bases: :py:obj:`onegov.people.Person` A person. .. py:attribute:: person :type: str .. py:attribute:: context_specific_function :type: str .. py:attribute:: display_function_in_person_directory :type: bool .. py:class:: PersonLinkExtension Bases: :py:obj:`ContentExtension` Extends any class that has a content dictionary field with the ability to reference people from :class:`onegov.people.PersonCollection`. .. py:attribute:: western_name_order :type: onegov.core.orm.mixins.dict_property[bool] .. py:property:: people :type: list[PersonWithFunction] | None Returns the people linked to this content or None. The context specific function is temporarily stored on the ``context_specific_function`` attribute on each object in the resulting list. Similarly, to indicate if we want to show a particular function in the page of a person, ``display_function_in_person_directory`` is temporarily stored on each object of the resulting list. .. py:method:: get_selectable_people(request: onegov.org.request.OrgRequest) -> list[onegov.people.Person] Returns a list of people which may be linked. .. py:method:: get_person_function_by_id(id: str) -> tuple[str, bool] .. py:method:: move_person(subject: str, target: str, direction: onegov.core.orm.abstract.MoveDirection) -> None Moves the subject below or above the target. :subject: The key of the person to be moved. :target: The key of the person above or below which the subject is moved. :direction: The direction relative to the target. .. py:method:: extend_form(form_class: type[onegov.form.types.FormT], request: onegov.org.request.OrgRequest) -> type[onegov.form.types.FormT] Must be implemented by each ContentExtension. Takes the form class without extension and adds the required fields to it. .. py:class:: ResourceValidationExtension Bases: :py:obj:`ContentExtension` Extends classes based on :class:`onegov.core.orm.mixins.ContentMixin` with custom data that is stored in either 'meta' or 'content'. .. py:method:: extend_form(form_class: type[onegov.form.types.FormT], request: onegov.org.request.OrgRequest) -> type[onegov.form.types.FormT] Must be implemented by each ContentExtension. Takes the form class without extension and adds the required fields to it. .. py:class:: PublicationExtension Bases: :py:obj:`ContentExtension` Extends classes based on :class:`onegov.core.orm.mixins.ContentMixin` with custom data that is stored in either 'meta' or 'content'. .. py:method:: extend_form(form_class: type[onegov.form.types.FormT], request: onegov.org.request.OrgRequest) -> type[onegov.form.types.FormT] Must be implemented by each ContentExtension. Takes the form class without extension and adds the required fields to it. .. py:class:: PushNotificationExtension Bases: :py:obj:`ContentExtension` Extends classes based on :class:`onegov.core.orm.mixins.ContentMixin` with custom data that is stored in either 'meta' or 'content'. .. py:method:: extend_form(form_class: type[onegov.form.types.FormT], request: onegov.org.request.OrgRequest) -> type[onegov.form.types.FormT] Must be implemented by each ContentExtension. Takes the form class without extension and adds the required fields to it. .. py:class:: HoneyPotExtension Bases: :py:obj:`ContentExtension` Extends classes based on :class:`onegov.core.orm.mixins.ContentMixin` with custom data that is stored in either 'meta' or 'content'. .. py:attribute:: honeypot .. py:method:: extend_form(form_class: type[onegov.form.types.FormT], request: onegov.org.request.OrgRequest) -> type[onegov.form.types.FormT] Must be implemented by each ContentExtension. Takes the form class without extension and adds the required fields to it. .. py:class:: ImageExtension Bases: :py:obj:`ContentExtension` Extends classes based on :class:`onegov.core.orm.mixins.ContentMixin` with custom data that is stored in either 'meta' or 'content'. .. py:attribute:: page_image .. py:attribute:: show_preview_image .. py:attribute:: show_page_image .. py:method:: extend_form(form_class: type[onegov.form.types.FormT], request: onegov.org.request.OrgRequest) -> type[onegov.form.types.FormT] Must be implemented by each ContentExtension. Takes the form class without extension and adds the required fields to it. .. py:data:: FILE_URL_RE .. py:function:: _files_observer(self: GeneralFileLinkExtension, files: list[onegov.file.File], meta: set[str], publication_start: datetime.datetime | None = None, publication_end: datetime.datetime | None = None) -> None .. py:function:: _content_file_link_observer(self: GeneralFileLinkExtension, content: set[str]) -> None .. py:class:: GeneralFileLinkExtension Bases: :py:obj:`ContentExtension` Extends any class that has a files relationship to reference files from :class:`onegov.org.models.file.GeneralFileCollection`. Additionally any files linked within the object's content will be added to the explicit list of linked files and access is propagated from the owner of the link to the file. .. py:attribute:: content_fields_containing_links_to_files :type: ClassVar[set[str]] .. py:attribute:: show_file_links_in_sidebar :type: onegov.core.orm.mixins.dict_property[bool] .. py:attribute:: id :type: Any .. py:method:: extend_form(form_class: type[onegov.form.types.FormT], request: onegov.org.request.OrgRequest) -> type[onegov.form.types.FormT] Must be implemented by each ContentExtension. Takes the form class without extension and adds the required fields to it. .. py:class:: SidebarLinksExtension Bases: :py:obj:`ContentExtension` Extends classes based on :class:`onegov.core.orm.mixins.ContentMixin` with custom data that is stored in either 'meta' or 'content'. .. py:attribute:: sidepanel_links .. py:method:: extend_form(form_class: type[onegov.form.types.FormT], request: onegov.org.request.OrgRequest) -> type[onegov.form.types.FormT] Must be implemented by each ContentExtension. Takes the form class without extension and adds the required fields to it. .. py:class:: SidebarContactLinkExtension Bases: :py:obj:`ContentExtension` Like SidebarLinkExtension but the links are shown below the contact field. We knowingly duplicate some code here . .. py:attribute:: sidepanel_contact .. py:method:: extend_form(form_class: type[onegov.form.types.FormT], request: onegov.org.request.OrgRequest) -> type[onegov.form.types.FormT] Must be implemented by each ContentExtension. Takes the form class without extension and adds the required fields to it. .. py:class:: DeletableContentExtension Bases: :py:obj:`ContentExtension` Extends any class that has a meta dictionary field with the ability to mark the content as deletable after reaching the end date. A cronjob will periodically check for 'deletable' content with expired end date and delete it e.g. Directories. .. py:attribute:: delete_when_expired :type: onegov.core.orm.mixins.dict_property[bool] .. py:method:: extend_form(form_class: type[onegov.form.types.FormT], request: onegov.org.request.OrgRequest) -> type[onegov.form.types.FormT] Must be implemented by each ContentExtension. Takes the form class without extension and adds the required fields to it. .. py:class:: InlinePhotoAlbumExtension Bases: :py:obj:`ContentExtension` Adds ability to reference photo albums (ImageSets) and show them inline at the end of the content of the page. .. py:attribute:: photo_album_id :type: onegov.core.orm.mixins.dict_property[str | None] .. py:property:: photo_album :type: onegov.org.models.ImageSet | None .. py:method:: extend_form(form_class: type[onegov.form.types.FormT], request: onegov.org.request.OrgRequest) -> type[onegov.form.types.FormT] Must be implemented by each ContentExtension. Takes the form class without extension and adds the required fields to it.