138
app/core/templates/celery_log.html.j2
Normal file
138
app/core/templates/celery_log.html.j2
Normal file
@ -0,0 +1,138 @@
|
||||
{% extends 'base.html.j2' %}
|
||||
|
||||
{% load json %}
|
||||
{% load markdown %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<script>
|
||||
|
||||
function openCity(evt, cityName) {
|
||||
// Declare all variables
|
||||
var i, tabcontent, tablinks;
|
||||
|
||||
// Get all elements with class="tabcontent" and hide them
|
||||
tabcontent = document.getElementsByClassName("tabcontent");
|
||||
for (i = 0; i < tabcontent.length; i++) {
|
||||
tabcontent[i].style.display = "none";
|
||||
}
|
||||
|
||||
// Get all elements with class="tablinks" and remove the class "active"
|
||||
tablinks = document.getElementsByClassName("tablinks");
|
||||
for (i = 0; i < tablinks.length; i++) {
|
||||
tablinks[i].className = tablinks[i].className.replace(" active", "");
|
||||
}
|
||||
|
||||
// Show the current tab, and add an "active" class to the button that opened the tab
|
||||
document.getElementById(cityName).style.display = "block";
|
||||
evt.currentTarget.className += " active";
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<div class="tab">
|
||||
<button onclick="window.location='{% url 'Settings:_task_results' %}';"
|
||||
style="vertical-align: middle; padding: auto; margin: 0px">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="25px" viewBox="0 -960 960 960" width="25px"
|
||||
style="vertical-align: middle; margin: 0px; padding: 0px border: none; " fill="#6a6e73">
|
||||
<path d="m313-480 155 156q11 11 11.5 27.5T468-268q-11 11-28 11t-28-11L228-452q-6-6-8.5-13t-2.5-15q0-8 2.5-15t8.5-13l184-184q11-11 27.5-11.5T468-692q11 11 11 28t-11 28L313-480Zm264 0 155 156q11 11 11.5 27.5T732-268q-11 11-28 11t-28-11L492-452q-6-6-8.5-13t-2.5-15q0-8 2.5-15t8.5-13l184-184q11-11 27.5-11.5T732-692q11 11 11 28t-11 28L577-480Z" />
|
||||
</svg> Back to Task Results</button>
|
||||
<button id="defaultOpen" class="tablinks" onclick="openCity(event, 'Details')">Details</button>
|
||||
<!-- <button class="tablinks" onclick="openCity(event, 'Installations')">Installations</button> -->
|
||||
</div>
|
||||
<style>
|
||||
|
||||
.detail-view-field {
|
||||
display:unset;
|
||||
height: 30px;
|
||||
line-height: 30px;
|
||||
padding: 0px 20px 40px 20px;
|
||||
|
||||
}
|
||||
|
||||
.detail-view-field label {
|
||||
display: inline-block;
|
||||
font-weight: bold;
|
||||
width: 200px;
|
||||
margin: 10px;
|
||||
/*padding: 10px;*/
|
||||
height: 30px;
|
||||
line-height: 30px;
|
||||
|
||||
}
|
||||
|
||||
.detail-view-field span {
|
||||
display: inline-block;
|
||||
width: 340px;
|
||||
margin: 10px;
|
||||
/*padding: 10px;*/
|
||||
border-bottom: 1px solid #ccc;
|
||||
height: 30px;
|
||||
line-height: 30px;
|
||||
|
||||
}
|
||||
</style>
|
||||
|
||||
<div id="Details" class="tabcontent">
|
||||
|
||||
<h3>Details </h3>
|
||||
|
||||
<div style="align-items:flex-start; align-content: center; display: flexbox; width: 100%">
|
||||
|
||||
<div style="display: inline; width: 40%; margin: 30px;">
|
||||
|
||||
<div class="detail-view-field">
|
||||
<label>{{ form.task_id.label }}</label>
|
||||
<span>{{ form.task_id.value }}</span>
|
||||
</div>
|
||||
|
||||
<div class="detail-view-field">
|
||||
<label>{{ form.task_name.label }}</label>
|
||||
<span>{{ form.task_name.value }}</span>
|
||||
</div>
|
||||
|
||||
<div class="detail-view-field">
|
||||
<label>{{ form.status.label }}</label>
|
||||
<span>{{ form.status.value }}</span>
|
||||
</div>
|
||||
|
||||
<div class="detail-view-field">
|
||||
<label>Created</label>
|
||||
<span>{{ task_result.date_created }}</span>
|
||||
</div>
|
||||
|
||||
<div class="detail-view-field">
|
||||
<label>Finished</label>
|
||||
<span>{{ task_result.date_done }}</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div style="display: inline; width: 40%; margin: 30px; text-align: left;">
|
||||
<div>
|
||||
<label style="font-weight: bold; width: 100%; border-bottom: 1px solid #ccc; display: block; text-align: inherit;">{{ form.task_args.label }}</label>
|
||||
|
||||
<div style="display: inline-block; text-align: left;">{{ form.task_args.value }}</div>
|
||||
|
||||
</div>
|
||||
<br />
|
||||
<div>
|
||||
<label style="font-weight: bold; width: 100%; border-bottom: 1px solid #ccc; display: block; text-align: inherit;">Result</label>
|
||||
|
||||
<div style="display: inline-block; text-align: left;"><pre style="text-align: left; max-width: 300px;">{{ task_result.result | json_pretty }}</pre></div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
// Get the element with id="defaultOpen" and click on it
|
||||
document.getElementById("defaultOpen").click();
|
||||
</script>
|
||||
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
25
app/core/templates/celery_log_index.html.j2
Normal file
25
app/core/templates/celery_log_index.html.j2
Normal file
@ -0,0 +1,25 @@
|
||||
{% extends 'base.html.j2' %}
|
||||
|
||||
{% block content %}
|
||||
<input type="button" value="<< Back to settings" onclick="window.location='{% url 'Settings:Settings' %}';">
|
||||
|
||||
<table style="max-width: 100%;">
|
||||
<thead>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th>Status</th>
|
||||
<th>Created</th>
|
||||
<th>Completed</th>
|
||||
</thead>
|
||||
{% for entry in task_results %}
|
||||
<tr class="clicker">
|
||||
<td><a href="{% url 'Settings:_task_result_view' pk=entry.id %}">{{ entry.task_id }}</a></td>
|
||||
<td>{{ entry.task_name }}</td>
|
||||
<td>{{ entry.status }}</td>
|
||||
<td>{{ entry.date_created }}</td>
|
||||
<td>{{ entry.date_done }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
{% endblock %}
|
74
app/core/views/celery_log.py
Normal file
74
app/core/views/celery_log.py
Normal file
@ -0,0 +1,74 @@
|
||||
import markdown
|
||||
|
||||
from django.views import generic
|
||||
|
||||
from access.mixin import OrganizationPermission
|
||||
|
||||
from django_celery_results.models import TaskResult
|
||||
|
||||
|
||||
|
||||
class Index(OrganizationPermission, generic.ListView):
|
||||
|
||||
context_object_name = "task_results"
|
||||
|
||||
fields = [
|
||||
"task_id",
|
||||
'task_name',
|
||||
'status',
|
||||
'date_created',
|
||||
'date_done',
|
||||
]
|
||||
|
||||
model = TaskResult
|
||||
|
||||
permission_required = [
|
||||
'django_celery_results.view_taskresult',
|
||||
]
|
||||
|
||||
template_name = 'celery_log_index.html.j2'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
context['content_title'] = 'Background Task Results'
|
||||
|
||||
return context
|
||||
|
||||
|
||||
def get_success_url(self, **kwargs):
|
||||
|
||||
return reverse('Settings:_device_model_view', args=(self.kwargs['pk'],))
|
||||
|
||||
|
||||
|
||||
class View(OrganizationPermission, generic.UpdateView):
|
||||
|
||||
context_object_name = "task_result"
|
||||
|
||||
fields = [
|
||||
"task_id",
|
||||
'task_name',
|
||||
'status',
|
||||
'task_args',
|
||||
]
|
||||
|
||||
model = TaskResult
|
||||
|
||||
permission_required = [
|
||||
'django_celery_results.view_taskresult',
|
||||
]
|
||||
|
||||
template_name = 'celery_log.html.j2'
|
||||
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
context['content_title'] = f"Task {self.object.task_id}"
|
||||
|
||||
return context
|
||||
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
pass
|
@ -39,6 +39,7 @@ div#content article h3 {
|
||||
<h3>Application</h3>
|
||||
<ul>
|
||||
<li><a href="{% url 'Settings:_settings_application' %}">Settings</a></li>
|
||||
<li><a href="{% url 'Settings:_task_results' %}">Task Logs</a></li>
|
||||
</ul>
|
||||
</article>
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
from django.urls import path
|
||||
|
||||
from core.views import celery_log
|
||||
|
||||
from .views import app_settings, home, device_models, device_types, manufacturer, software_categories
|
||||
|
||||
from itam.views import device_type, device_model, software_category
|
||||
@ -11,6 +13,8 @@ urlpatterns = [
|
||||
|
||||
path('application', app_settings.View.as_view(), name="_settings_application"),
|
||||
|
||||
path("task_results", celery_log.Index.as_view(), name="_task_results"),
|
||||
path("task_result/<int:pk>", celery_log.View.as_view(), name="_task_result_view"),
|
||||
|
||||
path("device_models", device_models.Index.as_view(), name="_device_models"),
|
||||
path("device_model/<int:pk>", device_model.View.as_view(), name="_device_model_view"),
|
||||
|
Reference in New Issue
Block a user