Link job to user.

parent 67243b85
......@@ -4,8 +4,8 @@ from .models import Job
class JobAdmin(admin.ModelAdmin):
list_display = ('name', 'result_id', 'status', 'created_on', 'finished_on')
list_filter = ('result', )
list_display = ('name', 'result_id', 'status', 'created_by', 'created_on', 'finished_on')
list_filter = ('status', 'created_by')
readonly_fields = ('name', 'task', 'result_id', 'result', 'status', 'created_on', 'finished_on')
......
......@@ -3,6 +3,7 @@
import datetime
from django.contrib.auth.models import User
from django.db import models
from jsonfield import JSONField
......@@ -21,12 +22,15 @@ class Job(models.Model):
created_on = models.DateTimeField(auto_now_add=True, blank=True, null=True, help_text="when task was created")
finished_on = models.DateTimeField(blank=True, null=True, help_text="when task ended")
created_by = models.ForeignKey(User, blank=True, null=True)
@classmethod
def create(cls, task, name, *args, **kwargs):
def create(cls, task, name, request, *args, **kwargs):
"""Create job object and publish task on celery queue."""
# create database object
job = cls(task=str(task))
if request:
job.created_by = request.user
job.save()
# publish original task which stores the result in this Job object
......
......@@ -159,7 +159,7 @@ class UrlAdmin(admin.ModelAdmin):
urls = list(queryset)
task = security_headers_scan_urls(urls=urls, execute=False)
name = "Scan Security Headers (%s) " % str(urls)
job = Job.create(task, name)
job = Job.create(task, name, request)
self.message_user(request, "%s: job created, id:%s" % (name, str(job)))
security_headers.short_description = "Scan Security Headers"
actions.append('security_headers')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment