mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-25 10:18:56 +02:00
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import json
|
||||
from typing import Dict, List, Tuple
|
||||
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
@@ -19,8 +18,8 @@ class APISelect(forms.Select):
|
||||
"""
|
||||
template_name = 'widgets/apiselect.html'
|
||||
option_template_name = 'widgets/select_option.html'
|
||||
dynamic_params: Dict[str, str]
|
||||
static_params: Dict[str, List[str]]
|
||||
dynamic_params: dict[str, str]
|
||||
static_params: dict[str, list[str]]
|
||||
|
||||
def get_context(self, name, value, attrs):
|
||||
context = super().get_context(name, value, attrs)
|
||||
@@ -35,8 +34,8 @@ class APISelect(forms.Select):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.attrs['class'] = 'api-select'
|
||||
self.dynamic_params: Dict[str, List[str]] = {}
|
||||
self.static_params: Dict[str, List[str]] = {}
|
||||
self.dynamic_params: dict[str, list[str]] = {}
|
||||
self.static_params: dict[str, list[str]] = {}
|
||||
|
||||
if api_url:
|
||||
self.attrs['data-url'] = '/{}{}'.format(settings.BASE_PATH, api_url.lstrip('/')) # Inject BASE_PATH
|
||||
@@ -96,7 +95,7 @@ class APISelect(forms.Select):
|
||||
Process an entire query_params dictionary, and handle primitive or list values.
|
||||
"""
|
||||
for key, value in query_params.items():
|
||||
if isinstance(value, (List, Tuple)):
|
||||
if isinstance(value, (list, tuple)):
|
||||
# If value is a list/tuple, iterate through each item.
|
||||
for item in value:
|
||||
self._process_query_param(key, item)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import datetime
|
||||
import os
|
||||
from dataclasses import asdict, dataclass, field
|
||||
from typing import Union
|
||||
|
||||
import yaml
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
@@ -28,9 +27,9 @@ class FeatureSet:
|
||||
class ReleaseInfo:
|
||||
version: str
|
||||
edition: str
|
||||
published: Union[datetime.date, None] = None
|
||||
designation: Union[str, None] = None
|
||||
build: Union[str, None] = None
|
||||
published: datetime.date | None = None
|
||||
designation: str | None = None
|
||||
build: str | None = None
|
||||
features: FeatureSet = field(default_factory=FeatureSet)
|
||||
|
||||
@property
|
||||
@@ -57,12 +56,12 @@ def load_release_data():
|
||||
base_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
# Load canonical release attributes
|
||||
with open(os.path.join(base_path, RELEASE_PATH), 'r') as release_file:
|
||||
with open(os.path.join(base_path, RELEASE_PATH)) as release_file:
|
||||
data = yaml.safe_load(release_file)
|
||||
|
||||
# Overlay any local release date (if defined)
|
||||
try:
|
||||
with open(os.path.join(base_path, LOCAL_RELEASE_PATH), 'r') as release_file:
|
||||
with open(os.path.join(base_path, LOCAL_RELEASE_PATH)) as release_file:
|
||||
local_data = yaml.safe_load(release_file)
|
||||
except FileNotFoundError:
|
||||
local_data = {}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import json
|
||||
from typing import Any, Dict
|
||||
from typing import Any
|
||||
from urllib.parse import quote
|
||||
|
||||
from django import template
|
||||
@@ -306,7 +306,7 @@ def startswith(text: str, starts: str) -> bool:
|
||||
|
||||
|
||||
@register.filter
|
||||
def get_key(value: Dict, arg: str) -> Any:
|
||||
def get_key(value: dict, arg: str) -> Any:
|
||||
"""
|
||||
Template implementation of `dict.get()`, for accessing dict values
|
||||
by key when the key is not able to be used in a template. For
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from datetime import datetime, timezone
|
||||
from datetime import UTC, datetime
|
||||
from itertools import chain
|
||||
|
||||
import django_filters
|
||||
@@ -156,12 +156,12 @@ class ChangeLoggedFilterSetTests(BaseFilterSetTests):
|
||||
|
||||
def test_created(self):
|
||||
pk_list = self.queryset.values_list('pk', flat=True)[:2]
|
||||
self.queryset.filter(pk__in=pk_list).update(created=datetime(2021, 1, 1, 0, 0, 0, tzinfo=timezone.utc))
|
||||
self.queryset.filter(pk__in=pk_list).update(created=datetime(2021, 1, 1, 0, 0, 0, tzinfo=UTC))
|
||||
params = {'created': ['2021-01-01T00:00:00']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_last_updated(self):
|
||||
pk_list = self.queryset.values_list('pk', flat=True)[:2]
|
||||
self.queryset.filter(pk__in=pk_list).update(last_updated=datetime(2021, 1, 2, 0, 0, 0, tzinfo=timezone.utc))
|
||||
self.queryset.filter(pk__in=pk_list).update(last_updated=datetime(2021, 1, 2, 0, 0, 0, tzinfo=UTC))
|
||||
params = {'last_updated': ['2021-01-02T00:00:00']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from collections.abc import Iterable
|
||||
from dataclasses import dataclass
|
||||
from typing import Iterable
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.mixins import AccessMixin
|
||||
|
||||
Reference in New Issue
Block a user