script_list_content.html 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. {% load buttons %}
  2. {% load helpers %}
  3. {% load perms %}
  4. {% load i18n %}
  5. {# Core script list content - used by both full page and embedded views #}
  6. {% for module in script_modules %}
  7. {% include 'inc/sync_warning.html' with object=module %}
  8. <div class="card{% if embedded %} mb-3{% endif %}">
  9. {% if not embedded %}
  10. <h2 class="card-header" id="module{{ module.pk }}">
  11. <i class="mdi mdi-file-document-outline"></i> {{ module }}
  12. <div class="card-actions">
  13. {% if perms.extras.edit_scriptmodule %}
  14. <a href="{% url 'extras:scriptmodule_edit' pk=module.pk %}" class="btn btn-ghost-warning btn-sm">
  15. <i class="mdi mdi-pencil" aria-hidden="true"></i> {% trans "Edit" %}
  16. </a>
  17. {% endif %}
  18. {% if perms.extras.delete_scriptmodule %}
  19. <a href="{% url 'extras:scriptmodule_delete' pk=module.pk %}" class="btn btn-ghost-danger btn-sm">
  20. <i class="mdi mdi-trash-can-outline" aria-hidden="true"></i> {% trans "Delete" %}
  21. </a>
  22. {% endif %}
  23. </div>
  24. </h2>
  25. {% endif %}
  26. {% with scripts=module.ordered_scripts %}
  27. {% if scripts %}
  28. <table class="table table-hover scripts{% if embedded %} object-list table-sm{% endif %}">
  29. <thead>
  30. <tr>
  31. <th>{% trans "Name" %}</th>
  32. <th>{% trans "Description" %}</th>
  33. <th>{% trans "Last Run" %}</th>
  34. <th>{% trans "Status" %}</th>
  35. <th></th>
  36. </tr>
  37. </thead>
  38. <tbody>
  39. {% for script in scripts %}
  40. {% if script in available_scripts %}
  41. {% with last_job=script.get_latest_jobs|first %}
  42. <tr>
  43. <td>
  44. {% if script.is_executable %}
  45. <a href="{% url 'extras:script' script.pk %}" id="{{ script.module }}.{{ script.class_name }}">{{ script.python_class.name }}</a>
  46. {% else %}
  47. <a href="{% url 'extras:script_jobs' script.pk %}" id="{{ script.module }}.{{ script.class_name }}">{{ script.python_class.name }}</a>
  48. <span class="text-danger">
  49. <i class="mdi mdi-alert" title="{% trans "Script is no longer present in the source file" %}"></i>
  50. </span>
  51. {% endif %}
  52. </td>
  53. <td>{{ script.python_class.description|markdown|placeholder }}</td>
  54. {% if last_job %}
  55. <td>
  56. <a href="{% url 'extras:script_result' job_pk=last_job.pk %}">{{ last_job.created|isodatetime }}</a>
  57. </td>
  58. <td>
  59. {% badge last_job.get_status_display last_job.get_status_color %}
  60. </td>
  61. {% else %}
  62. <td class="text-muted">{% trans "Never" %}</td>
  63. <td>{{ ''|placeholder }}</td>
  64. {% endif %}
  65. <td>
  66. {% if request.user|can_run:script and script.is_executable %}
  67. <div class="float-end d-print-none">
  68. <form action="{% url 'extras:script' script.pk %}" method="post">
  69. {% if script.python_class.commit_default %}
  70. <input type="checkbox" name="_commit" hidden checked>
  71. {% endif %}
  72. {% csrf_token %}
  73. <button type="submit" name="_run" class="btn btn-primary{% if embedded %} btn-sm{% endif %}">
  74. {% if last_job %}
  75. <i class="mdi mdi-replay"></i> {% if not embedded %}{% trans "Run Again" %}{% endif %}
  76. {% else %}
  77. <i class="mdi mdi-play"></i> {% if not embedded %}{% trans "Run Script" %}{% endif %}
  78. {% endif %}
  79. </button>
  80. </form>
  81. </div>
  82. {% endif %}
  83. </td>
  84. </tr>
  85. {% if last_job and not embedded %}
  86. {% for test_name, data in last_job.data.tests.items %}
  87. <tr>
  88. <td colspan="4" class="method">
  89. <span class="ps-3">{{ test_name }}</span>
  90. </td>
  91. <td class="text-end text-nowrap script-stats">
  92. <span class="badge text-bg-success">{{ data.success }}</span>
  93. <span class="badge text-bg-info">{{ data.info }}</span>
  94. <span class="badge text-bg-warning">{{ data.warning }}</span>
  95. <span class="badge text-bg-danger">{{ data.failure }}</span>
  96. </td>
  97. </tr>
  98. {% endfor %}
  99. {% elif last_job and not last_job.data.log and not embedded %}
  100. {# legacy #}
  101. {% for method, stats in last_job.data.items %}
  102. <tr>
  103. <td colspan="4" class="method">
  104. <span class="ps-3">{{ method }}</span>
  105. </td>
  106. <td class="text-end text-nowrap report-stats">
  107. <span class="badge bg-success">{{ stats.success }}</span>
  108. <span class="badge bg-info">{{ stats.info }}</span>
  109. <span class="badge bg-warning">{{ stats.warning }}</span>
  110. <span class="badge bg-danger">{{ stats.failure }}</span>
  111. </td>
  112. </tr>
  113. {% endfor %}
  114. {% endif %}
  115. {% endwith %}
  116. {% endif %}
  117. {% endfor %}
  118. </tbody>
  119. </table>
  120. {% else %}
  121. <div class="card-body">
  122. <div class="alert alert-warning" role="alert">
  123. <i class="mdi mdi-alert"></i>
  124. {% blocktrans with module=module.name %}Could not load scripts from module {{ module }}{% endblocktrans %}
  125. {% if module.error %}<code>{{ module.error }}</code>{% endif %}
  126. </div>
  127. </div>
  128. {% endif %}
  129. {% endwith %}
  130. </div>
  131. {% empty %}
  132. <div class="alert alert-info" role="alert">
  133. <h4 class="alert-heading">{% trans "No Scripts Found" %}</h4>
  134. {% if perms.extras.add_scriptmodule and not embedded %}
  135. {% url 'extras:scriptmodule_add' as create_script_url %}
  136. {% blocktrans trimmed %}
  137. Get started by <a href="{{ create_script_url }}">creating a script</a> from an uploaded file or data source.
  138. {% endblocktrans %}
  139. {% endif %}
  140. </div>
  141. {% endfor %}