From: Radek Czajka Date: Fri, 14 Oct 2022 11:36:40 +0000 (+0200) Subject: Remove machina, remove default cache config, add some upgrades and compatibility... X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/5c14b2f1216cf266efd63f4de84e3f83bb99c9ff?page=%7B%7B%20page%20%7D%7D%7B%7B%20getvars%20%7D%7D Remove machina, remove default cache config, add some upgrades and compatibility fixes. --- diff --git a/Makefile b/Makefile index 3956cf34c..d43ff1e6d 100644 --- 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 diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 9f2340da3..b99f18e3b 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -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 diff --git a/src/api/tests/tests.py b/src/api/tests/tests.py index c9afad7b0..5ad5ca34f 100644 --- a/src/api/tests/tests.py +++ b/src/api/tests/tests.py @@ -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, diff --git a/src/catalogue/fields.py b/src/catalogue/fields.py index 56de8c6da..c592c5504 100644 --- a/src/catalogue/fields.py +++ b/src/catalogue/fields.py @@ -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]) diff --git a/src/catalogue/tasks.py b/src/catalogue/tasks.py index e16f1ff5a..b2308bbdf 100644 --- a/src/catalogue/tasks.py +++ b/src/catalogue/tasks.py @@ -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() diff --git a/src/catalogue/utils.py b/src/catalogue/utils.py index 9461243da..ee3631c76 100644 --- a/src/catalogue/utils.py +++ b/src/catalogue/utils.py @@ -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 '' diff --git a/src/wolnelektury/settings/__init__.py b/src/wolnelektury/settings/__init__.py index f8451cc23..113c1e731 100644 --- a/src/wolnelektury/settings/__init__.py +++ b/src/wolnelektury/settings/__init__.py @@ -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 * diff --git a/src/wolnelektury/settings/apps.py b/src/wolnelektury/settings/apps.py index 124f4764b..ad0ff1592 100644 --- a/src/wolnelektury/settings/apps.py +++ b/src/wolnelektury/settings/apps.py @@ -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 diff --git a/src/wolnelektury/settings/basic.py b/src/wolnelektury/settings/basic.py index 133db91e2..11eb7cfe4 100644 --- a/src/wolnelektury/settings/basic.py +++ b/src/wolnelektury/settings/basic.py @@ -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 index ce873cbc4..000000000 --- a/src/wolnelektury/settings/cache.py +++ /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 diff --git a/src/wolnelektury/settings/static.py b/src/wolnelektury/settings/static.py index 66caafbe3..776b47f7d 100644 --- a/src/wolnelektury/settings/static.py +++ b/src/wolnelektury/settings/static.py @@ -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, -) diff --git a/src/wolnelektury/templates/base/app.html b/src/wolnelektury/templates/base/app.html index 5bca344e9..e10b6892e 100644 --- a/src/wolnelektury/templates/base/app.html +++ b/src/wolnelektury/templates/base/app.html @@ -48,7 +48,7 @@ {% csrf_token %} + class="{% if lang.0 == LANGUAGE_CODE %}active{% endif %}">{{ lang.1 }} {% endfor %} diff --git a/src/wolnelektury/templates/base/superbase.html b/src/wolnelektury/templates/base/superbase.html index 9c77627e8..176b3c3f4 100644 --- a/src/wolnelektury/templates/base/superbase.html +++ b/src/wolnelektury/templates/base/superbase.html @@ -80,7 +80,7 @@ {% csrf_token %} + class="{% if lang.0 == LANGUAGE_CODE %}active{% endif %}">{{ lang.1 }} {% endfor %} diff --git a/src/wolnelektury/templates/board_base.html b/src/wolnelektury/templates/board_base.html deleted file mode 100644 index 0a83b8077..000000000 --- a/src/wolnelektury/templates/board_base.html +++ /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 %} - -{% endblock header %} diff --git a/src/wolnelektury/templates/pagination/pagination.html b/src/wolnelektury/templates/pagination/pagination.html index 9f3375a7d..460932127 100644 --- a/src/wolnelektury/templates/pagination/pagination.html +++ b/src/wolnelektury/templates/pagination/pagination.html @@ -9,11 +9,11 @@ {% endif %} {% for page in pages %} {% if page %} - {% ifequal page page_obj.number %} + {% if page == page_obj.number %} {{ page }} {% else %} {{ page }} - {% endifequal %} + {% endif %} {% else %} … {% endif %} diff --git a/src/wolnelektury/urls.py b/src/wolnelektury/urls.py index 4de5f4909..f71b02ba8 100644 --- a/src/wolnelektury/urls.py +++ b/src/wolnelektury/urls.py @@ -74,7 +74,6 @@ urlpatterns += [ path('szukaj/', include('search.urls')), path('i18n/', include('django.conf.urls.i18n')), - path('forum/', include('machina.urls')), ] urlpatterns += [