Merge branch 'develop' into 5509-cf-test-2

This commit is contained in:
Arthur 2023-09-13 14:34:57 -07:00
commit a146051c44
4 changed files with 45 additions and 6 deletions

View File

@ -16,6 +16,7 @@ from django.utils.translation import gettext as _
from extras.choices import BookmarkOrderingChoices
from extras.utils import FeatureQuery
from utilities.choices import ButtonColorChoices
from utilities.forms import BootstrapMixin
from utilities.permissions import get_permission_for_model
from utilities.templatetags.builtins.filters import render_markdown
@ -115,6 +116,22 @@ class DashboardWidget:
def name(self):
return f'{self.__class__.__module__.split(".")[0]}.{self.__class__.__name__}'
@property
def fg_color(self):
"""
Return the appropriate foreground (text) color for the widget's color.
"""
if self.color in (
ButtonColorChoices.CYAN,
ButtonColorChoices.GRAY,
ButtonColorChoices.GREY,
ButtonColorChoices.TEAL,
ButtonColorChoices.WHITE,
ButtonColorChoices.YELLOW,
):
return ButtonColorChoices.BLACK
return ButtonColorChoices.WHITE
@property
def form_data(self):
return {

View File

@ -1,7 +1,6 @@
from django.contrib.contenttypes.models import ContentType
from django.db.models import F, Prefetch
from django.db.models.expressions import RawSQL
from django.db.models.functions import Round
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
from django.utils.translation import gettext as _
@ -11,6 +10,7 @@ from dcim.filtersets import InterfaceFilterSet
from dcim.models import Interface, Site
from netbox.views import generic
from tenancy.views import ObjectContactsView
from utilities.tables import get_table_ordering
from utilities.utils import count_related
from utilities.views import ViewTab, register_model_view
from virtualization.filtersets import VMInterfaceFilterSet
@ -606,7 +606,7 @@ class PrefixIPAddressesView(generic.ObjectChildrenView):
return parent.get_child_ips().restrict(request.user, 'view').prefetch_related('vrf', 'tenant', 'tenant__group')
def prep_table_data(self, request, queryset, parent):
if not request.GET.get('q') and not request.GET.get('sort'):
if not get_table_ordering(request, self.table):
return add_available_ipaddresses(parent.prefix, queryset, parent.is_pool)
return queryset
@ -952,7 +952,9 @@ class VLANGroupVLANsView(generic.ObjectChildrenView):
)
def prep_table_data(self, request, queryset, parent):
return add_available_vlans(parent.get_child_vlans(), parent)
if not get_table_ordering(request, self.table):
return add_available_vlans(parent.get_child_vlans(), parent)
return queryset
#

View File

@ -9,14 +9,16 @@
gs-id="{{ widget.id }}"
>
<div class="card grid-stack-item-content">
<div class="card-header text-center text-light bg-{% if widget.color %}{{ widget.color }}{% else %}secondary{% endif %} p-1">
<div class="card-header text-center text-{{ widget.fg_color }} bg-{{ widget.color|default:"secondary" }} p-1">
<div class="float-start ps-1">
<a href="#"
hx-get="{% url 'extras:dashboardwidget_config' id=widget.id %}"
hx-target="#htmx-modal-content"
data-bs-toggle="modal"
data-bs-target="#htmx-modal"
><i class="mdi mdi-cog text-gray"></i></a>
>
<i class="mdi mdi-cog text-{{ widget.fg_color }}"></i>
</a>
</div>
<div class="float-end pe-1">
<a href="#"
@ -24,7 +26,9 @@
hx-target="#htmx-modal-content"
data-bs-toggle="modal"
data-bs-target="#htmx-modal"
><i class="mdi mdi-close text-gray"></i></a>
>
<i class="mdi mdi-close text-{{ widget.fg_color }}"></i>
</a>
</div>
{% if widget.title %}
<strong>{{ widget.title }}</strong>

View File

@ -1,8 +1,24 @@
__all__ = (
'get_table_ordering',
'linkify_phone',
)
def get_table_ordering(request, table):
"""
Given a request, return the prescribed table ordering, if any. This may be necessary to determine prior to rendering
the table itself.
"""
# Check for an explicit ordering
if 'sort' in request.GET:
return request.GET['sort'] or None
# Check for a configured preference
if request.user.is_authenticated:
if preference := request.user.config.get(f'tables.{table.__name__}.ordering'):
return preference
def linkify_phone(value):
"""
Render a telephone number as a hyperlink.