Skip to content

Commit 3b1bf7d

Browse files
igpaecIsrael Pineda
andauthored
Add support for filtering by a classname longer than twenty characters and multiple classnames (#187)
* Add support for filtering by classname longer than twenty characters * Standarize all the CharFields of the model to the same max length * Fix form field type * Fix formatting * Catch ImportErrors on new functionality * Fix format on import --------- Co-authored-by: Israel Pineda <[email protected]>
1 parent ee9f183 commit 3b1bf7d

File tree

4 files changed

+56
-7
lines changed

4 files changed

+56
-7
lines changed

changes/183.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added support for filtering by Compliance Class Name with a name longer than twenty characters and to filter by multiple names at the same time.

nautobot_data_validation_engine/forms.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22

33
from django import forms
44
from django.contrib.contenttypes.models import ContentType
5+
6+
try:
7+
from nautobot.apps.constants import CHARFIELD_MAX_LENGTH
8+
except ImportError:
9+
CHARFIELD_MAX_LENGTH = 255
510
from nautobot.core.forms import (
611
BootstrapMixin,
712
BulkEditNullBooleanSelect,
813
CSVMultipleContentTypeField,
914
DynamicModelChoiceField,
1015
DynamicModelMultipleChoiceField,
1116
MultipleContentTypeField,
17+
MultiValueCharField,
1218
StaticSelect2,
1319
TagFilterField,
1420
)
@@ -297,8 +303,8 @@ class DataComplianceFilterForm(BootstrapMixin, forms.Form):
297303
"""Form for DataCompliance instances."""
298304

299305
model = DataCompliance
300-
compliance_class_name = forms.CharField(max_length=20, required=False)
301-
validated_attribute = forms.CharField(max_length=20, required=False)
306+
compliance_class_name = MultiValueCharField(max_length=CHARFIELD_MAX_LENGTH, required=False)
307+
validated_attribute = MultiValueCharField(max_length=CHARFIELD_MAX_LENGTH, required=False)
302308
valid = forms.NullBooleanField(required=False, widget=StaticSelect2(choices=BOOLEAN_WITH_BLANK_CHOICES))
303309
content_type = MultipleContentTypeField(
304310
feature=None,
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Generated by Django 4.2.16 on 2024-10-23 20:57
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("nautobot_data_validation_engine", "0006_add_field_defaults"),
9+
]
10+
11+
operations = [
12+
migrations.AlterField(
13+
model_name="datacompliance",
14+
name="compliance_class_name",
15+
field=models.CharField(max_length=255),
16+
),
17+
migrations.AlterField(
18+
model_name="datacompliance",
19+
name="object_id",
20+
field=models.CharField(max_length=255),
21+
),
22+
migrations.AlterField(
23+
model_name="datacompliance",
24+
name="validated_attribute",
25+
field=models.CharField(blank=True, default="", max_length=255),
26+
),
27+
migrations.AlterField(
28+
model_name="datacompliance",
29+
name="validated_attribute_value",
30+
field=models.CharField(blank=True, default="", max_length=255),
31+
),
32+
migrations.AlterField(
33+
model_name="datacompliance",
34+
name="validated_object_str",
35+
field=models.CharField(blank=True, default="", max_length=255),
36+
),
37+
]

nautobot_data_validation_engine/models.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
from django.core.validators import MinValueValidator, ValidationError
88
from django.db import models
99
from django.shortcuts import reverse
10+
11+
try:
12+
from nautobot.apps.constants import CHARFIELD_MAX_LENGTH
13+
except ImportError:
14+
CHARFIELD_MAX_LENGTH = 255
1015
from nautobot.core.models.generics import PrimaryModel
1116
from nautobot.core.models.querysets import RestrictedQuerySet
1217
from nautobot.extras.utils import FeatureQuery, extras_features
@@ -318,14 +323,14 @@ def clean(self):
318323
class DataCompliance(PrimaryModel):
319324
"""Model to represent the results of an audit method."""
320325

321-
compliance_class_name = models.CharField(max_length=100, blank=False, null=False)
326+
compliance_class_name = models.CharField(max_length=CHARFIELD_MAX_LENGTH, blank=False, null=False)
322327
last_validation_date = models.DateTimeField(blank=False, null=False, auto_now=True)
323328
content_type = models.ForeignKey(ContentType, on_delete=models.PROTECT, blank=False, null=False)
324-
object_id = models.CharField(max_length=200, blank=False, null=False)
329+
object_id = models.CharField(max_length=CHARFIELD_MAX_LENGTH, blank=False, null=False)
325330
validated_object = GenericForeignKey("content_type", "object_id")
326-
validated_object_str = models.CharField(max_length=200, blank=True, default="")
327-
validated_attribute = models.CharField(max_length=100, blank=True, default="")
328-
validated_attribute_value = models.CharField(max_length=200, blank=True, default="")
331+
validated_object_str = models.CharField(max_length=CHARFIELD_MAX_LENGTH, blank=True, default="")
332+
validated_attribute = models.CharField(max_length=CHARFIELD_MAX_LENGTH, blank=True, default="")
333+
validated_attribute_value = models.CharField(max_length=CHARFIELD_MAX_LENGTH, blank=True, default="")
329334
valid = models.BooleanField(blank=False, null=False)
330335
message = models.TextField(blank=True, default="")
331336

0 commit comments

Comments
 (0)