mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-26 18:38: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))
|
||||
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):
|
||||
"""
|
||||
|
@ -3,8 +3,6 @@
|
||||
{% load i18n %}
|
||||
|
||||
{% block form %}
|
||||
{% render_errors form %}
|
||||
|
||||
<div class="field-group my-5">
|
||||
<div class="row">
|
||||
<h2 class="col-9 offset-3">{% trans "Device" %}</h2>
|
||||
@ -47,5 +45,4 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
@ -13,7 +13,10 @@ __all__ = (
|
||||
|
||||
def get_table_for_model(model, name=None):
|
||||
name = name or f'{model.__name__}Table'
|
||||
try:
|
||||
return import_string(f'{model._meta.app_label}.tables.{name}')
|
||||
except ImportError:
|
||||
return
|
||||
|
||||
|
||||
def get_table_ordering(request, table):
|
||||
|
Loading…
Reference in New Issue
Block a user