mirror of https://github.com/interlegis/sigi.git
Sesóstris Vieira
11 months ago
9 changed files with 87 additions and 7 deletions
@ -0,0 +1,10 @@ |
|||||
|
from django.urls import path, include |
||||
|
from sigi.apps.utils import views |
||||
|
|
||||
|
urlpatterns = [ |
||||
|
path( |
||||
|
"runjob/<str:job_name>/", |
||||
|
views.user_run_job, |
||||
|
name="utils_runjob", |
||||
|
), |
||||
|
] |
@ -0,0 +1,18 @@ |
|||||
|
{% extends "admin/base_site.html" %} |
||||
|
{% load static i18n %} |
||||
|
|
||||
|
{% block extrastyle %} |
||||
|
{{ block.super }} |
||||
|
<style type="text/css"> |
||||
|
h1 { |
||||
|
font-size: 2.5rem; |
||||
|
} |
||||
|
h2 { |
||||
|
font-size: 2rem; |
||||
|
} |
||||
|
h3 { |
||||
|
font-size: 1.5rem; |
||||
|
} |
||||
|
</style> |
||||
|
{% endblock %} |
||||
|
{% block content %}{{ content|safe }}{% endblock %} |
@ -0,0 +1,23 @@ |
|||||
|
from parsel import Selector |
||||
|
from django.contrib.auth.decorators import user_passes_test |
||||
|
from django.contrib.auth.decorators import login_required |
||||
|
from django.shortcuts import render |
||||
|
from django.utils import timezone |
||||
|
from django_extensions.management.jobs import get_job |
||||
|
|
||||
|
|
||||
|
@login_required |
||||
|
@user_passes_test(lambda user: user.is_superuser) |
||||
|
def user_run_job(request, job_name): |
||||
|
job = get_job(None, job_name)() |
||||
|
start_time = timezone.localtime() |
||||
|
job.do_job() |
||||
|
end_time = timezone.localtime() |
||||
|
rst, html = job.prepare_report(start_time, end_time) |
||||
|
dp = Selector(text=html) |
||||
|
|
||||
|
return render( |
||||
|
request, |
||||
|
"admin/jobs/job_result.html", |
||||
|
{"content": dp.xpath("//body/*").get()}, |
||||
|
) |
Loading…
Reference in new issue