Skip to content

Admin helpers

hypha.apply.categories.admin_helpers

MetaTermButtonHelper

Bases: ButtonHelper

delete_button

delete_button(pk, *args, **kwargs)

Ensure that the delete button is not shown for root meta term.

Source code in hypha/apply/categories/admin_helpers.py
def delete_button(self, pk, *args, **kwargs):
    """Ensure that the delete button is not shown for root meta term."""
    instance = self.model.objects.get(pk=pk)
    if instance.is_root():
        return
    return super().delete_button(pk, *args, **kwargs)

prepare_classname

prepare_classname(start=None, add=None, exclude=None)

Parse classname sets into final css classes list.

Source code in hypha/apply/categories/admin_helpers.py
def prepare_classname(self, start=None, add=None, exclude=None):
    """Parse classname sets into final css classes list."""
    classname = start or []
    classname.extend(add or [])
    return self.finalise_classname(classname, exclude or [])

add_child_button

add_child_button(pk, child_verbose_name, **kwargs)

Build a add child button, to easily add a child under meta term.

Source code in hypha/apply/categories/admin_helpers.py
def add_child_button(self, pk, child_verbose_name, **kwargs):
    """Build a add child button, to easily add a child under meta term."""
    instance = self.model.objects.get(pk=pk)
    if (
        instance.is_archived
        or instance.get_parent()
        and instance.get_parent().is_archived
    ):
        return

    classname = self.prepare_classname(
        start=self.edit_button_classnames + ["icon", "icon-plus"],
        add=kwargs.get("classnames_add"),
        exclude=kwargs.get("classnames_exclude"),
    )
    return {
        "classname": classname,
        "label": "Add %s %s" % (child_verbose_name, self.verbose_name),
        "title": "Add %s %s under this one"
        % (child_verbose_name, self.verbose_name),
        "url": self.url_helper.get_action_url("add_child", quote(pk)),
    }

get_buttons_for_obj

get_buttons_for_obj(obj, exclude=None, *args, **kwargs)

Override the getting of buttons, prepending create child button.

Source code in hypha/apply/categories/admin_helpers.py
def get_buttons_for_obj(self, obj, exclude=None, *args, **kwargs):
    """Override the getting of buttons, prepending create child button."""
    buttons = super().get_buttons_for_obj(obj, *args, **kwargs)

    add_child_button = self.add_child_button(
        pk=getattr(obj, self.opts.pk.attname),
        child_verbose_name=obj.node_child_verbose_name,
        **kwargs,
    )
    buttons.append(add_child_button)

    return buttons