Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add args & kwargs capabilities into admin.py #7

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

shadeimi
Copy link

from celery.execute import send_task
from django.contrib import admin
from djcelery import admin as djcelery_admin
from djcelery.models import PeriodicTask
import json

class ExtendedPeriodicTaskAdmin(djcelery_admin.PeriodicTaskAdmin):
actions = djcelery_admin.PeriodicTaskAdmin.actions + ['run_task']

def run_task(self, request, queryset):
    if request.user.is_admin:
        for task in queryset.all():
            send_task(task.task, args=json.loads(task.args), kwargs=json.loads(task.kwargs))
        self.message = 'Tasks are running'
    else:
        self.message = 'You must be an admin to perform this action.'
run_task.short_description = 'Run Task'

admin.site.unregister(PeriodicTask)
admin.site.register(PeriodicTask, ExtendedPeriodicTaskAdmin)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants