Skip to content

Commit

Permalink
Add support for filtering by a classname longer than twenty character…
Browse files Browse the repository at this point in the history
…s 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]>
  • Loading branch information
igpaec and Israel Pineda authored Oct 29, 2024
1 parent ee9f183 commit 3b1bf7d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
1 change: 1 addition & 0 deletions changes/183.added
Original file line number Diff line number Diff line change
@@ -0,0 +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.
10 changes: 8 additions & 2 deletions nautobot_data_validation_engine/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

from django import forms
from django.contrib.contenttypes.models import ContentType

try:
from nautobot.apps.constants import CHARFIELD_MAX_LENGTH
except ImportError:
CHARFIELD_MAX_LENGTH = 255
from nautobot.core.forms import (
BootstrapMixin,
BulkEditNullBooleanSelect,
CSVMultipleContentTypeField,
DynamicModelChoiceField,
DynamicModelMultipleChoiceField,
MultipleContentTypeField,
MultiValueCharField,
StaticSelect2,
TagFilterField,
)
Expand Down Expand Up @@ -297,8 +303,8 @@ class DataComplianceFilterForm(BootstrapMixin, forms.Form):
"""Form for DataCompliance instances."""

model = DataCompliance
compliance_class_name = forms.CharField(max_length=20, required=False)
validated_attribute = forms.CharField(max_length=20, required=False)
compliance_class_name = MultiValueCharField(max_length=CHARFIELD_MAX_LENGTH, required=False)
validated_attribute = MultiValueCharField(max_length=CHARFIELD_MAX_LENGTH, required=False)
valid = forms.NullBooleanField(required=False, widget=StaticSelect2(choices=BOOLEAN_WITH_BLANK_CHOICES))
content_type = MultipleContentTypeField(
feature=None,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated by Django 4.2.16 on 2024-10-23 20:57

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("nautobot_data_validation_engine", "0006_add_field_defaults"),
]

operations = [
migrations.AlterField(
model_name="datacompliance",
name="compliance_class_name",
field=models.CharField(max_length=255),
),
migrations.AlterField(
model_name="datacompliance",
name="object_id",
field=models.CharField(max_length=255),
),
migrations.AlterField(
model_name="datacompliance",
name="validated_attribute",
field=models.CharField(blank=True, default="", max_length=255),
),
migrations.AlterField(
model_name="datacompliance",
name="validated_attribute_value",
field=models.CharField(blank=True, default="", max_length=255),
),
migrations.AlterField(
model_name="datacompliance",
name="validated_object_str",
field=models.CharField(blank=True, default="", max_length=255),
),
]
15 changes: 10 additions & 5 deletions nautobot_data_validation_engine/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
from django.core.validators import MinValueValidator, ValidationError
from django.db import models
from django.shortcuts import reverse

try:
from nautobot.apps.constants import CHARFIELD_MAX_LENGTH
except ImportError:
CHARFIELD_MAX_LENGTH = 255
from nautobot.core.models.generics import PrimaryModel
from nautobot.core.models.querysets import RestrictedQuerySet
from nautobot.extras.utils import FeatureQuery, extras_features
Expand Down Expand Up @@ -318,14 +323,14 @@ def clean(self):
class DataCompliance(PrimaryModel):
"""Model to represent the results of an audit method."""

compliance_class_name = models.CharField(max_length=100, blank=False, null=False)
compliance_class_name = models.CharField(max_length=CHARFIELD_MAX_LENGTH, blank=False, null=False)
last_validation_date = models.DateTimeField(blank=False, null=False, auto_now=True)
content_type = models.ForeignKey(ContentType, on_delete=models.PROTECT, blank=False, null=False)
object_id = models.CharField(max_length=200, blank=False, null=False)
object_id = models.CharField(max_length=CHARFIELD_MAX_LENGTH, blank=False, null=False)
validated_object = GenericForeignKey("content_type", "object_id")
validated_object_str = models.CharField(max_length=200, blank=True, default="")
validated_attribute = models.CharField(max_length=100, blank=True, default="")
validated_attribute_value = models.CharField(max_length=200, blank=True, default="")
validated_object_str = models.CharField(max_length=CHARFIELD_MAX_LENGTH, blank=True, default="")
validated_attribute = models.CharField(max_length=CHARFIELD_MAX_LENGTH, blank=True, default="")
validated_attribute_value = models.CharField(max_length=CHARFIELD_MAX_LENGTH, blank=True, default="")
valid = models.BooleanField(blank=False, null=False)
message = models.TextField(blank=True, default="")

Expand Down

0 comments on commit 3b1bf7d

Please sign in to comment.