mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Introduce ContentTypesColumn for custom field and webhook tables
This commit is contained in:
@ -35,7 +35,6 @@ class CustomField(ChangeLoggedModel):
|
|||||||
content_types = models.ManyToManyField(
|
content_types = models.ManyToManyField(
|
||||||
to=ContentType,
|
to=ContentType,
|
||||||
related_name='custom_fields',
|
related_name='custom_fields',
|
||||||
verbose_name='Object(s)',
|
|
||||||
limit_choices_to=FeatureQuery('custom_fields'),
|
limit_choices_to=FeatureQuery('custom_fields'),
|
||||||
help_text='The object(s) to which this field applies.'
|
help_text='The object(s) to which this field applies.'
|
||||||
)
|
)
|
||||||
|
@ -2,7 +2,8 @@ import django_tables2 as tables
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from utilities.tables import (
|
from utilities.tables import (
|
||||||
BaseTable, BooleanColumn, ButtonsColumn, ChoiceFieldColumn, ColorColumn, ContentTypeColumn, ToggleColumn,
|
BaseTable, BooleanColumn, ButtonsColumn, ChoiceFieldColumn, ColorColumn, ContentTypeColumn, ContentTypesColumn,
|
||||||
|
ToggleColumn,
|
||||||
)
|
)
|
||||||
from .models import *
|
from .models import *
|
||||||
|
|
||||||
@ -37,14 +38,16 @@ class CustomFieldTable(BaseTable):
|
|||||||
name = tables.Column(
|
name = tables.Column(
|
||||||
linkify=True
|
linkify=True
|
||||||
)
|
)
|
||||||
|
content_types = ContentTypesColumn()
|
||||||
required = BooleanColumn()
|
required = BooleanColumn()
|
||||||
|
|
||||||
class Meta(BaseTable.Meta):
|
class Meta(BaseTable.Meta):
|
||||||
model = CustomField
|
model = CustomField
|
||||||
fields = (
|
fields = (
|
||||||
'pk', 'name', 'label', 'type', 'required', 'weight', 'default', 'description', 'filter_logic', 'choices',
|
'pk', 'name', 'content_types', 'label', 'type', 'required', 'weight', 'default', 'description',
|
||||||
|
'filter_logic', 'choices',
|
||||||
)
|
)
|
||||||
default_columns = ('pk', 'name', 'label', 'type', 'required', 'description')
|
default_columns = ('pk', 'name', 'content_types', 'label', 'type', 'required', 'description')
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -98,6 +101,7 @@ class WebhookTable(BaseTable):
|
|||||||
name = tables.Column(
|
name = tables.Column(
|
||||||
linkify=True
|
linkify=True
|
||||||
)
|
)
|
||||||
|
content_types = ContentTypesColumn()
|
||||||
enabled = BooleanColumn()
|
enabled = BooleanColumn()
|
||||||
type_create = BooleanColumn()
|
type_create = BooleanColumn()
|
||||||
type_update = BooleanColumn()
|
type_update = BooleanColumn()
|
||||||
@ -106,11 +110,12 @@ class WebhookTable(BaseTable):
|
|||||||
class Meta(BaseTable.Meta):
|
class Meta(BaseTable.Meta):
|
||||||
model = Webhook
|
model = Webhook
|
||||||
fields = (
|
fields = (
|
||||||
'pk', 'name', 'enabled', 'type_create', 'type_update', 'type_delete', 'http_method', 'payload_url',
|
'pk', 'name', 'content_types', 'enabled', 'type_create', 'type_update', 'type_delete', 'http_method',
|
||||||
'secret', 'ssl_validation', 'ca_file_path',
|
'payload_url', 'secret', 'ssl_validation', 'ca_file_path',
|
||||||
)
|
)
|
||||||
default_columns = (
|
default_columns = (
|
||||||
'pk', 'name', 'enabled', 'type_create', 'type_update', 'type_delete', 'http_method', 'payload_url',
|
'pk', 'name', 'content_types', 'enabled', 'type_create', 'type_update', 'type_delete', 'http_method',
|
||||||
|
'payload_url',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@ from django_tables2.data import TableQuerysetData
|
|||||||
from django_tables2.utils import Accessor
|
from django_tables2.utils import Accessor
|
||||||
|
|
||||||
from extras.models import CustomField
|
from extras.models import CustomField
|
||||||
|
from extras.utils import FeatureQuery
|
||||||
|
from .utils import content_type_name
|
||||||
from .paginator import EnhancedPaginator, get_paginate_count
|
from .paginator import EnhancedPaginator, get_paginate_count
|
||||||
|
|
||||||
|
|
||||||
@ -235,12 +237,20 @@ class ContentTypeColumn(tables.Column):
|
|||||||
Display a ContentType instance.
|
Display a ContentType instance.
|
||||||
"""
|
"""
|
||||||
def render(self, value):
|
def render(self, value):
|
||||||
return value.name[0].upper() + value.name[1:]
|
return content_type_name(value)
|
||||||
|
|
||||||
def value(self, value):
|
def value(self, value):
|
||||||
return f"{value.app_label}.{value.model}"
|
return f"{value.app_label}.{value.model}"
|
||||||
|
|
||||||
|
|
||||||
|
class ContentTypesColumn(tables.ManyToManyColumn):
|
||||||
|
"""
|
||||||
|
Display a list of ContentType instances.
|
||||||
|
"""
|
||||||
|
def transform(self, obj):
|
||||||
|
return content_type_name(obj)
|
||||||
|
|
||||||
|
|
||||||
class ColorColumn(tables.Column):
|
class ColorColumn(tables.Column):
|
||||||
"""
|
"""
|
||||||
Display a color (#RRGGBB).
|
Display a color (#RRGGBB).
|
||||||
|
Reference in New Issue
Block a user