Remove machina, remove default cache config, add some upgrades and compatibility...
authorRadek Czajka <rczajka@rczajka.pl>
Fri, 14 Oct 2022 11:36:40 +0000 (13:36 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Fri, 14 Oct 2022 11:36:40 +0000 (13:36 +0200)
16 files changed:
Makefile
requirements/requirements.txt
src/api/tests/tests.py
src/catalogue/fields.py
src/catalogue/tasks.py
src/catalogue/utils.py
src/wolnelektury/settings/__init__.py
src/wolnelektury/settings/apps.py
src/wolnelektury/settings/basic.py
src/wolnelektury/settings/cache.py [deleted file]
src/wolnelektury/settings/static.py
src/wolnelektury/templates/base/app.html
src/wolnelektury/templates/base/superbase.html
src/wolnelektury/templates/board_base.html [deleted file]
src/wolnelektury/templates/pagination/pagination.html
src/wolnelektury/urls.py

index 3956cf3..d43ff1e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -11,7 +11,7 @@ deploy: src/wolnelektury/localsettings.py
 .ONESHELL:
 test:
        cd src
-       coverage run --branch --source='.' ./manage.py test; true
+       python -Wall -m coverage run --branch --source='.' ./manage.py test; true
        coverage html -d ../htmlcov.new
        rm -rf ../htmlcov
        mv ../htmlcov.new ../htmlcov
index 9f2340d..b99f18e 100644 (file)
@@ -10,13 +10,12 @@ libsasscompiler==0.1.9
 jsmin==3.0.1
 
 fnp-django-pagination==2.2.5
-django-modeltranslation==0.18.2
+django-modeltranslation==0.18.4
 django-allauth==0.51
-django-extensions==3.1.5
+django-extensions==3.2.1
 djangorestframework==3.13.1
 djangorestframework-xml==2.0.0
 django-admin-ordering==0.14.0
-django-machina==1.1.6
 django-countries==7.3.2
 
 # A version compatible with Django 2.2+, with long help text and editable max_length.
@@ -34,7 +33,6 @@ pytz==2022.2.1
 
 django-honeypot==1.0.2
 
-python-memcached==1.59
 python-fb==0.2
 
 Feedparser==6.0.10
@@ -50,7 +48,8 @@ librarian==2.4.1
 celery[redis]==5.2.7
 
 # OAI-PMH
-pyoai==2.5.0
+#pyoai==2.5.1
+-e git+https://github.com/infrae/pyoai@5ff2f15e869869e70d8139e4c37b7832854d7049#egg=pyoai
 
 scorched==0.13
 httplib2
index c9afad7..5ad5ca3 100644 (file)
@@ -108,16 +108,18 @@ class TagTests(ApiTest):
 class PictureTests(ApiTest):
     def test_publish(self):
         slug = "kandinsky-composition-viii"
-        xml = SimpleUploadedFile(
-            'composition8.xml',
-            open(path.join(
+        with open(path.join(
                 picture.tests.__path__[0], "files", slug + ".xml"
-            ), 'rb').read())
-        img = SimpleUploadedFile(
-            'kompozycja-8.png',
-            open(path.join(
+            ), 'rb') as f:
+            xml = SimpleUploadedFile(
+                'composition8.xml',
+                f.read())
+        with open(path.join(
                 picture.tests.__path__[0], "files", slug + ".png"
-            ), 'rb').read())
+            ), 'rb') as f:
+            img = SimpleUploadedFile(
+                'kompozycja-8.png',
+                f.read())
 
         import_form = PictureImportForm({}, {
             'picture_xml_file': xml,
index 56de8c6..c592c55 100644 (file)
@@ -173,7 +173,8 @@ class EbookField(models.FileField):
         out = self.transform(
             book.wldocument2() if self.librarian2_api else book.wldocument(),
         )
-        fieldfile.save(None, File(open(out.get_filename(), 'rb')), save=False)
+        with open(out.get_filename(), 'rb') as f:
+            fieldfile.save(None, File(f), save=False)
         self.set_file_permissions(fieldfile)
         if book.pk is not None:
             book.save(update_fields=[self.attname])
index e16f1ff..b2308bb 100644 (file)
@@ -62,7 +62,8 @@ def build_custom_pdf(book_id, customizations, file_name, waiter_id=None):
                 morefloats=settings.LIBRARIAN_PDF_MOREFLOATS,
                 base_url=absolute_url(gallery_url(wldoc.book_info.url.slug)),
                 **kwargs)
-            DefaultStorage().save(file_name, File(open(pdf.get_filename(), 'rb')))
+            with open(pdf.get_filename(), 'rb') as f:
+                DefaultStorage().save(file_name, File(f))
     finally:
         if waiter_id is not None:
             WaitedFile.objects.filter(pk=waiter_id).delete()
index 9461243..ee3631c 100644 (file)
@@ -19,7 +19,7 @@ from django.conf import settings
 from django.core.files.storage import DefaultStorage
 from django.core.files.uploadedfile import UploadedFile
 from django.http import HttpResponse
-from django.utils.encoding import force_text
+from django.utils.encoding import force_str
 
 from reporting.utils import read_chunks
 
@@ -200,7 +200,7 @@ def truncate_html_words(s, num, end_text='...'):
 
     This is just a version of django.utils.text.truncate_html_words with no space before the end_text.
     """
-    s = force_text(s)
+    s = force_str(s)
     length = int(num)
     if length <= 0:
         return ''
index f8451cc..113c1e7 100644 (file)
@@ -8,7 +8,6 @@ from sentry_sdk.integrations.django import DjangoIntegration
 from .apps import *
 from .basic import *
 from .auth import *
-from .cache import *
 from .celery import *
 from .contrib import *
 from .custom import *
index 124f476..ad0ff15 100644 (file)
@@ -75,24 +75,6 @@ INSTALLED_APPS_CONTRIB = [
     'allauth.socialaccount.providers.facebook',
     'allauth.socialaccount.providers.google',
     # 'allauth.socialaccount.providers.twitter',
-
-    # Machina dependencies:
-    'mptt',
-    'haystack',
-    'widget_tweaks',
-
-    # Machina apps:
-    'machina',
-    'machina.apps.forum',
-    'machina.apps.forum_conversation',
-    'machina.apps.forum_conversation.forum_attachments',
-    'machina.apps.forum_conversation.forum_polls',
-    'machina.apps.forum_feeds',
-    'machina.apps.forum_moderation',
-    'machina.apps.forum_search',
-    'machina.apps.forum_tracking',
-    'machina.apps.forum_member',
-    'machina.apps.forum_permission',
 ]
 
 INSTALLED_APPS = INSTALLED_APPS_OUR + INSTALLED_APPS_CONTRIB
index 133db91..11eb7cf 100644 (file)
@@ -2,7 +2,6 @@
 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
 #
 from os import path
-from machina import MACHINA_MAIN_TEMPLATE_DIR
 from .paths import PROJECT_DIR
 
 DEBUG = True
@@ -15,6 +14,8 @@ MANAGERS = ADMINS
 
 CONTACT_EMAIL = 'fundacja@nowoczesnapolska.org.pl'
 
+CACHE_MIDDLEWARE_SECONDS = 24 * 60 * 60
+
 DATABASES = {
     'default': {
         'ENGINE': 'django.db.backends.sqlite3',  # 'postgresql_psycopg2'
@@ -43,10 +44,6 @@ SITE_ID = 1
 TEMPLATES = [{
     'BACKEND': 'django.template.backends.django.DjangoTemplates',
     'APP_DIRS': True,
-    'DIRS': (
-        path.join(PROJECT_DIR, 'templates'),  # Duplicate, because of Machina<1 weird configuration.
-        MACHINA_MAIN_TEMPLATE_DIR,
-    ),
     'OPTIONS': {
         'context_processors': (
             'django.contrib.auth.context_processors.auth',
@@ -57,7 +54,6 @@ TEMPLATES = [{
             'django.template.context_processors.request',
             'wolnelektury.context_processors.extra_settings',
             'search.context_processors.search_form',
-            'machina.core.context_processors.metadata',
         ),
     },
 }]
@@ -76,7 +72,6 @@ MIDDLEWARE = [
     'django.contrib.messages.middleware.MessageMiddleware',
     'fnpdjango.middleware.SetRemoteAddrFromXRealIP',
     'django.middleware.cache.FetchFromCacheMiddleware',
-    'machina.apps.forum_permission.middleware.ForumPermissionMiddleware',
     'experiments.middleware.experiments_middleware',
 ]
 
diff --git a/src/wolnelektury/settings/cache.py b/src/wolnelektury/settings/cache.py
deleted file mode 100644 (file)
index ce873cb..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
-# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
-#
-CACHES = {
-    'default': {
-        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
-        'LOCATION': [
-            '127.0.0.1:11211',
-        ]
-    },
-    'template_fragments': {
-        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
-        'TIMEOUT': 86400,
-        'LOCATION': [
-            '127.0.0.1:11211',
-        ],
-    },
-    'machina_attachments': {
-        'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
-        'LOCATION': '/tmp',
-    },
-}
-
-CACHE_MIDDLEWARE_SECONDS = 24 * 60 * 60
index 66caafb..776b47f 100644 (file)
@@ -238,9 +238,3 @@ STATICFILES_FINDERS = [
     'pipeline.finders.CachedFileFinder',
     'pipeline.finders.PipelineFinder',
 ]
-
-
-from machina import MACHINA_MAIN_STATIC_DIR
-STATICFILES_DIRS = (
-    MACHINA_MAIN_STATIC_DIR,
-)
index 5bca344..e10b689 100644 (file)
@@ -48,7 +48,7 @@
                       {% csrf_token %}
                       <input type="hidden" name="language" value="{{ lang.0 }}"/>
                       <button type="submit" lang="{{ lang.0 }}"
-                              class="{% ifequal lang.0 LANGUAGE_CODE %}active{% endifequal %}">{{ lang.1 }}</button>
+                              class="{% if lang.0 == LANGUAGE_CODE %}active{% endif %}">{{ lang.1 }}</button>
                     </form>
                   {% endfor %}
                 </div>
index 9c77627..176b3c3 100644 (file)
@@ -80,7 +80,7 @@
                       {% csrf_token %}
                       <input type="hidden" name="language" value="{{ lang.0 }}"/>
                       <button type="submit" lang="{{ lang.0 }}" tabindex="121"
-                              class="{% ifequal lang.0 LANGUAGE_CODE %}active{% endifequal %}">{{ lang.1 }}</button>
+                              class="{% if lang.0 == LANGUAGE_CODE %}active{% endif %}">{{ lang.1 }}</button>
                     </form>
                   {% endfor %}
                 </div>
diff --git a/src/wolnelektury/templates/board_base.html b/src/wolnelektury/templates/board_base.html
deleted file mode 100644 (file)
index 0a83b80..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-{% extends 'board_base.html' %}
-{% load i18n %}
-{% load static %}
-{% load stylesheet from pipeline %}
-
-{% block css %}
-   {{ block.super }}
-   {% stylesheet 'forum' %}
-{% endblock css %}
-
-
-
-{% block header %}
-<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
-  <a class="navbar-brand" href="{% url 'forum:index' %}">
-    {% block brand %}
-      <img src="{% static 'img/logo-neon-transp.png' %}" alt="Wolne Lektury">
-    {% endblock %}
-  </a>
-
-  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
-    <span class="navbar-toggler-icon"></span>
-  </button>
-  <div class="collapse navbar-collapse" id="navbarSupportedContent">
-    {% block header_collapse %}
-    <form class="form-inline my-2 ml-3 my-lg-0" role="search" action="{% url 'forum_search:search' %}">
-      <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search" name="q">
-      <button class="btn btn-outline-light my-2 my-sm-0" type="submit">{% trans "Search" %}</button>
-    </form>
-    <div class="navbar-nav mr-auto">
-      <a class="nav-item nav-link" href="{% url 'forum_search:search' %}">{% trans "Advanced search" %}</a>
-    </div>
-    <div class="navbar-nav mr-auto">
-      {% if request.user.is_authenticated %}
-        <div class="nav-item">
-          <a class="nav-link disabled">
-            {{ request.user.username }}
-          </a>
-       </div>
-        {% if request.user.is_staff %}
-         <div class="nav-item">
-            <a class="nav-link" href="{% url 'admin:index' %}">
-              {% trans "Administration" %}
-            </a>
-         </div>
-        {% endif %}
-       <div class="nav-item">
-          <a class="nav-link" href="{% url 'logout' %}">{% trans "Logout" %}</a>
-       </div>
-      {% endif %}
-    </div>
-    {% endblock header_collapse %}
-  </div>
-</nav>
-{% endblock header %}
index 9f3375a..4609321 100644 (file)
@@ -9,11 +9,11 @@
     {% endif %}
     {% for page in pages %}
       {% if page %}
-        {% ifequal page page_obj.number %}
+        {% if page == page_obj.number %}
           <span class="current page"> {{ page }} </span>
         {% else %}
           <a href="?page={{ page }}{{ getvars }}" class="page"> {{ page }} </a>
-        {% endifequal %}
+        {% endif %}
       {% else %}
         …
       {% endif %}
index 4de5f49..f71b02b 100644 (file)
@@ -74,7 +74,6 @@ urlpatterns += [
     path('szukaj/', include('search.urls')),
 
     path('i18n/', include('django.conf.urls.i18n')),
-    path('forum/', include('machina.urls')),
 ]
 
 urlpatterns += [