mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-22 05:12:22 -06:00
Merge branch 'develop' into develop-2.10
This commit is contained in:
@@ -175,13 +175,14 @@ class CustomField(models.Model):
|
||||
# Select
|
||||
elif self.type == CustomFieldTypeChoices.TYPE_SELECT:
|
||||
choices = [(c, c) for c in self.choices]
|
||||
default_choice = self.default if self.default in self.choices else None
|
||||
|
||||
if not required:
|
||||
if not required or default_choice is None:
|
||||
choices = add_blank_choice(choices)
|
||||
|
||||
# Set the initial value to the first available choice (if any)
|
||||
if set_initial and self.choices:
|
||||
initial = self.choices[0]
|
||||
if set_initial and default_choice:
|
||||
initial = default_choice
|
||||
|
||||
field_class = CSVChoiceField if for_csv_import else forms.ChoiceField
|
||||
field = field_class(
|
||||
|
||||
@@ -22,10 +22,8 @@ CONFIGCONTEXT_ACTIONS = """
|
||||
"""
|
||||
|
||||
OBJECTCHANGE_OBJECT = """
|
||||
{% if record.action != 3 and record.changed_object.get_absolute_url %}
|
||||
{% if record.changed_object.get_absolute_url %}
|
||||
<a href="{{ record.changed_object.get_absolute_url }}">{{ record.object_repr }}</a>
|
||||
{% elif record.action != 3 and record.related_object.get_absolute_url %}
|
||||
<a href="{{ record.related_object.get_absolute_url }}">{{ record.object_repr }}</a>
|
||||
{% else %}
|
||||
{{ record.object_repr }}
|
||||
{% endif %}
|
||||
|
||||
@@ -20,8 +20,8 @@ GROUP_BUTTON = '<div class="btn-group">\n' \
|
||||
GROUP_LINK = '<li><a href="{}"{}>{}</a></li>\n'
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def custom_links(obj):
|
||||
@register.simple_tag(takes_context=True)
|
||||
def custom_links(context, obj):
|
||||
"""
|
||||
Render all applicable links for the given object.
|
||||
"""
|
||||
@@ -30,8 +30,13 @@ def custom_links(obj):
|
||||
if not custom_links:
|
||||
return ''
|
||||
|
||||
context = {
|
||||
# Pass select context data when rendering the CustomLink
|
||||
link_context = {
|
||||
'obj': obj,
|
||||
'debug': context['debug'], # django.template.context_processors.debug
|
||||
'request': context['request'], # django.template.context_processors.request
|
||||
'user': context['user'], # django.contrib.auth.context_processors.auth
|
||||
'perms': context['perms'], # django.contrib.auth.context_processors.auth
|
||||
}
|
||||
template_code = ''
|
||||
group_names = OrderedDict()
|
||||
@@ -47,9 +52,9 @@ def custom_links(obj):
|
||||
# Add non-grouped links
|
||||
else:
|
||||
try:
|
||||
text_rendered = render_jinja2(cl.text, context)
|
||||
text_rendered = render_jinja2(cl.text, link_context)
|
||||
if text_rendered:
|
||||
link_rendered = render_jinja2(cl.url, context)
|
||||
link_rendered = render_jinja2(cl.url, link_context)
|
||||
link_target = ' target="_blank"' if cl.new_window else ''
|
||||
template_code += LINK_BUTTON.format(
|
||||
link_rendered, link_target, cl.button_class, text_rendered
|
||||
@@ -65,10 +70,10 @@ def custom_links(obj):
|
||||
|
||||
for cl in links:
|
||||
try:
|
||||
text_rendered = render_jinja2(cl.text, context)
|
||||
text_rendered = render_jinja2(cl.text, link_context)
|
||||
if text_rendered:
|
||||
link_target = ' target="_blank"' if cl.new_window else ''
|
||||
link_rendered = render_jinja2(cl.url, context)
|
||||
link_rendered = render_jinja2(cl.url, link_context)
|
||||
links_rendered.append(
|
||||
GROUP_LINK.format(link_rendered, link_target, text_rendered)
|
||||
)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from django import template
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db.models import Count, Prefetch, Q
|
||||
@@ -13,7 +12,7 @@ from rq import Worker
|
||||
from dcim.models import DeviceRole, Platform, Region, Site
|
||||
from tenancy.models import Tenant, TenantGroup
|
||||
from utilities.forms import ConfirmationForm
|
||||
from utilities.paginator import EnhancedPaginator
|
||||
from utilities.paginator import EnhancedPaginator, get_paginate_count
|
||||
from utilities.utils import copy_safe_request, shallow_compare_dict
|
||||
from utilities.views import (
|
||||
BulkDeleteView, BulkEditView, BulkImportView, ObjectView, ObjectDeleteView, ObjectEditView, ObjectListView,
|
||||
@@ -258,7 +257,7 @@ class ObjectChangeLogView(View):
|
||||
# Apply the request context
|
||||
paginate = {
|
||||
'paginator_class': EnhancedPaginator,
|
||||
'per_page': request.GET.get('per_page', settings.PAGINATE_COUNT)
|
||||
'per_page': get_paginate_count(request)
|
||||
}
|
||||
RequestConfig(request, paginate).configure(objectchanges_table)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user