From 76f5b6738f48b7802480b98113608907b210bf6e Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 13 Sep 2024 16:04:52 -0400 Subject: [PATCH] Closes #123: Introduce template tags for branch action buttons --- .../templates/netbox_branching/branch.html | 41 +++--------------- .../buttons/branch_archive.html | 10 +++++ .../buttons/branch_merge.html | 10 +++++ .../buttons/branch_revert.html | 10 +++++ .../netbox_branching/buttons/branch_sync.html | 10 +++++ netbox_branching/templatetags/__init__.py | 0 .../templatetags/branch_buttons.py | 42 +++++++++++++++++++ 7 files changed, 87 insertions(+), 36 deletions(-) create mode 100644 netbox_branching/templates/netbox_branching/buttons/branch_archive.html create mode 100644 netbox_branching/templates/netbox_branching/buttons/branch_merge.html create mode 100644 netbox_branching/templates/netbox_branching/buttons/branch_revert.html create mode 100644 netbox_branching/templates/netbox_branching/buttons/branch_sync.html create mode 100644 netbox_branching/templatetags/__init__.py create mode 100644 netbox_branching/templatetags/branch_buttons.py diff --git a/netbox_branching/templates/netbox_branching/branch.html b/netbox_branching/templates/netbox_branching/branch.html index 75edc00..75eff0c 100644 --- a/netbox_branching/templates/netbox_branching/branch.html +++ b/netbox_branching/templates/netbox_branching/branch.html @@ -4,6 +4,7 @@ {% load plugins %} {% load render_table from django_tables2 %} {% load i18n %} +{% load branch_buttons %} {% block extra_controls %} {% if not object.is_active %} @@ -22,44 +23,12 @@ {% endif %} {% if object.ready %} - {% if perms.netbox_branching.sync_branch %} - - {% trans "Sync" %} - - {% else %} - - {% endif %} - {% if perms.netbox_branching.merge_branch %} - - {% trans "Merge" %} - - {% else %} - - {% endif %} + {% branch_sync_button object %} + {% branch_merge_button object %} {% endif %} {% if object.merged %} - {% if perms.netbox_branching.revert_branch %} - - {% trans "Revert" %} - - {% else %} - - {% endif %} - {% if perms.netbox_branching.archive_branch %} - - {% trans "Archive" %} - - {% else %} - - {% endif %} + {% branch_revert_button object %} + {% branch_archive_button object %} {% endif %} {% endblock %} diff --git a/netbox_branching/templates/netbox_branching/buttons/branch_archive.html b/netbox_branching/templates/netbox_branching/buttons/branch_archive.html new file mode 100644 index 0000000..1ecbf34 --- /dev/null +++ b/netbox_branching/templates/netbox_branching/buttons/branch_archive.html @@ -0,0 +1,10 @@ +{% load i18n %} +{% if perms.netbox_branching.archive_branch %} + + {% trans "Archive" %} + +{% else %} + +{% endif %} diff --git a/netbox_branching/templates/netbox_branching/buttons/branch_merge.html b/netbox_branching/templates/netbox_branching/buttons/branch_merge.html new file mode 100644 index 0000000..efbb5b0 --- /dev/null +++ b/netbox_branching/templates/netbox_branching/buttons/branch_merge.html @@ -0,0 +1,10 @@ +{% load i18n %} +{% if perms.netbox_branching.merge_branch %} + + {% trans "Merge" %} + +{% else %} + +{% endif %} diff --git a/netbox_branching/templates/netbox_branching/buttons/branch_revert.html b/netbox_branching/templates/netbox_branching/buttons/branch_revert.html new file mode 100644 index 0000000..f004631 --- /dev/null +++ b/netbox_branching/templates/netbox_branching/buttons/branch_revert.html @@ -0,0 +1,10 @@ +{% load i18n %} +{% if perms.netbox_branching.revert_branch %} + + {% trans "Revert" %} + +{% else %} + +{% endif %} diff --git a/netbox_branching/templates/netbox_branching/buttons/branch_sync.html b/netbox_branching/templates/netbox_branching/buttons/branch_sync.html new file mode 100644 index 0000000..fcf21bb --- /dev/null +++ b/netbox_branching/templates/netbox_branching/buttons/branch_sync.html @@ -0,0 +1,10 @@ +{% load i18n %} +{% if perms.netbox_branching.sync_branch %} + + {% trans "Sync" %} + +{% else %} + +{% endif %} diff --git a/netbox_branching/templatetags/__init__.py b/netbox_branching/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/netbox_branching/templatetags/branch_buttons.py b/netbox_branching/templatetags/branch_buttons.py new file mode 100644 index 0000000..2fa62f2 --- /dev/null +++ b/netbox_branching/templatetags/branch_buttons.py @@ -0,0 +1,42 @@ +from django import template + +__all__ = ( + 'branch_sync_button', + 'branch_merge_button', + 'branch_revert_button', + 'branch_archive_button', +) + +register = template.Library() + + +@register.inclusion_tag('netbox_branching/buttons/branch_sync.html', takes_context=True) +def branch_sync_button(context, branch): + return { + 'branch': branch, + 'perms': context.get('perms'), + } + + +@register.inclusion_tag('netbox_branching/buttons/branch_merge.html', takes_context=True) +def branch_merge_button(context, branch): + return { + 'branch': branch, + 'perms': context.get('perms'), + } + + +@register.inclusion_tag('netbox_branching/buttons/branch_revert.html', takes_context=True) +def branch_revert_button(context, branch): + return { + 'branch': branch, + 'perms': context.get('perms'), + } + + +@register.inclusion_tag('netbox_branching/buttons/branch_archive.html', takes_context=True) +def branch_archive_button(context, branch): + return { + 'branch': branch, + 'perms': context.get('perms'), + }