Beispiel #1
0
    def page_menu(self, breadcrumb: Breadcrumb) -> PageMenu:
        new = self._folder.name() is None
        is_enabled = new or not watolib.Folder.current().locked()

        # When backfolder is set, we have the special situation that we want to redirect the user
        # two breadcrumb layers up. This is a very specific case, so we realize this locally instead
        # of using a generic approach. Just like it done locally by the action method.
        if html.request.has_var("backfolder"):
            breadcrumb = make_folder_breadcrumb(
                watolib.Folder.folder(html.request.var("backfolder")))
            breadcrumb.append(self._breadcrumb_item())

        return make_simple_form_page_menu(breadcrumb,
                                          form_name="edit_host",
                                          button_name="save",
                                          save_is_enabled=is_enabled)
Beispiel #2
0
def test_breadcrumb_creation():
    i1 = BreadcrumbItem("Title1", "index.py")

    b = Breadcrumb([i1])
    assert len(b) == 1
    assert b[0].title == "Title1"

    b.append(BreadcrumbItem("Title2", "index.py"))
    assert len(b) == 2
    assert b[1].title == "Title2"

    b += [  # type: ignore[misc]
        BreadcrumbItem("Title3", "index.py"),
        BreadcrumbItem("Title4", "index.py"),
    ]
    assert isinstance(b, Breadcrumb)
    assert len(b) == 4
    assert b[2].title == "Title3"
    assert b[3].title == "Title4"
Beispiel #3
0
        if parent_cls := self.parent_mode():
            # For some reason pylint does not understand that this is a class type
            breadcrumb = parent_cls().breadcrumb()  # pylint: disable=not-callable
        else:
            breadcrumb = Breadcrumb()

        # For the currently active mode use the same link as the "page title click"
        if html.request.get_ascii_input("mode") == self.name():
            breadcrumb_url = "javascript:window.location.reload(false)"
        else:
            breadcrumb_url = self._breadcrumb_url()

        breadcrumb.append(
            BreadcrumbItem(
                title=self.title(),
                url=breadcrumb_url,
            ))

        return breadcrumb

    def _breadcrumb_url(self) -> str:
        """Override this method to implement a custom breadcrumb URL

        This can be useful when a mode needs some more contextual information
        to link to the correct page.
        """
        return html.makeuri_contextless([("mode", self.name())],
                                        filename="wato.py")

    def buttons(self) -> None:
Beispiel #4
0
    def breadcrumb(self) -> Breadcrumb:
        """Render the breadcrumb to the current mode

        This methods job is to a) gather the breadcrumb from the
        parent modes, b) append it's own part and then return it
        """

        if parent_cls := self.parent_mode():
            # For some reason pylint does not understand that this is a class type
            breadcrumb = parent_cls().breadcrumb()  # pylint: disable=not-callable
        else:
            breadcrumb = Breadcrumb()

        breadcrumb.extend(self._topic_breadcrumb_item())
        breadcrumb.append(self._breadcrumb_item())

        return breadcrumb

    def _breadcrumb_item(self) -> BreadcrumbItem:
        """Return the breadcrumb item for the current mode"""
        # For the currently active mode use the same link as the "page title click"
        if request.get_ascii_input("mode") == self.name():
            breadcrumb_url = "javascript:window.location.reload(false)"
        else:
            breadcrumb_url = self._breadcrumb_url()

        return BreadcrumbItem(
            title=self.title(),
            url=breadcrumb_url,
        )
Beispiel #5
0
def _edit_annotation_breadcrumb(breadcrumb: Breadcrumb, title: str) -> Breadcrumb:
    breadcrumb.append(BreadcrumbItem(
        title=title,
        url=html.makeuri([]),
    ))
    return breadcrumb
Beispiel #6
0
    def breadcrumb(self) -> Breadcrumb:
        """Render the breadcrumb to the current mode

        This methods job is to a) gather the breadcrumb from the
        parent modes, b) append it's own part and then return it
        """

        if parent_cls := self.parent_mode():
            # For some reason pylint does not understand that this is a class type
            breadcrumb = parent_cls().breadcrumb()  # pylint: disable=not-callable
        else:
            breadcrumb = Breadcrumb()

            topic_item = self._topic_breadcrumb_item()
            if topic_item:
                breadcrumb.append(topic_item)

        breadcrumb.append(self._breadcrumb_item())

        return breadcrumb

    def _breadcrumb_item(self) -> BreadcrumbItem:
        """Return the breadcrumb item for the current mode"""
        # For the currently active mode use the same link as the "page title click"
        if html.request.get_ascii_input("mode") == self.name():
            breadcrumb_url = "javascript:window.location.reload(false)"
        else:
            breadcrumb_url = self._breadcrumb_url()

        return BreadcrumbItem(
            title=self.title(),