From: Radek Czajka Date: Fri, 2 Aug 2019 13:24:47 +0000 (+0200) Subject: Remove ssify. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/75957f735219259d3b4bc361f80ccd3d7b92a0e9?ds=sidebyside;hp=9ce7b544a0616db407be602ea453771fc9c0a6dd Remove ssify. --- diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 299652762..9660e2414 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -59,7 +59,6 @@ django-getpaid==1.8.0 deprecated httplib2 -django-ssify==0.2.7 raven diff --git a/src/catalogue/api/views.py b/src/catalogue/api/views.py index 68626e6d6..34971c45f 100644 --- a/src/catalogue/api/views.py +++ b/src/catalogue/api/views.py @@ -159,7 +159,7 @@ class Preview(ListAPIView): def get_queryset(self): qs = Book.objects.filter(preview=True) # FIXME: temporary workaround for a problem with iOS app; see #3954. - if 'Darwin' in self.request.META['HTTP_USER_AGENT'] and 'debug' not in self.request.GET: + if 'Darwin' in self.request.META.get('HTTP_USER_AGENT', '') and 'debug' not in self.request.GET: qs = qs.none() return qs diff --git a/src/catalogue/fields.py b/src/catalogue/fields.py index 2b2d6a6da..8f6bc7aa4 100644 --- a/src/catalogue/fields.py +++ b/src/catalogue/fields.py @@ -96,7 +96,7 @@ class BuildEbook(Task): """Just run `build` on FieldFile, can't pass it directly to Celery.""" task_logger.info("%s -> %s" % (obj.slug, field_name)) ret = self.build(getattr(obj, field_name)) - obj.flush_includes() + obj.clear_cache() return ret def set_file_permissions(self, fieldfile): diff --git a/src/catalogue/models/book.py b/src/catalogue/models/book.py index ecf6d9651..d47cb1520 100644 --- a/src/catalogue/models/book.py +++ b/src/catalogue/models/book.py @@ -16,7 +16,6 @@ from django.utils.translation import ugettext_lazy as _, get_language from django.utils.deconstruct import deconstructible import jsonfield from fnpdjango.storage import BofhFileSystemStorage -from ssify import flush_ssi_includes from librarian.cover import WLCover from librarian.html import transform_abstrakt @@ -592,23 +591,9 @@ class Book(models.Model): b.ancestor.add(parent) parent = parent.parent - def flush_includes(self, languages=True): + def clear_cache(self): clear_cached_renders(self.mini_box) clear_cached_renders(self.mini_box_nolink) - if not languages: - return - if languages is True: - languages = [lc for (lc, _ln) in settings.LANGUAGES] - flush_ssi_includes([ - template % (self.pk, lang) - for template in [ - '/katalog/b/%d/short.%s.html', - '/katalog/b/%d/wide.%s.html', - '/api/include/book/%d.%s.json', - '/api/include/book/%d.%s.xml', - ] - for lang in languages - ]) def cover_info(self, inherit=True): """Returns a dictionary to serve as fallback for BookInfo. diff --git a/src/catalogue/models/collection.py b/src/catalogue/models/collection.py index f059cb3c9..739ad78ec 100644 --- a/src/catalogue/models/collection.py +++ b/src/catalogue/models/collection.py @@ -5,8 +5,8 @@ from django.conf import settings from django.db import models from django.urls import reverse from django.utils.translation import ugettext_lazy as _ -from ssify import flush_ssi_includes import re +from wolnelektury.utils import cached_render, clear_cached_renders class Collection(models.Model): @@ -46,11 +46,11 @@ class Collection(models.Model): from catalogue.models import Book return Book.objects.filter(self.get_query()) - def flush_includes(self, languages=True): - if not languages: - return - if languages is True: - languages = [lc for (lc, _ln) in settings.LANGUAGES] + @cached_render('catalogue/collection_box.html') + def box(self): + return { + 'collection': self + } - flush_ssi_includes([ - '/katalog/%s.json' % lang for lang in languages]) + def clear_cache(self): + clear_cached_renders(self.box) diff --git a/src/catalogue/models/fragment.py b/src/catalogue/models/fragment.py index ef15f85b4..ac0c53908 100644 --- a/src/catalogue/models/fragment.py +++ b/src/catalogue/models/fragment.py @@ -8,7 +8,7 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ from newtagging import managers from catalogue.models import Tag -from ssify import flush_ssi_includes +from wolnelektury.utils import cached_render, clear_cached_renders class Fragment(models.Model): @@ -23,8 +23,6 @@ class Fragment(models.Model): tags = managers.TagDescriptor(Tag) tag_relations = GenericRelation(Tag.intermediary_table_model) - short_html_url_name = 'catalogue_fragment_short' - class Meta: ordering = ('book', 'anchor',) verbose_name = _('fragment') @@ -41,21 +39,18 @@ class Fragment(models.Model): """Returns short version of the fragment.""" return self.short_text if self.short_text else self.text + @cached_render('catalogue/fragment_short.html') + def midi_box(self): + return {'fragment': self} + + @cached_render('catalogue/fragment_promo.html') + def promo_box(self): + return {'fragment': self} + @property def themes(self): return self.tags.filter(category='theme') - def flush_includes(self, languages=True): - if not languages: - return - if languages is True: - languages = [lc for (lc, _ln) in settings.LANGUAGES] - flush_ssi_includes([ - template % (self.pk, lang) - for template in [ - '/katalog/f/%d/short.%s.html', - '/api/include/fragment/%d.%s.json', - '/api/include/fragment/%d.%s.xml', - ] - for lang in languages - ]) + def clear_cache(self): + clear_cached_renders(self.midi_box) + clear_cached_renders(self.promo_box) diff --git a/src/catalogue/models/source.py b/src/catalogue/models/source.py index f36850ddd..c678cad51 100644 --- a/src/catalogue/models/source.py +++ b/src/catalogue/models/source.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # @@ -40,5 +39,5 @@ class Source(models.Model): for book in Book.objects.all(): source = book.extra_info.get('source_url', '') if self.netloc in source or (old_netloc != self.netloc and old_netloc in source): - book.flush_includes() + book.clear_cache() return ret diff --git a/src/catalogue/models/tag.py b/src/catalogue/models/tag.py index dac96e248..db7267e1b 100644 --- a/src/catalogue/models/tag.py +++ b/src/catalogue/models/tag.py @@ -14,7 +14,6 @@ from django.urls import reverse from django.utils.translation import ugettext_lazy as _ from newtagging.models import TagManager, TaggedItemManager -from ssify import flush_ssi_includes # Those are hard-coded here so that makemessages sees them. @@ -72,7 +71,7 @@ class Tag(models.Model): created_at = models.DateTimeField(_('creation date'), auto_now_add=True, db_index=True) changed_at = models.DateTimeField(_('creation date'), auto_now=True, db_index=True) - after_change = Signal(providing_args=['instance', 'languages']) + after_change = Signal(providing_args=['instance']) intermediary_table_model = TagRelation objects = TagManager() @@ -101,59 +100,12 @@ class Tag(models.Model): app_label = 'catalogue' def save(self, *args, **kwargs): - flush_cache = flush_all_includes = False - if self.pk and self.category != 'set': - # Flush the whole views cache. - # Seem a little harsh, but changed tag names, descriptions - # and links come up at any number of places. - flush_cache = True - - # Find in which languages we need to flush related includes. - old_self = type(self).objects.get(pk=self.pk) - # Category shouldn't normally be changed, but just in case. - if self.category != old_self.category: - flush_all_includes = True - languages_changed = self.languages_changed(old_self) - + existing = self.pk and self.category != 'set' ret = super(Tag, self).save(*args, **kwargs) - - if flush_cache: - caches[settings.CACHE_MIDDLEWARE_ALIAS].clear() - if flush_all_includes: - flush_ssi_includes() - else: - self.flush_includes() - self.after_change.send(sender=type(self), instance=self, languages=languages_changed) - + if existing: + self.after_change.send(sender=type(self), instance=self) return ret - def languages_changed(self, old): - all_langs = [lc for (lc, _ln) in settings.LANGUAGES] - if (old.category, old.slug) != (self.category, self.slug): - return all_langs - languages = set() - for lang in all_langs: - name_field = 'name_%s' % lang - if getattr(old, name_field) != getattr(self, name_field): - languages.add(lang) - return languages - - def flush_includes(self, languages=True): - if not languages: - return - if languages is True: - languages = [lc for (lc, _ln) in settings.LANGUAGES] - flush_ssi_includes([ - template % (self.pk, lang) - for template in [ - '/api/include/tag/%d.%s.json', - '/api/include/tag/%d.%s.xml', - ] - for lang in languages - ]) - flush_ssi_includes([ - '/katalog/%s.json' % lang for lang in languages]) - def __str__(self): return self.name diff --git a/src/catalogue/signals.py b/src/catalogue/signals.py index d3d6ec340..72f8a8910 100644 --- a/src/catalogue/signals.py +++ b/src/catalogue/signals.py @@ -6,7 +6,6 @@ from django.core.cache import caches from django.core.exceptions import ImproperlyConfigured from django.db.models.signals import post_save, post_delete from django.dispatch import receiver -from ssify import flush_ssi_includes from newtagging.models import tags_updated from picture.models import Picture, PictureArea from .models import BookMedia, Book, Collection, Fragment, Tag @@ -31,17 +30,8 @@ def bookmedia_save(sender, instance, **kwargs): @receiver(post_save, sender=Collection) def collection_save(sender, instance, **kwargs): caches[settings.CACHE_MIDDLEWARE_ALIAS].clear() - flush_ssi_includes([ - '/katalog/%s.json' % lang - for lang in [lc for (lc, _ln) in settings.LANGUAGES]]) -@receiver(post_delete, sender=Collection) -def collection_delete(sender, instance, **kwargs): - flush_ssi_includes([ - '/katalog/%s.json' % lang - for lang in [lc for (lc, _ln) in settings.LANGUAGES]]) - #### # Book #### @@ -56,15 +46,12 @@ def book_save(sender, instance, **kwargs): caches['template_fragments'].clear() except ImproperlyConfigured: pass - instance.flush_includes() + instance.clear_cache() @receiver(post_delete, sender=Book) def book_delete(sender, instance, **kwargs): caches[settings.CACHE_MIDDLEWARE_ALIAS].clear() - flush_ssi_includes([ - '/katalog/%s.json' % lang - for lang in [lc for (lc, _ln) in settings.LANGUAGES]]) if not settings.NO_SEARCH_INDEX: # remove the book from search index, when it is deleted. @@ -80,20 +67,17 @@ def book_delete(sender, instance, **kwargs): @receiver(Tag.after_change) -def tag_after_change(sender, instance, languages, **kwargs): +def tag_after_change(sender, instance, **kwargs): caches[settings.CACHE_MIDDLEWARE_ALIAS].clear() - flush_ssi_includes([ - '/katalog/%s.json' % lang - for lang in [lc for (lc, _ln) in settings.LANGUAGES]]) for model in Book, Picture: for model_instance in model.tagged.with_all([instance]).only('pk'): - model_instance.flush_includes() + model_instance.clear_cache() if instance.category == 'author': for model in Fragment, PictureArea: for model_instance in model.tagged.with_all([instance]).only('pk'): - model_instance.flush_includes() + model_instance.clear_cache() @receiver(tags_updated) @@ -103,7 +87,4 @@ def receive_tags_updated(sender, instance, affected_tags, **kwargs): return caches[settings.CACHE_MIDDLEWARE_ALIAS].clear() - instance.flush_includes() - flush_ssi_includes([ - '/katalog/%s.json' % lang - for lang in [lc for (lc, _ln) in settings.LANGUAGES]]) + instance.clear_cache() diff --git a/src/catalogue/templates/catalogue/book_wide.html b/src/catalogue/templates/catalogue/book_wide.html index b4faeab50..ad0384c48 100644 --- a/src/catalogue/templates/catalogue/book_wide.html +++ b/src/catalogue/templates/catalogue/book_wide.html @@ -2,7 +2,6 @@ {% load i18n %} {% load choose_fragment license_icon from catalogue_tags %} {% load choose_cite from social_tags %} -{% load ssi_include from ssify %} {% block box-class %}book-wide-box{% endblock %} @@ -18,14 +17,15 @@ {% block right-column %}
- {% choose_cite book.pk as cite_promo %} - {% choose_fragment book.pk unless=cite_promo as fragment_promo %} - {{ cite_promo.if }} - {% ssi_include 'social_cite' pk=cite_promo %} - {{ cite_promo.endif }} - {{ fragment_promo.if }} - {% ssi_include 'catalogue_fragment_promo' pk=fragment_promo %} - {{ fragment_promo.endif }} + {% choose_cite book as cite_promo %} + {% if cite_promo %} + {{ cite.promo_box }} + {% else %} + {% choose_fragment book as fragment_promo %} + {% if fragment_promo %} + {{ fragment_promo.promo_box }} + {% endif %} + {% endif %}
{% include 'catalogue/snippets/jplayer.html' %}
diff --git a/src/catalogue/templates/catalogue/collections.html b/src/catalogue/templates/catalogue/collections.html index 2f8d1214b..1d7b0f71e 100644 --- a/src/catalogue/templates/catalogue/collections.html +++ b/src/catalogue/templates/catalogue/collections.html @@ -1,7 +1,6 @@ {% extends "base/base.html" %} {% load i18n %} {% load catalogue_tags %} -{% load ssi_include from ssify %} {% block titleextra %}{% trans "Collections" %}{% endblock %} @@ -11,7 +10,7 @@

{% trans "Collections" %}

{% for obj in best %} - {% ssi_include 'catalogue_collection_box' pk=obj.pk %} + {{ obj.box }} {% endfor %}

{% trans "All collections" %}

diff --git a/src/catalogue/templates/catalogue/related_books.html b/src/catalogue/templates/catalogue/related_books.html index 62e45f26d..cd2f358ac 100755 --- a/src/catalogue/templates/catalogue/related_books.html +++ b/src/catalogue/templates/catalogue/related_books.html @@ -12,12 +12,13 @@ {% if random %} {% catalogue_random_book random_excluded_books as random_book %} - {% picture_random_picture random_excluded_pics unless=random_book as random_pic %} {% if random_book %} {{ random_book.mini_box }} - {% endif %} - {% if random_pic %} - {{ random_pic.mini_box }} + {% else %} + {% picture_random_picture random_excluded_pics as random_pic %} + {% if random_pic %} + {{ random_pic.mini_box }} + {% endif %} {% endif %} {% endif %} {% endspaceless %} diff --git a/src/catalogue/templates/catalogue/search_multiple_hits.html b/src/catalogue/templates/catalogue/search_multiple_hits.html index b14ab0cc0..6da02a8d3 100644 --- a/src/catalogue/templates/catalogue/search_multiple_hits.html +++ b/src/catalogue/templates/catalogue/search_multiple_hits.html @@ -3,7 +3,6 @@ {% load pagination_tags %} {% load inline_tag_list from catalogue_tags %} {% load book_searched from search_tags %} -{% load ssi_include from ssify %} {% block titleextra %}{% trans "Search" %}{% endblock %} diff --git a/src/catalogue/templates/catalogue/snippets/like_button.html b/src/catalogue/templates/catalogue/snippets/like_button.html index 9b333c402..298f34ea7 100644 --- a/src/catalogue/templates/catalogue/snippets/like_button.html +++ b/src/catalogue/templates/catalogue/snippets/like_button.html @@ -1,6 +1,6 @@ {% load likes_book from social_tags %} -{% likes_book book.pk as likes %} -
+{% likes_book book as likes %} +