X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/5913c54d19b8f6775633176032161d49f9b2f1aa..df341bdd09208d2b0f84060454cc0000df19deba:/src/catalogue/models/chunk.py?ds=inline diff --git a/src/catalogue/models/chunk.py b/src/catalogue/models/chunk.py old mode 100755 new mode 100644 index fc3a9eae..b3e6acaa --- a/src/catalogue/models/chunk.py +++ b/src/catalogue/models/chunk.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -# # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # @@ -7,10 +5,10 @@ from django.conf import settings from django.db import models from django.db.utils import IntegrityError from django.template.loader import render_to_string +from django.urls import reverse from django.utils.translation import ugettext_lazy as _ from catalogue.helpers import cached_in_field from catalogue.managers import VisibleManager -from catalogue.tasks import refresh_instance from dvcs import models as dvcs_models @@ -18,16 +16,16 @@ class Chunk(dvcs_models.Document): """ An editable chunk of text. Every Book text is divided into chunks. """ REPO_PATH = settings.CATALOGUE_REPO_PATH - book = models.ForeignKey('Book', editable=False, verbose_name=_('book')) + book = models.ForeignKey('Book', models.CASCADE, editable=False, verbose_name=_('book')) number = models.IntegerField(_('number')) title = models.CharField(_('title'), max_length=255, blank=True) slug = models.SlugField(_('slug')) gallery_start = models.IntegerField(_('gallery start'), null=True, blank=True, default=1) # cache - _short_html = models.TextField(null=True, blank=True, editable=False) _hidden = models.NullBooleanField(editable=False) _changed = models.NullBooleanField(editable=False) + _new_publishable = models.NullBooleanField(editable=False) # managers objects = models.Manager() @@ -44,18 +42,17 @@ class Chunk(dvcs_models.Document): # Representing # ============ - def __unicode__(self): + def __str__(self): return "%d:%d: %s" % (self.book_id, self.number, self.title) - @models.permalink def get_absolute_url(self): - return "wiki_editor", [self.book.slug, self.slug] + return reverse("wiki_editor", args=[self.book.slug, self.slug]) def pretty_name(self, book_length=None): title = self.book.title if self.title: title += ", %s" % self.title - if book_length > 1: + if book_length and book_length > 1: title += " (%d/%d)" % (self.number, book_length) return title @@ -87,11 +84,12 @@ class Chunk(dvcs_models.Document): # State & cache # ============= - def new_publishable(self): + def is_new_publishable(self): change = self.publishable() if not change: return False return not change.publish_log.exists() + new_publishable = cached_in_field('_new_publishable')(is_new_publishable) def is_changed(self): if self.head is None: @@ -103,22 +101,10 @@ class Chunk(dvcs_models.Document): return self.book.hidden() hidden = cached_in_field('_hidden')(is_hidden) - @cached_in_field('_short_html') - def short_html(self): - return render_to_string( - 'catalogue/book_list/chunk.html', {'chunk': self}) - def touch(self): update = { "_changed": self.is_changed(), + "_new_publishable": self.is_new_publishable(), "_hidden": self.is_hidden(), - "_short_html": None, } Chunk.objects.filter(pk=self.pk).update(**update) - refresh_instance(self) - - def refresh(self): - """This should be done offline.""" - self.changed - self.hidden - self.short_html