mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 18:08:38 -06:00
Merge 6744a96652
into 6df0a02d8d
This commit is contained in:
commit
3d28dfa3e5
@ -1,3 +1,4 @@
|
|||||||
|
from django.template import loader
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.urls.exceptions import NoReverseMatch
|
from django.urls.exceptions import NoReverseMatch
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
@ -27,12 +28,14 @@ class ObjectAction:
|
|||||||
Params:
|
Params:
|
||||||
name: The action name appended to the module for view resolution
|
name: The action name appended to the module for view resolution
|
||||||
label: Human-friendly label for the rendered button
|
label: Human-friendly label for the rendered button
|
||||||
|
template_name: Name of the HTML template which renders the button
|
||||||
multi: Set to True if this action is performed by selecting multiple objects (i.e. using a table)
|
multi: Set to True if this action is performed by selecting multiple objects (i.e. using a table)
|
||||||
permissions_required: The set of permissions a user must have to perform the action
|
permissions_required: The set of permissions a user must have to perform the action
|
||||||
url_kwargs: The set of URL keyword arguments to pass when resolving the view's URL
|
url_kwargs: The set of URL keyword arguments to pass when resolving the view's URL
|
||||||
"""
|
"""
|
||||||
name = ''
|
name = ''
|
||||||
label = None
|
label = None
|
||||||
|
template_name = None
|
||||||
multi = False
|
multi = False
|
||||||
permissions_required = set()
|
permissions_required = set()
|
||||||
url_kwargs = []
|
url_kwargs = []
|
||||||
@ -49,11 +52,13 @@ class ObjectAction:
|
|||||||
return
|
return
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_context(cls, context, obj):
|
def render(cls, obj, **kwargs):
|
||||||
return {
|
context = {
|
||||||
'url': cls.get_url(obj),
|
'url': cls.get_url(obj),
|
||||||
'label': cls.label,
|
'label': cls.label,
|
||||||
|
**kwargs,
|
||||||
}
|
}
|
||||||
|
return loader.render_to_string(cls.template_name, context)
|
||||||
|
|
||||||
|
|
||||||
class AddObject(ObjectAction):
|
class AddObject(ObjectAction):
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
<button type="submit" name="_sync" {% formaction %}="{{ url }}" class="btn btn-primary">
|
<button type="submit" name="_sync" {% formaction %}="{{ url }}{% if return_url %}?return_url={{ return_url }}{% endif %}" class="btn btn-primary">
|
||||||
<i class="mdi mdi-sync" aria-hidden="true"></i> {{ label }}
|
<i class="mdi mdi-sync" aria-hidden="true"></i> {{ label }}
|
||||||
</button>
|
</button>
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
<button type="submit" name="_disconnect" {% formaction %}="{{ url }}" class="btn btn-red">
|
<button type="submit" name="_disconnect" {% formaction %}="{{ url }}{% if return_url %}?return_url={{ return_url }}{% endif %}" class="btn btn-red">
|
||||||
<i class="mdi mdi-ethernet-cable-off" aria-hidden="true"></i> {{ label }}
|
<i class="mdi mdi-ethernet-cable-off" aria-hidden="true"></i> {{ label }}
|
||||||
</button>
|
</button>
|
||||||
|
@ -35,7 +35,7 @@ Context:
|
|||||||
</div>
|
</div>
|
||||||
<div class="d-print-none mt-2">
|
<div class="d-print-none mt-2">
|
||||||
{% block bulk_controls %}
|
{% block bulk_controls %}
|
||||||
{% action_buttons actions model multi=True %}
|
{% action_buttons actions model multi=True return_url=request.path %}
|
||||||
{% block bulk_extra_controls %}{% endblock %}
|
{% block bulk_extra_controls %}{% endblock %}
|
||||||
{% endblock bulk_controls %}
|
{% endblock bulk_controls %}
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
<button type="submit" name="_delete" {% formaction %}="{{ url }}" class="btn btn-red">
|
<button type="submit" name="_delete" {% formaction %}="{{ url }}{% if return_url %}?return_url={{ return_url }}{% endif %}" class="btn btn-red">
|
||||||
<i class="mdi mdi-trash-can-outline" aria-hidden="true"></i> {{ label }}
|
<i class="mdi mdi-trash-can-outline" aria-hidden="true"></i> {{ label }}
|
||||||
</button>
|
</button>
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
<button type="submit" name="_edit" {% formaction %}="{{ url }}" class="btn btn-yellow">
|
<button type="submit" name="_edit" {% formaction %}="{{ url }}{% if return_url %}?return_url={{ return_url }}{% endif %}" class="btn btn-yellow">
|
||||||
<i class="mdi mdi-pencil" aria-hidden="true"></i> {{ label }}
|
<i class="mdi mdi-pencil" aria-hidden="true"></i> {{ label }}
|
||||||
</button>
|
</button>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{% if url %}
|
{% if url %}
|
||||||
<button type="submit" name="_rename" {% formaction %}="{{ url }}" class="btn btn-yellow">
|
<button type="submit" name="_rename" {% formaction %}="{{ url }}{% if return_url %}?return_url={{ return_url }}{% endif %}" class="btn btn-yellow">
|
||||||
<i class="mdi mdi-pencil" aria-hidden="true"></i> {{ label }}
|
<i class="mdi mdi-pencil" aria-hidden="true"></i> {{ label }}
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
from django import template
|
from django import template
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.template import loader
|
|
||||||
from django.urls import NoReverseMatch, reverse
|
from django.urls import NoReverseMatch, reverse
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
@ -29,11 +28,10 @@ __all__ = (
|
|||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag
|
||||||
def action_buttons(context, actions, obj, multi=False):
|
def action_buttons(actions, obj, multi=False, **kwargs):
|
||||||
buttons = [
|
buttons = [
|
||||||
loader.render_to_string(action.template_name, action.get_context(context, obj))
|
action.render(obj, **kwargs) for action in actions if action.multi == multi
|
||||||
for action in actions if action.multi == multi
|
|
||||||
]
|
]
|
||||||
return mark_safe(''.join(buttons))
|
return mark_safe(''.join(buttons))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user