From: Radek Czajka Date: Thu, 19 Mar 2015 15:02:35 +0000 (+0100) Subject: Celery update + cleaning. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/baab092545bc665c1259488925af9213591ee310?ds=inline;hp=e4176cee859a58a2986f4c3093318f47ade29356 Celery update + cleaning. --- diff --git a/apps/catalogue/templates/catalogue/my_page.html b/apps/catalogue/templates/catalogue/my_page.html index c6b61ce8..00df71c9 100755 --- a/apps/catalogue/templates/catalogue/my_page.html +++ b/apps/catalogue/templates/catalogue/my_page.html @@ -23,8 +23,14 @@

{% trans "Your last edited documents" %}

    - {% for slugs, item in last_books %} -
  1. {{ item.title }}
    ({{ item.time|date:"H:i:s, d/m/Y" }})
  2. {% endfor %}
diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index ef8d83a5..5aeab7a7 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -58,10 +58,12 @@ def user(request, username): @active_tab('my') @never_cache def my(request): + last_books = sorted(request.session.get("wiki_last_books", {}).items(), + key=lambda x: x[1]['time'], reverse=True) + for k, v in last_books: + v['time'] = datetime.fromtimestamp(v['time']) return render(request, 'catalogue/my_page.html', { - 'last_books': sorted(request.session.get("wiki_last_books", {}).items(), - key=lambda x: x[1]['time'], reverse=True), - + 'last_books': last_books, "logout_to": '/', }) diff --git a/apps/wiki/views.py b/apps/wiki/views.py index f9594261..34f02407 100644 --- a/apps/wiki/views.py +++ b/apps/wiki/views.py @@ -1,6 +1,7 @@ from datetime import datetime import os import logging +from time import mktime import urllib from django.conf import settings @@ -52,8 +53,8 @@ def editor(request, slug, chunk=None, template_name='wiki/document_details.html' access_time = datetime.now() last_books = request.session.get("wiki_last_books", {}) - last_books[slug, chunk.slug] = { - 'time': access_time, + last_books[reverse(editor, args=[chunk.book.slug, chunk.slug])] = { + 'time': mktime(access_time.timetuple()), 'title': chunk.pretty_name(), } @@ -87,7 +88,7 @@ def editor_readonly(request, slug, chunk=None, template_name='wiki/document_deta access_time = datetime.now() last_books = request.session.get("wiki_last_books", {}) last_books[slug, chunk.slug] = { - 'time': access_time, + 'time': mktime(access_time.timetuple()), 'title': chunk.book.title, } diff --git a/redakcja.vhost.template b/redakcja.vhost.template deleted file mode 100644 index 0c56cbd1..00000000 --- a/redakcja.vhost.template +++ /dev/null @@ -1,23 +0,0 @@ - - ServerName $DOMAIN - ServerAdmin $ADMIN_EMAIL - - WSGIDaemonProcess $PROJECT_NAME user=$WSGI_USER group=$WSGI_USER processes=$WSGI_PROCESSES threads=$WSGI_THREADS display-name=%{GROUP} - WSGIProcessGroup $PROJECT_NAME - - WSGIScriptAlias / $WSGI_FILE - - Order allow,deny - allow from all - - - Alias /media $MEDIA_DIR - - Order allow,deny - Allow from all - - - LogLevel warn - ErrorLog /var/log/apache2/$PROJECT_NAME/error.log - CustomLog /var/log/apache2/$PROJECT_NAME/access.log combined - diff --git a/redakcja.wsgi.template b/redakcja.wsgi.template deleted file mode 100644 index 2d10ac38..00000000 --- a/redakcja.wsgi.template +++ /dev/null @@ -1,26 +0,0 @@ -#!$PYTHON_BIN -import site -site.addsitedir('$PYTHON_SITE') - -import os -from os.path import abspath, dirname, join -import sys - -# Redirect sys.stdout to sys.stderr for bad libraries like geopy that use -# print statements for optional import exceptions. -sys.stdout = sys.stderr - -# Add apps and lib directories to PYTHONPATH -sys.path = [ - '$APP_DIR', - '$APP_DIR/lib', - '$APP_DIR/lib/librarian', - '$APP_DIR/apps', -] + sys.path - -# Run Django -os.environ["CELERY_LOADER"] = "django" -os.environ['DJANGO_SETTINGS_MODULE'] = '$PROJECT_NAME.settings' - -from django.core.handlers.wsgi import WSGIHandler -application = WSGIHandler() diff --git a/redakcja/__init__.py b/redakcja/__init__.py index e69de29b..b64e43e8 100644 --- a/redakcja/__init__.py +++ b/redakcja/__init__.py @@ -0,0 +1,5 @@ +from __future__ import absolute_import + +# 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 diff --git a/redakcja/celery.py b/redakcja/celery.py new file mode 100644 index 00000000..a2fed69b --- /dev/null +++ b/redakcja/celery.py @@ -0,0 +1,23 @@ +from __future__ import absolute_import + +import os +import sys + +ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +sys.path = [ + os.path.join(ROOT, 'apps'), + os.path.join(ROOT, 'lib'), + os.path.join(ROOT, 'lib/librarian'), +] + sys.path + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'redakcja.localsettings') + +from celery import Celery +from django.conf import settings + +app = Celery('redakcja') + +# 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) diff --git a/redakcja/settings/common.py b/redakcja/settings/common.py index 09d5016e..0c1a009f 100644 --- a/redakcja/settings/common.py +++ b/redakcja/settings/common.py @@ -112,9 +112,8 @@ INSTALLED_APPS = ( 'sorl.thumbnail', 'pagination', 'django_gravatar', - 'djcelery', - 'djkombu', 'fileupload', + 'kombu.transport.django', 'pipeline', 'fnpdjango', @@ -138,15 +137,10 @@ CAS_USER_ATTRS_MAP = { IMAGE_DIR = 'images/' -import djcelery -djcelery.setup_loader() - -BROKER_BACKEND = "djkombu.transport.DatabaseTransport" -BROKER_HOST = "localhost" -BROKER_PORT = 5672 -BROKER_USER = "guest" -BROKER_PASSWORD = "guest" -BROKER_VHOST = "/" +BROKER_URL = 'django://' +CELERY_EAGER_PROPAGATES_EXCEPTIONS = True +CELERY_SEND_TASK_ERROR_EMAILS = True +CELERY_ACCEPT_CONTENT = ['pickle'] # Remove when all tasks jsonable. SHOW_APP_VERSION = False diff --git a/requirements.txt b/requirements.txt index 83f494f9..1bc4f094 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,8 @@ --i http://pypi.nowoczesnapolska.org.pl/simple +-i http://py.mdrn.pl:8443/simple ## Python libraries lxml>=2.2.2 -Mercurial>=2.6,<2.7 +Mercurial>=3.3,<3.4 PyYAML>=3.0 Pillow oauth2 @@ -20,8 +20,9 @@ sorl-thumbnail>=11.09,<12 django-maintenancemode>=0.9 django-pagination django-gravatar2 -django-celery -django-kombu + +celery>=3.1.12,<3.2 +kombu>=3.0,<3.1 # migrations -south>=0.6 +South>=1.0.2