mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-27 02:48:38 -06:00
Improve TableConfig validation
This commit is contained in:
parent
ea2fa5cbf1
commit
e5e548f784
@ -613,6 +613,31 @@ class TableConfig(CloningMixin, ChangeLoggedModel):
|
|||||||
items.append((col, ascending))
|
items.append((col, ascending))
|
||||||
return items
|
return items
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
super().clean()
|
||||||
|
|
||||||
|
# Validate table
|
||||||
|
if self.table_class is None:
|
||||||
|
raise ValidationError({
|
||||||
|
'table': _("Unknown table: {name}").format(name=self.table)
|
||||||
|
})
|
||||||
|
|
||||||
|
table = self.table_class([])
|
||||||
|
|
||||||
|
# Validate ordering columns
|
||||||
|
for name in self.ordering:
|
||||||
|
if name not in table.columns:
|
||||||
|
raise ValidationError({
|
||||||
|
'ordering': _('Unknown column: {name}').format(name=name)
|
||||||
|
})
|
||||||
|
|
||||||
|
# Validate selected columns
|
||||||
|
for name in self.columns:
|
||||||
|
if name not in table.columns:
|
||||||
|
raise ValidationError({
|
||||||
|
'columns': _('Unknown column: {name}').format(name=name)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
class ImageAttachment(ChangeLoggedModel):
|
class ImageAttachment(ChangeLoggedModel):
|
||||||
"""
|
"""
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block form %}
|
{% block form %}
|
||||||
{% render_errors form %}
|
|
||||||
|
|
||||||
<div class="field-group my-5">
|
<div class="field-group my-5">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<h2 class="col-9 offset-3">{% trans "Device" %}</h2>
|
<h2 class="col-9 offset-3">{% trans "Device" %}</h2>
|
||||||
@ -47,5 +45,4 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -13,7 +13,10 @@ __all__ = (
|
|||||||
|
|
||||||
def get_table_for_model(model, name=None):
|
def get_table_for_model(model, name=None):
|
||||||
name = name or f'{model.__name__}Table'
|
name = name or f'{model.__name__}Table'
|
||||||
|
try:
|
||||||
return import_string(f'{model._meta.app_label}.tables.{name}')
|
return import_string(f'{model._meta.app_label}.tables.{name}')
|
||||||
|
except ImportError:
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def get_table_ordering(request, table):
|
def get_table_ordering(request, table):
|
||||||
|
Loading…
Reference in New Issue
Block a user