From 2c8a71eaa09e46d9c17b92c6673b31783eba9266 Mon Sep 17 00:00:00 2001 From: Dmitriy Shesterkin Date: Fri, 28 Apr 2017 02:14:48 +0300 Subject: [PATCH] fix celery --- project/__init__.py | 12 +++++++----- project/celery.py | 28 ++++++++++++++-------------- project/myauth/emails.py | 8 ++++---- project/settings.py | 12 ++++++------ project/urls.py | 11 ++++++----- 5 files changed, 37 insertions(+), 34 deletions(-) diff --git a/project/__init__.py b/project/__init__.py index 7124615..3b91b07 100644 --- a/project/__init__.py +++ b/project/__init__.py @@ -1,5 +1,7 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import -# from .celery import app as celery_app -# -# __all__ = ['celery_app'] \ No newline at end of file +from __future__ import absolute_import, unicode_literals + +# This will make sure the app is always imported when +# Django starts so that shared_task will use this app. +from .celery import app as celery_app + +__all__ = ['celery_app'] diff --git a/project/celery.py b/project/celery.py index 02beb9b..1e9d489 100644 --- a/project/celery.py +++ b/project/celery.py @@ -1,23 +1,23 @@ -# -*- coding: utf-8 -*- from __future__ import absolute_import, unicode_literals import os - -import celery -print celery.__file__ -# from celery import Celery -from django.conf import settings +from celery import Celery # set the default Django settings module for the 'celery' program. os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings') -# app = Celery('proj') +app = Celery('project') + +# Using a string here means the worker doesn't have to serialize +# the configuration object to child processes. +# - namespace='CELERY' means all celery-related configuration keys +# should have a `CELERY_` prefix. +app.config_from_object('django.conf:settings', namespace='CELERY') + +# Load task modules from all registered Django app configs. +app.autodiscover_tasks() -# Using a string here means the worker will not have to -# pickle the object when using Windows. -# app.config_from_object('django.conf:settings') -# app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) +@app.task(bind=True) +def debug_task(self): + print('Request: {0!r}'.format(self.request)) -# @app.task(bind=True) -# def debug_task(self): -# print('Request: {0!r}'.format(self.request)) \ No newline at end of file diff --git a/project/myauth/emails.py b/project/myauth/emails.py index e64de77..b15c2cd 100644 --- a/project/myauth/emails.py +++ b/project/myauth/emails.py @@ -2,13 +2,13 @@ from django.template.loader import render_to_string from django.core.mail import EmailMessage from django.conf import settings -# from celery import shared_task +from celery.task import task SUPPORT_EMAIL = getattr(settings, 'SUPPORT_EMAIL', '') -# @shared_task +@task def send_registration_email(user_email, confirm_url): """Отправить письмо о регистрации нового пользователя.""" template_name = 'myauth/registration_email.txt' @@ -19,7 +19,7 @@ def send_registration_email(user_email, confirm_url): return email.send() -# @shared_task +@task def send_reset_password_email(user_email, confirm_url): """Отправить письмо с ключём для восстановления пароля.""" template_name = 'myauth/reset_key_email.txt' @@ -30,7 +30,7 @@ def send_reset_password_email(user_email, confirm_url): return email.send() -# @shared_task +@task def send_new_password_email(user_email, new_password): """Отправить письмо с новым паролем.""" template_name = 'myauth/reset_new_password_email.txt' diff --git a/project/settings.py b/project/settings.py index 04f1ef2..5315ee9 100644 --- a/project/settings.py +++ b/project/settings.py @@ -5,13 +5,12 @@ import os import sys from imp import find_module +from datetime import timedelta BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) ROOT_DIR = os.path.dirname( os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -print BASE_DIR - path = lambda *xs: os.path.abspath(os.path.join(os.path.dirname(__file__), *xs)) sys.path.insert(1, path('..')) @@ -19,7 +18,6 @@ sys.path.insert(1, path('.')) sys.path.insert(1, path('project')) DEBUG = False -TEMPLATE_DEBUG = DEBUG ADMINS = ( # ('Your Name', 'your_email@example.com'), @@ -86,6 +84,11 @@ STATICFILES_DIRS = ( # Make this unique, and don't share it with anybody. SECRET_KEY = 'uqrv8bpqt-#up^ay-)^@bcjjgq1^jy8qc!fkr!1wd*u%)1dg#y' +# List of callables that know how to import templates from various sources. +TEMPLATE_LOADERS = ( + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader', +) MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', @@ -286,9 +289,7 @@ BROKER_PASSWORD = "dokumentor" BROKER_VHOST = "dokumentor" CELERY_TIMEZONE = 'Europe/Moscow' -CELERY_ACCEPT_CONTENT = ['pickle'] # will be disabled in Celery 3.2 -from datetime import timedelta CALLBACK_SETTINGS = { 'EMAIL_SENDER': '!DEFINE', @@ -330,7 +331,6 @@ TEXT_SAVE_IMAGE_FUNCTION = 'cmsplugin_filer_image.integrations.ckeditor.create_i THUMBNAIL_PROCESSORS = ( 'easy_thumbnails.processors.colorspace', 'easy_thumbnails.processors.autocrop', - #'easy_thumbnails.processors.scale_and_crop', 'filer.thumbnail_processors.scale_and_crop_with_subject_location', 'easy_thumbnails.processors.filters', ) diff --git a/project/urls.py b/project/urls.py index 81c3d85..fba815e 100644 --- a/project/urls.py +++ b/project/urls.py @@ -11,11 +11,6 @@ autocomplete_light.autodiscover() urlpatterns = patterns('', - # Examples: - # url(r'^$', 'project.views.home', name='home'), - # url(r'^project/', include('project.foo.urls')), - - # Uncomment the admin/doc line below to enable admin documentation: url(r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: @@ -41,3 +36,9 @@ if settings.DEBUG: 'show_indexes': True, }), ) + +if settings.DEBUG: + import debug_toolbar + urlpatterns = [ + url(r'^__debug__/', include(debug_toolbar.urls)), + ] + urlpatterns \ No newline at end of file