-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 🚧 Replace custom Notes by Nautobot ones (#324)
* refactor: 🚧 Replace custom Notes by Nautobot ones * add change doc * Split migrations into two files * fix migration reference name * fix: add NoteModelFormMixin, clean view, and format with ruff * recover instance check for view * merge fixes * rename maintenance path * fix for 2.0.0 * ruff * adjust migrations * Apply suggestions from code review Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com> * recover test checks and clean view --------- Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com>
- Loading branch information
1 parent
a68d46c
commit a560946
Showing
17 changed files
with
144 additions
and
447 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Replace custom Note model by the Nautobot one |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
nautobot_circuit_maintenance/migrations/0014_migrate_notes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Generated by Django 4.2.16 on 2024-09-13 08:49 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def move_data_to_new_model(apps, schema_editor): | ||
CircuitMaintenance = apps.get_model("nautobot_circuit_maintenance", "CircuitMaintenance") | ||
ContentType = apps.get_model("contenttypes", "ContentType") | ||
OldModel = apps.get_model("nautobot_circuit_maintenance", "Note") | ||
NewModel = apps.get_model("extras", "Note") | ||
|
||
for old_obj in OldModel.objects.all(): | ||
NewModel.objects.create( | ||
note=f"### {old_obj.title}\n\n{old_obj.comment}", | ||
assigned_object_type=ContentType.objects.get_for_model(CircuitMaintenance), | ||
assigned_object_id=old_obj.maintenance.id, | ||
user_name="migration", | ||
) | ||
|
||
|
||
def reverse_move_data(apps, schema_editor): | ||
OldModel = apps.get_model("nautobot_circuit_maintenance", "Note") | ||
NewModel = apps.get_model("extras", "Note") | ||
|
||
for new_obj in NewModel.objects.all(): | ||
OldModel.objects.create( | ||
title=new_obj.note[:20], # truncate to 20 | ||
content=new_obj.note, | ||
maintenance=new_obj.assigned_object, | ||
) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("nautobot_circuit_maintenance", "0013_rename_site_search_job"), | ||
("extras", "0043_note"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(move_data_to_new_model, reverse_move_data), | ||
] |
15 changes: 15 additions & 0 deletions
15
nautobot_circuit_maintenance/migrations/0015_delete_note.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Generated by Django 4.2.16 on 2024-09-13 08:49 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("nautobot_circuit_maintenance", "0014_migrate_notes"), | ||
] | ||
|
||
operations = [ | ||
migrations.DeleteModel( | ||
name="Note", | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.