Просмотр исходного кода

#19739: Include tab character as CSV delimiter choice

Jeremy Stretch 6 месяцев назад
Родитель
Сommit
f3ecf94393
2 измененных файлов с 13 добавлено и 5 удалено
  1. 1 0
      netbox/netbox/constants.py
  2. 12 5
      netbox/netbox/preferences.py

+ 1 - 0
netbox/netbox/constants.py

@@ -66,4 +66,5 @@ CSV_DELIMITERS = {
     'comma': ',',
     'semicolon': ';',
     'pipe': '|',
+    'tab': '\t',
 }

+ 12 - 5
netbox/netbox/preferences.py

@@ -1,6 +1,7 @@
 from django.conf import settings
 from django.utils.translation import gettext_lazy as _
 
+from netbox.constants import CSV_DELIMITERS
 from netbox.registry import registry
 from users.preferences import UserPreference
 from utilities.paginator import EnhancedPaginator
@@ -12,6 +13,16 @@ def get_page_lengths():
     ]
 
 
+def get_csv_delimiters():
+    choices = []
+    for k, v in CSV_DELIMITERS.items():
+        label = _(k.title())
+        if v.strip():
+            label = f'{label} ({v})'
+        choices.append((k, label))
+    return choices
+
+
 PREFERENCES = {
 
     # User interface
@@ -74,11 +85,7 @@ PREFERENCES = {
     ),
     'csv_delimiter': UserPreference(
         label=_('CSV delimiter'),
-        choices=(
-            ('comma', 'Comma (,)'),
-            ('semicolon', 'Semicolon (;)'),
-            ('pipe', 'Pipe (|)'),
-        ),
+        choices=get_csv_delimiters(),
         default='comma',
         description=_('The character used to separate fields in CSV data')
     ),