X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/5913c54d19b8f6775633176032161d49f9b2f1aa..f16104e5ce08700745c66caf77c2e6403243059c:/src/catalogue/models/chunk.py diff --git a/src/catalogue/models/chunk.py b/src/catalogue/models/chunk.py index fc3a9eae..4182d08f 100755 --- a/src/catalogue/models/chunk.py +++ b/src/catalogue/models/chunk.py @@ -10,7 +10,6 @@ from django.template.loader import render_to_string 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 @@ -25,9 +24,9 @@ class Chunk(dvcs_models.Document): 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,7 +43,7 @@ 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 @@ -55,7 +54,7 @@ class Chunk(dvcs_models.Document): 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 +86,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 +103,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