Skip to content

Commit 694ac01

Browse files
committed
Allow editing of class_name and module_path on ScriptInstance
1 parent 6e72f42 commit 694ac01

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,8 @@
6464

6565
# 0.3.11
6666

67-
* Omit logging empty strings. Prevents exception when logging a blank value or None.
67+
* Omit logging empty strings. Prevents exception when logging a blank value or None.
68+
69+
# 0.4.0
70+
71+
* Allow editing of class_name and module_path on ScriptInstance to allow the preservation of ScriptExecutions if the script is moved/renamed.

netbox_script_manager/api/serializers.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class ScriptInstanceSerializer(NetBoxModelSerializer):
3636
tenant = NestedTenantSerializer(required=False, allow_null=True)
3737

3838
class Meta:
39-
read_only_fields = ["module_path", "class_name"]
4039
model = ScriptInstance
4140
fields = (
4241
"id",
@@ -60,7 +59,6 @@ class NestedScriptInstanceSerializer(NetBoxModelSerializer):
6059
name = serializers.CharField(required=True)
6160

6261
class Meta:
63-
read_only_fields = ["module_path", "class_name"]
6462
model = ScriptInstance
6563
fields = (
6664
"id",

netbox_script_manager/forms.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,18 @@ class ScriptInstanceForm(NetBoxModelForm):
2323
"group_id": "$tenant_group",
2424
},
2525
)
26+
module_path = forms.CharField(
27+
required=True,
28+
help_text="The path to the python module. Can be changed if the script has been moved.",
29+
)
30+
class_name = forms.CharField(
31+
required=True,
32+
help_text="The name of the CustomScript class. Can be changed if the script class has been renamed.",
33+
)
2634

2735
class Meta:
2836
model = ScriptInstance
29-
fields = ("name", "group", "weight", "description", "task_queues", "comments", "tenant", "tags")
37+
fields = ("name", "module_path", "class_name", "group", "weight", "description", "task_queues", "comments", "tenant", "tags")
3038

3139
widgets = {
3240
"description": forms.Textarea(attrs={"rows": 3}),

netbox_script_manager/templates/netbox_script_manager/scriptinstance.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ <h5 class="card-header">Script Instance</h5>
7676
<th scope="row">Name</th>
7777
<td>{{ object.name }}</td>
7878
</tr>
79+
<tr>
80+
<th scope="row">Module Path</th>
81+
<td>{{ object.module_path }}</td>
82+
</tr>
83+
<tr>
84+
<th scope="row">Class Name</th>
85+
<td>{{ object.class_name }}</td>
86+
</tr>
7987
<tr>
8088
<th scope="row">Description</th>
8189
<td>{{ object.description|placeholder }}</td>

0 commit comments

Comments
 (0)