mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 05:28:16 -06:00
14438 script job mapping
This commit is contained in:
parent
6930e441ae
commit
5981fc958d
@ -19,7 +19,7 @@ def update_scripts(apps, schema_editor):
|
||||
)
|
||||
|
||||
# update all jobs associated with this module/name to point to the new script obj
|
||||
module.jobs.filter(name=name).update(object_type=ct, object_id=obj.id)
|
||||
module.jobs.filter(name=script).update(object_type=ct, object_id=obj.id)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
@ -50,11 +50,6 @@ class Script(EventRulesMixin, JobsMixin, models.Model):
|
||||
def python_class(self):
|
||||
return self.module.get_module_scripts.get(self.name)
|
||||
|
||||
def get_jobs(self):
|
||||
return self.module.jobs.filter(
|
||||
name=self.name
|
||||
)
|
||||
|
||||
|
||||
class ScriptModuleManager(models.Manager.from_queryset(RestrictedQuerySet)):
|
||||
|
||||
|
@ -1209,7 +1209,7 @@ class ScriptListView(ContentTypePermissionRequiredMixin, View):
|
||||
return 'extras.view_script'
|
||||
|
||||
def get(self, request):
|
||||
script_modules = ScriptModule.objects.restrict(request.user)
|
||||
script_modules = ScriptModule.objects.restrict(request.user).prefetch_related('jobs')
|
||||
|
||||
return render(request, 'extras/script_list.html', {
|
||||
'model': ScriptModule,
|
||||
@ -1229,7 +1229,7 @@ class ScriptView(ContentTypePermissionRequiredMixin, View):
|
||||
def get(self, request, pk):
|
||||
script = Script.objects.get(pk=pk)
|
||||
script_class = script.python_class()
|
||||
jobs = script.get_jobs()
|
||||
jobs = script.jobs.all()
|
||||
form = script_class.as_form(initial=normalize_querydict(request.GET))
|
||||
|
||||
return render(request, 'extras/script.html', {
|
||||
@ -1246,7 +1246,7 @@ class ScriptView(ContentTypePermissionRequiredMixin, View):
|
||||
|
||||
script = Script.objects.get(pk=pk)
|
||||
script_class = script.python_class()
|
||||
jobs = script.get_jobs()
|
||||
jobs = script.jobs.all()
|
||||
form = script_class.as_form(request.POST, request.FILES)
|
||||
|
||||
# Allow execution only if RQ worker process is running
|
||||
@ -1256,7 +1256,7 @@ class ScriptView(ContentTypePermissionRequiredMixin, View):
|
||||
elif form.is_valid():
|
||||
job = Job.enqueue(
|
||||
run_script,
|
||||
instance=script.module,
|
||||
instance=script,
|
||||
name=script_class.class_name,
|
||||
user=request.user,
|
||||
schedule_at=form.cleaned_data.pop('_schedule_at'),
|
||||
@ -1286,7 +1286,7 @@ class ScriptSourceView(ContentTypePermissionRequiredMixin, View):
|
||||
def get(self, request, pk):
|
||||
script = Script.objects.get(pk=pk)
|
||||
script_class = script.python_class()
|
||||
jobs = script.get_jobs()
|
||||
jobs = script.jobs.all()
|
||||
|
||||
return render(request, 'extras/script/source.html', {
|
||||
'job_count': jobs.count(),
|
||||
@ -1305,7 +1305,7 @@ class ScriptJobsView(ContentTypePermissionRequiredMixin, View):
|
||||
def get(self, request, pk):
|
||||
script = Script.objects.get(pk=pk)
|
||||
script_class = script.python_class()
|
||||
jobs = script.get_jobs()
|
||||
jobs = script.jobs.all()
|
||||
|
||||
jobs_table = JobTable(
|
||||
data=jobs,
|
||||
|
@ -52,31 +52,29 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% with jobs=module.get_latest_jobs %}
|
||||
{% for script in module.scripts.all %}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{% url 'extras:script' script.id %}" name="script.{{ script.name }}">{{ script.python_class.name }}</a>
|
||||
</td>
|
||||
<td>
|
||||
{{ script.python_class.Meta.description|markdown|placeholder }}
|
||||
</td>
|
||||
{% with last_result=jobs|get_key:script.python_class.class_name %}
|
||||
{% if last_result %}
|
||||
<td>
|
||||
<a href="{% url 'extras:script_result' job_pk=last_result.pk %}">{{ last_result.created|annotated_date }}</a>
|
||||
</td>
|
||||
<td class="text-end">
|
||||
{% badge last_result.get_status_display last_result.get_status_color %}
|
||||
</td>
|
||||
{% else %}
|
||||
<td class="text-muted">{% trans "Never" %}</td>
|
||||
<td class="text-end">{{ ''|placeholder }}</td>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% for script in module.scripts.all %}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{% url 'extras:script' script.id %}" name="script.{{ script.name }}">{{ script.python_class.name }}</a>
|
||||
</td>
|
||||
<td>
|
||||
{{ script.python_class.Meta.description|markdown|placeholder }}
|
||||
</td>
|
||||
{% with last_result=script.get_latest_jobs|get_key:script.name %}
|
||||
{% if last_result %}
|
||||
<td>
|
||||
<a href="{% url 'extras:script_result' job_pk=last_result.pk %}">{{ last_result.created|annotated_date }}</a>
|
||||
</td>
|
||||
<td class="text-end">
|
||||
{% badge last_result.get_status_display last_result.get_status_color %}
|
||||
</td>
|
||||
{% else %}
|
||||
<td class="text-muted">{% trans "Never" %}</td>
|
||||
<td class="text-end">{{ ''|placeholder }}</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
|
Loading…
Reference in New Issue
Block a user