script_list_content.html 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. {% with last_job=script.get_latest_jobs|first %}
  41. <tr>
  42. <td>
  43. {% if script.is_executable %}
  44. <a href="{% url 'extras:script' script.pk %}" id="{{ script.module }}.{{ script.class_name }}">{{ script.python_class.name }}</a>
  45. {% else %}
  46. <a href="{% url 'extras:script_jobs' script.pk %}" id="{{ script.module }}.{{ script.class_name }}">{{ script.python_class.name }}</a>
  47. <span class="text-danger">
  48. <i class="mdi mdi-alert" title="{% trans "Script is no longer present in the source file" %}"></i>
  49. </span>
  50. {% endif %}
  51. </td>
  52. <td>{{ script.python_class.description|markdown|placeholder }}</td>
  53. {% if last_job %}
  54. <td>
  55. <a href="{% url 'extras:script_result' job_pk=last_job.pk %}">{{ last_job.created|isodatetime }}</a>
  56. </td>
  57. <td>
  58. {% badge last_job.get_status_display last_job.get_status_color %}
  59. </td>
  60. {% else %}
  61. <td class="text-muted">{% trans "Never" %}</td>
  62. <td>{{ ''|placeholder }}</td>
  63. {% endif %}
  64. <td>
  65. {% if request.user|can_run:script and script.is_executable %}
  66. <div class="float-end d-print-none">
  67. <form action="{% url 'extras:script' script.pk %}" method="post">
  68. {% if script.python_class.commit_default %}
  69. <input type="checkbox" name="_commit" hidden checked>
  70. {% endif %}
  71. {% csrf_token %}
  72. <button type="submit" name="_run" class="btn btn-primary{% if embedded %} btn-sm{% endif %}">
  73. {% if last_job %}
  74. <i class="mdi mdi-replay"></i> {% if not embedded %}{% trans "Run Again" %}{% endif %}
  75. {% else %}
  76. <i class="mdi mdi-play"></i> {% if not embedded %}{% trans "Run Script" %}{% endif %}
  77. {% endif %}
  78. </button>
  79. </form>
  80. </div>
  81. {% endif %}
  82. </td>
  83. </tr>
  84. {% if last_job and not embedded %}
  85. {% for test_name, data in last_job.data.tests.items %}
  86. <tr>
  87. <td colspan="4" class="method">
  88. <span class="ps-3">{{ test_name }}</span>
  89. </td>
  90. <td class="text-end text-nowrap script-stats">
  91. <span class="badge text-bg-success">{{ data.success }}</span>
  92. <span class="badge text-bg-info">{{ data.info }}</span>
  93. <span class="badge text-bg-warning">{{ data.warning }}</span>
  94. <span class="badge text-bg-danger">{{ data.failure }}</span>
  95. </td>
  96. </tr>
  97. {% endfor %}
  98. {% elif last_job and not last_job.data.log and not embedded %}
  99. {# legacy #}
  100. {% for method, stats in last_job.data.items %}
  101. <tr>
  102. <td colspan="4" class="method">
  103. <span class="ps-3">{{ method }}</span>
  104. </td>
  105. <td class="text-end text-nowrap report-stats">
  106. <span class="badge bg-success">{{ stats.success }}</span>
  107. <span class="badge bg-info">{{ stats.info }}</span>
  108. <span class="badge bg-warning">{{ stats.warning }}</span>
  109. <span class="badge bg-danger">{{ stats.failure }}</span>
  110. </td>
  111. </tr>
  112. {% endfor %}
  113. {% endif %}
  114. {% endwith %}
  115. {% endfor %}
  116. </tbody>
  117. </table>
  118. {% else %}
  119. <div class="card-body">
  120. <div class="alert alert-warning" role="alert">
  121. <i class="mdi mdi-alert"></i>
  122. {% blocktrans with module=module.name %}Could not load scripts from module {{ module }}{% endblocktrans %}
  123. </div>
  124. </div>
  125. {% endif %}
  126. {% endwith %}
  127. </div>
  128. {% empty %}
  129. <div class="alert alert-info" role="alert">
  130. <h4 class="alert-heading">{% trans "No Scripts Found" %}</h4>
  131. {% if perms.extras.add_scriptmodule and not embedded %}
  132. {% url 'extras:scriptmodule_add' as create_script_url %}
  133. {% blocktrans trimmed %}
  134. Get started by <a href="{{ create_script_url }}">creating a script</a> from an uploaded file or data source.
  135. {% endblocktrans %}
  136. {% endif %}
  137. </div>
  138. {% endfor %}