Celery update + cleaning.
authorRadek Czajka <radekczajka@nowoczesnapolska.org.pl>
Thu, 19 Mar 2015 15:02:35 +0000 (16:02 +0100)
committerRadek Czajka <radekczajka@nowoczesnapolska.org.pl>
Thu, 19 Mar 2015 15:02:35 +0000 (16:02 +0100)
apps/catalogue/templates/catalogue/my_page.html
apps/catalogue/views.py
apps/wiki/views.py
redakcja.vhost.template [deleted file]
redakcja.wsgi.template [deleted file]
redakcja/__init__.py
redakcja/celery.py [new file with mode: 0644]
redakcja/settings/common.py
requirements.txt

index c6b61ce..00df71c 100755 (executable)
     <div id="last-edited-list">
         <h2>{% trans "Your last edited documents" %}</h2>
         <ol>
-            {% for slugs, item in last_books %}
-            <li><a href="{% url 'wiki_editor' slugs.0 slugs.1 %}"
+            {% for edit_url, item in last_books %}
+                <li><a
+                {% if edit_url|length == 2 %}
+                    {# Temporary support for old-style last_books. #}
+                    href="{% url 'wiki_editor' edit_url.0 edit_url.1 %}"
+                {% else %}
+                    href="{{ edit_url }}"
+                {% endif %}
                 target="_blank">{{ item.title }}</a><br/><span class="date">({{ item.time|date:"H:i:s, d/m/Y" }})</span></li>
             {% endfor %}
         </ol>
index ef8d83a..5aeab7a 100644 (file)
@@ -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": '/',
         })
 
index f959426..34f0240 100644 (file)
@@ -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 (file)
index 0c56cbd..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-<VirtualHost *:80>
-    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
-    <Directory $WSGI_DIR>
-        Order allow,deny
-        allow from all
-    </Directory>
-
-    Alias /media $MEDIA_DIR
-    <Directory $MEDIA_DIR>
-        Order allow,deny
-        Allow from all
-    </Directory>
-
-    LogLevel warn
-    ErrorLog /var/log/apache2/$PROJECT_NAME/error.log
-    CustomLog /var/log/apache2/$PROJECT_NAME/access.log combined
-</VirtualHost>
diff --git a/redakcja.wsgi.template b/redakcja.wsgi.template
deleted file mode 100644 (file)
index 2d10ac3..0000000
+++ /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()
index e69de29..b64e43e 100644 (file)
@@ -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 (file)
index 0000000..a2fed69
--- /dev/null
@@ -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)
index 09d5016..0c1a009 100644 (file)
@@ -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
 
index 83f494f..1bc4f09 100644 (file)
@@ -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