mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-23 04:22:01 -06:00
Closes #13412: Enable pagination of custom field choice set choices
This commit is contained in:
parent
b4acbb5e16
commit
af06510921
@ -1,6 +1,7 @@
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.paginator import EmptyPage
|
||||
from django.db.models import Count, Q
|
||||
from django.http import HttpResponseBadRequest, HttpResponseForbidden, HttpResponse
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
@ -18,6 +19,7 @@ from netbox.config import get_config, PARAMS
|
||||
from netbox.views import generic
|
||||
from utilities.forms import ConfirmationForm, get_field_value
|
||||
from utilities.htmx import is_htmx
|
||||
from utilities.paginator import EnhancedPaginator, get_paginate_count
|
||||
from utilities.rqworker import get_workers_for_queue
|
||||
from utilities.templatetags.builtins.filters import render_markdown
|
||||
from utilities.utils import copy_safe_request, count_related, get_viewname, normalize_querydict, shallow_compare_dict
|
||||
@ -89,6 +91,25 @@ class CustomFieldChoiceSetListView(generic.ObjectListView):
|
||||
class CustomFieldChoiceSetView(generic.ObjectView):
|
||||
queryset = CustomFieldChoiceSet.objects.all()
|
||||
|
||||
def get_extra_context(self, request, instance):
|
||||
|
||||
# Paginate choices list
|
||||
per_page = get_paginate_count(request)
|
||||
try:
|
||||
page_number = request.GET.get('page', 1)
|
||||
except ValueError:
|
||||
page_number = 1
|
||||
paginator = EnhancedPaginator(instance.choices, per_page)
|
||||
try:
|
||||
choices = paginator.page(page_number)
|
||||
except EmptyPage:
|
||||
choices = paginator.page(paginator.num_pages)
|
||||
|
||||
return {
|
||||
'paginator': paginator,
|
||||
'choices': choices,
|
||||
}
|
||||
|
||||
|
||||
@register_model_view(CustomFieldChoiceSet, 'edit')
|
||||
class CustomFieldChoiceSetEditView(generic.ObjectEditView):
|
||||
|
@ -55,18 +55,14 @@
|
||||
<th>Label</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for value, label in object.choices|slice:":50" %}
|
||||
{% for value, label in choices %}
|
||||
<tr>
|
||||
<td>{{ value }}</td>
|
||||
<td>{{ label }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% if object.choices|length > 50 %}
|
||||
<tr>
|
||||
<td colspan="2" class="text-muted">(Additional choices not displayed)</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</table>
|
||||
{% include 'inc/paginator.html' with page=choices %}
|
||||
</div>
|
||||
</div>
|
||||
{% plugin_right_page object %}
|
||||
|
Loading…
Reference in New Issue
Block a user