12416 warning for missing script file

This commit is contained in:
Arthur 2023-05-03 14:24:49 -07:00
parent 01fa6e28cd
commit 39a74727c3
3 changed files with 51 additions and 39 deletions

View File

@ -53,7 +53,12 @@ class ScriptModule(PythonModuleMixin, JobsMixin, ManagedFile):
# For child objects in submodules use the full import path w/o the root module as the name # For child objects in submodules use the full import path w/o the root module as the name
return cls.full_name.split(".", maxsplit=1)[1] return cls.full_name.split(".", maxsplit=1)[1]
module = self.get_module() module = None
try:
module = self.get_module()
except OSError as e:
pass
scripts = {} scripts = {}
ordered = getattr(module, 'script_order', []) ordered = getattr(module, 'script_order', [])

View File

@ -1033,7 +1033,6 @@ class ScriptView(ContentTypePermissionRequiredMixin, View):
return 'extras.view_script' return 'extras.view_script'
def get(self, request, module, name): def get(self, request, module, name):
print(module)
module = get_object_or_404(ScriptModule.objects.restrict(request.user), file_path__startswith=module) module = get_object_or_404(ScriptModule.objects.restrict(request.user), file_path__startswith=module)
script = module.scripts[name]() script = module.scripts[name]()
form = script.as_form(initial=normalize_querydict(request.GET)) form = script.as_form(initial=normalize_querydict(request.GET))

View File

@ -37,43 +37,51 @@
</h5> </h5>
<div class="card-body"> <div class="card-body">
{% include 'inc/sync_warning.html' with object=module %} {% include 'inc/sync_warning.html' with object=module %}
<table class="table table-hover table-headings reports"> {% if not module.scripts %}
<thead> <div class="alert alert-warning d-flex align-items-center" role="alert">
<tr> <div>
<th width="250">Name</th> Warning: Script file at: <strong>{{ module.full_path }}"</strong> is either missing or has a problem with the script code, please check the file.
<th>Description</th> </div>
<th>Last Run</th> </div>
<th class="text-end">Status</th> {% else %}
</tr> <table class="table table-hover table-headings reports">
</thead> <thead>
<tbody> <tr>
{% with jobs=module.get_latest_jobs %} <th width="250">Name</th>
{% for script_name, script_class in module.scripts.items %} <th>Description</th>
<tr> <th>Last Run</th>
<td> <th class="text-end">Status</th>
<a href="{% url 'extras:script' module=module.python_name name=script_name %}" name="script.{{ script_name }}">{{ script_class.name }}</a> </tr>
</td> </thead>
<td> <tbody>
{{ script_class.Meta.description|markdown|placeholder }} {% with jobs=module.get_latest_jobs %}
</td> {% for script_name, script_class in module.scripts.items %}
{% with last_result=jobs|get_key:script_class.name %} <tr>
{% if last_result %} <td>
<td> <a href="{% url 'extras:script' module=module.python_name name=script_name %}" name="script.{{ script_name }}">{{ script_class.name }}</a>
<a href="{% url 'extras:script_result' job_pk=last_result.pk %}">{{ last_result.created|annotated_date }}</a> </td>
</td> <td>
<td class="text-end"> {{ script_class.Meta.description|markdown|placeholder }}
{% badge last_result.get_status_display last_result.get_status_color %} </td>
</td> {% with last_result=jobs|get_key:script_class.name %}
{% else %} {% if last_result %}
<td class="text-muted">Never</td> <td>
<td class="text-end">{{ ''|placeholder }}</td> <a href="{% url 'extras:script_result' job_pk=last_result.pk %}">{{ last_result.created|annotated_date }}</a>
{% endif %} </td>
{% endwith %} <td class="text-end">
</tr> {% badge last_result.get_status_display last_result.get_status_color %}
{% endfor %} </td>
{% endwith %} {% else %}
</tbody> <td class="text-muted">Never</td>
</table> <td class="text-end">{{ ''|placeholder }}</td>
{% endif %}
{% endwith %}
</tr>
{% endfor %}
{% endwith %}
</tbody>
</table>
{% endif %}
</div> </div>
</div> </div>
{% empty %} {% empty %}