mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 09:16:10 -06:00
MVP: custom field. url open in new_window
adds new_window support to the custom_fields URL type. as discussed in #11300
This commit is contained in:
parent
5a5fcf7d37
commit
1eddade01e
@ -77,7 +77,7 @@ class CustomFieldFilterSet(BaseFilterSet):
|
||||
model = CustomField
|
||||
fields = [
|
||||
'id', 'content_types', 'name', 'group_name', 'required', 'search_weight', 'filter_logic', 'ui_visibility',
|
||||
'weight', 'is_cloneable', 'description',
|
||||
'weight', 'is_cloneable', 'description', 'new_window',
|
||||
]
|
||||
|
||||
def search(self, queryset, name, value):
|
||||
|
@ -36,7 +36,7 @@ class CustomFieldFilterForm(SavedFiltersMixin, FilterForm):
|
||||
fieldsets = (
|
||||
(None, ('q', 'filter_id')),
|
||||
('Attributes', (
|
||||
'type', 'content_type_id', 'group_name', 'weight', 'required', 'ui_visibility', 'is_cloneable',
|
||||
'type', 'content_type_id', 'group_name', 'weight', 'required', 'ui_visibility', 'is_cloneable', 'new_window',
|
||||
)),
|
||||
)
|
||||
content_type_id = ContentTypeMultipleChoiceField(
|
||||
@ -72,6 +72,12 @@ class CustomFieldFilterForm(SavedFiltersMixin, FilterForm):
|
||||
choices=BOOLEAN_WITH_BLANK_CHOICES
|
||||
)
|
||||
)
|
||||
new_window = forms.NullBooleanField(
|
||||
required=False,
|
||||
widget=forms.Select(
|
||||
choices=BOOLEAN_WITH_BLANK_CHOICES
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class CustomLinkFilterForm(SavedFiltersMixin, FilterForm):
|
||||
|
@ -50,7 +50,7 @@ class CustomFieldForm(BootstrapMixin, forms.ModelForm):
|
||||
('Custom Field', (
|
||||
'content_types', 'name', 'label', 'group_name', 'type', 'object_type', 'required', 'description',
|
||||
)),
|
||||
('Behavior', ('search_weight', 'filter_logic', 'ui_visibility', 'weight', 'is_cloneable')),
|
||||
('Behavior', ('search_weight', 'filter_logic', 'ui_visibility', 'weight', 'is_cloneable', 'new_window')),
|
||||
('Values', ('default', 'choices')),
|
||||
('Validation', ('validation_minimum', 'validation_maximum', 'validation_regex')),
|
||||
)
|
||||
|
18
netbox/extras/migrations/0093_customfield_new_window.py
Normal file
18
netbox/extras/migrations/0093_customfield_new_window.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.1.9 on 2023-05-29 19:44
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('extras', '0092_delete_jobresult'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='customfield',
|
||||
name='new_window',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
@ -176,13 +176,17 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
||||
verbose_name='Cloneable',
|
||||
help_text=_('Replicate this value when cloning objects')
|
||||
)
|
||||
new_window = models.BooleanField(
|
||||
default=False,
|
||||
help_text=_("Force link to open in a new window")
|
||||
)
|
||||
|
||||
objects = CustomFieldManager()
|
||||
|
||||
clone_fields = (
|
||||
'content_types', 'type', 'object_type', 'group_name', 'description', 'required', 'search_weight',
|
||||
'filter_logic', 'default', 'weight', 'validation_minimum', 'validation_maximum', 'validation_regex', 'choices',
|
||||
'ui_visibility', 'is_cloneable',
|
||||
'ui_visibility', 'is_cloneable', 'new_window',
|
||||
)
|
||||
|
||||
class Meta:
|
||||
|
@ -38,7 +38,7 @@ class CustomFieldTable(NetBoxTable):
|
||||
fields = (
|
||||
'pk', 'id', 'name', 'content_types', 'label', 'type', 'group_name', 'required', 'default', 'description',
|
||||
'search_weight', 'filter_logic', 'ui_visibility', 'is_cloneable', 'weight', 'choices', 'created',
|
||||
'last_updated',
|
||||
'last_updated', 'new_window',
|
||||
)
|
||||
default_columns = ('pk', 'name', 'content_types', 'label', 'group_name', 'type', 'required', 'description')
|
||||
|
||||
|
@ -12,7 +12,11 @@
|
||||
{% elif customfield.type == 'datetime' and value %}
|
||||
{{ value|annotated_date }}
|
||||
{% elif customfield.type == 'url' and value %}
|
||||
{% if customfield.new_window %}
|
||||
<a href="{{ value }}" target="_blank">{{ value|truncatechars:70 }} <i class="mdi mdi-open-in-new"></i></a>
|
||||
{% else %}
|
||||
<a href="{{ value }}">{{ value|truncatechars:70 }}</a>
|
||||
{% endif %}
|
||||
{% elif customfield.type == 'json' and value %}
|
||||
<pre>{{ value|json }}</pre>
|
||||
{% elif customfield.type == 'multiselect' and value %}
|
||||
|
Loading…
Reference in New Issue
Block a user