X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/540e76dd8e04d7bab431da696565e826788bd218..ca8f4e8fef80cb603117ed579da8554f503698e5:/src/catalogue/models/fragment.py diff --git a/src/catalogue/models/fragment.py b/src/catalogue/models/fragment.py index dc159a59f..6609ba8f5 100644 --- a/src/catalogue/models/fragment.py +++ b/src/catalogue/models/fragment.py @@ -1,15 +1,13 @@ -# -*- 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. +# This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Wolne Lektury. See NOTICE for more information. # from django.conf import settings from django.contrib.contenttypes.fields import GenericRelation -from django.core.urlresolvers import reverse +from django.urls import reverse 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): @@ -17,19 +15,17 @@ class Fragment(models.Model): text = models.TextField() short_text = models.TextField(editable=False) anchor = models.CharField(max_length=120) - book = models.ForeignKey('Book', related_name='fragments') + book = models.ForeignKey('Book', models.CASCADE, related_name='fragments') objects = models.Manager() tagged = managers.ModelTaggedItemManager(Tag) 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') - verbose_name_plural = _('fragments') + verbose_name = 'fragment' + verbose_name_plural = 'fragmenty' app_label = 'catalogue' def get_absolute_url(self): @@ -45,18 +41,3 @@ class Fragment(models.Model): @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 - ])