diff --git a/wagtail/wagtailadmin/tasks.py b/wagtail/wagtailadmin/tasks.py index 701bd328bb..503ff1eedd 100644 --- a/wagtail/wagtailadmin/tasks.py +++ b/wagtail/wagtailadmin/tasks.py @@ -1,5 +1,3 @@ -from celery.decorators import task - from django.template.loader import render_to_string from django.core.mail import send_mail from django.conf import settings @@ -8,6 +6,27 @@ from django.db.models import Q from wagtail.wagtailcore.models import PageRevision, GroupPagePermission +# The following will check to see if we can import task from celery - +# if not then we definitely haven't installed it +try: + from celery.decorators import task + NO_CELERY = False +except: + NO_CELERY = True + + +# However, we could have installed celery for other projects. So we will also +# check if we have defined the BROKER_URL setting. If not then definitely we +# haven't configured it. +if NO_CELERY or not hasattr(settings, 'BROKER_URL'): + # So if we enter here we will define a different "task" decorator that + # just returns the original function and sets its delay attribute to + # point to the original function: This way, the send_notification + # function will be actually called instead of the the + # send_notification.delay() + def task(f): + f.delay=f + return f def users_with_page_permission(page, permission_type, include_superusers=True): # Get user model @@ -25,11 +44,11 @@ def users_with_page_permission(page, permission_type, include_superusers=True): return User.objects.filter(q).distinct() -@task() +@task def send_notification(page_revision_id, notification, excluded_user_id): # Get revision revision = PageRevision.objects.get(id=page_revision_id) - + # Get list of recipients if notification == 'submitted': # Get list of publishers