-
Notifications
You must be signed in to change notification settings - Fork 2
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
Models #59
Models #59
Conversation
design_builder/models.py
Outdated
"""Guarantee that the design field cannot be changed.""" | ||
super().clean() | ||
if not self._state.adding: | ||
enforce_managed_fields(self, ["job"], message="is a field that cannot be changed") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thoutght this validation should be done in the other models (e.g. Device) not here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to better understand your comment. Once a design job has been loaded by Nautobot, we should create a design model in the database. The foreign key should never change. This clean method is just a way to be careful to prevent some future runtime/semantic error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the way I read the enforce_managed_fields
was that is the method that we would use in the custom_validators of others models to make sure that there are no changes to models/attributes referenced by a Journal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that enforce_managed_fields
can be used in both places. This was my motivation for extracting it to a utility method in the first place.
design_builder/signals.py
Outdated
|
||
|
||
@receiver(nautobot_database_ready, sender=apps.get_app_config("design_builder")) | ||
def create_design_statuses(**kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if the design instance status should be Statuses or simply Choices. what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have an opinion, really, I used choices since the HLD had some clearly defined statuses. I'm okay with alternate approaches pending further discussion.
design_builder/signals.py
Outdated
|
||
|
||
@receiver(post_save, sender=Job) | ||
def create_design_model(sender, instance: Job, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the Design would be manually created, so you could have many DesignJobs, but only some of them would be added.
However, doing it automatically it's easier...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I actually never considered that designs would be manually created on an as-needed basis. I guess I was thinking that once we go down this path of versions and journaling/idempotence then it is likely that we'll want to do it for everything.
Again, I'm open to further discussion.
Implements views for: - design - design instance - journal - journal entry
Changed type hinting to indicate that django.db.models.Model is truly the base class of what we are dealing with in terms of model instances
A similar tag is provided out of the box with the Jinja2 framework so we aren't going to carry forward the `indent` support in Design Builder.
This provides some unit tests for the commit and roll back functionality provided by `ext.Extension`. This commit also introduces a small fix for the `commit` behavior.
design_builder/models.py
Outdated
|
||
old_model = model_class.objects.get(pk=new_model.pk) | ||
changed = {} | ||
for field_name in field_names: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of field comparison , can we use an "accessor key" to actually allow for changes to be done only through design builder ?
if instance.designbuilder_permitted:
del instance.designbuilder_permitted
instance.validated_save()
* feat: Connected design.Builder's journal to the new models * style: Black formatting * docs: Updated pydocs
…rset Feature delices q filterset
* feat: ✨ Change status from Design to Design Instance Remove Status from Design, Add Status to Design Instance, and also Live State. Allow delete of a Design Instance (under certain conditions), and add a button to trigger a Design execution * feat: ✨ Add a Tag for a full control object * Fix pylint * fix: Fixed cyclic import There was a cyclic import in util.py for nautobot_design_builder. There was actually no need for this import at all so it was removed. Also removed the try/except block for `importlib.metadata` since design_builder now only supports Python >= 3.8 and `metadata` was added in 3.8 * Update tests * bump version * Replace rollebacked by rolled back * Add a comment to provide context --------- Co-authored-by: Andrew Bates <[email protected]>
* Updates pyproject.toml for 3.11 * fix: Updates for OSRB documentation review fixes #78 * docs: The custom `indent` filter was removed in favor of using the builtin `indent` filter * docs: Documentation updates * docs: Removed unneeded doc template * feat: ✨ Decommissioning Job * Apply suggestions from code review Co-authored-by: Leo Kirchner <[email protected]> * Decouple pre decommission job * use callable * generalize hook * wip * wip * fix: Fixed test failures. The `TransactionTestCase` actually has less test isolation than `TestCase` which caused the test designs to not actually get reverted between tests. * refactor: JournalEntry can now be reverted. Moved the revertting code from the decommissioning job and into the JournalEntry model. Also added some tests to validate the code. * fix tests * fix dict logic * docs: Documented why refreshing `design_object` is necessary * refactor: Refactored revert code into `Journal` model * docs: Updated branding from `plugin` to `app` * refactor: Refactored decom code to model and hooks to signals Moved the design instance decommissioning code into the `DesignInstance` model. Also implemented the pre/post decom hooks as signals. * style: Autoformatting * Add l3vpn design example * fix old dict value null * refactor: Minor refactoring of `JournalEntry` revert and the model itself. * fix tests * update the l3vppn example and add a hook to validate input data * bump version * avoid overwrite of method * clean up some leftovers * Missing part of previous commit * Rename variables for consistency * fix: Fixed extra `{% endmacro %}` that got added at some point. * fix: Now logging the design instance and journal objects. * Adjust test with warning, improve logging plus journalentry retrieve view * adjust logging * mre info * fix exception chain --------- Co-authored-by: Josh VanDeraa <[email protected]> Co-authored-by: Andrew Bates <[email protected]> Co-authored-by: Leo Kirchner <[email protected]>
No description provided.