Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixed signal issues #58

Merged
merged 3 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions design_builder/contrib/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from nautobot.ipam.models import Prefix

import netaddr
from design_builder.design import Builder
from design_builder.design import INSTANCE_POST_SAVE, Builder
from design_builder.design import ModelInstance

from design_builder.errors import DesignImplementationError
Expand Down Expand Up @@ -462,5 +462,5 @@ def attribute(self, value, model_instance) -> None:
retval["endpoints"] = [endpoint_a, endpoint_z]
endpoint_a.attributes["peering"] = model_instance
endpoint_z.attributes["peering"] = model_instance
model_instance.connect(ModelInstance.POST_SAVE, BGPPeeringExtension._post_save)
model_instance.connect(INSTANCE_POST_SAVE, BGPPeeringExtension._post_save)
return retval
2 changes: 0 additions & 2 deletions design_builder/contrib/tests/test_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,6 @@ def test_creation(self):
design = yaml.safe_load(design_template)
object_creator = Builder(extensions=[BGPPeeringExtension])
object_creator.implement_design(design, commit=True)
for peering in Peering.objects.all():
print("Peering:", peering)
device1 = Device.objects.get(name="device1")
device2 = Device.objects.get(name="device2")

Expand Down
13 changes: 7 additions & 6 deletions design_builder/design.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ def _map_query_values(query: Mapping) -> Mapping:
return retval


# Callback Event types
INSTANCE_PRE_SAVE = Signal()
INSTANCE_POST_SAVE = Signal()


class ModelInstance: # pylint: disable=too-many-instance-attributes
"""An individual object to be created or updated as Design Builder iterates through a rendered design YAML file."""

Expand All @@ -109,10 +114,6 @@ class ModelInstance: # pylint: disable=too-many-instance-attributes

ACTION_CHOICES = [GET, CREATE, UPDATE, CREATE_OR_UPDATE]

# Callback Event types
PRE_SAVE = Signal()
POST_SAVE = Signal()

def __init__(
self, creator: "Builder", model_class: Type[BaseModel], attributes: dict, relationship_manager=None, parent=None
): # pylint:disable=too-many-arguments
Expand Down Expand Up @@ -309,7 +310,7 @@ def save(self):
# ensure that parent instances have been saved and
# assigned a primary key
self._update_fields()
ModelInstance.PRE_SAVE.send(sender=self)
INSTANCE_PRE_SAVE.send(sender=self)
try:
self.instance.full_clean()
self.instance.save()
Expand Down Expand Up @@ -338,7 +339,7 @@ def save(self):
self.instance.refresh_from_db()

field.set_value(related_object.instance)
ModelInstance.POST_SAVE.send(sender=self)
INSTANCE_POST_SAVE.send(sender=self)

def set_custom_field(self, field, value):
"""Sets a value for a custom field."""
Expand Down
Loading