X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/e977f7187b10b1bc0a30794cd585c6b840568996..ad422879d55a62e02c71024531aa4a2277dedaf3:/src/documents/models/chunk.py?ds=sidebyside diff --git a/src/documents/models/chunk.py b/src/documents/models/chunk.py index 39a20871..4d8f6d23 100644 --- a/src/documents/models/chunk.py +++ b/src/documents/models/chunk.py @@ -6,7 +6,7 @@ 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 django.utils.translation import gettext_lazy as _ from documents.helpers import cached_in_field from documents.managers import VisibleManager from dvcs import models as dvcs_models @@ -23,9 +23,9 @@ class Chunk(dvcs_models.Document): gallery_start = models.IntegerField(_('gallery start'), null=True, blank=True, default=1) # cache - _hidden = models.NullBooleanField(editable=False) - _changed = models.NullBooleanField(editable=False) - _new_publishable = models.NullBooleanField(editable=False) + _hidden = models.BooleanField(editable=False, null=True) + _changed = models.BooleanField(editable=False, null=True) + _new_publishable = models.BooleanField(editable=False, null=True) # managers objects = models.Manager() @@ -39,6 +39,20 @@ class Chunk(dvcs_models.Document): verbose_name_plural = _('chunks') permissions = [('can_pubmark', 'Can mark for publishing')] + @classmethod + def get_visible_for(cls, user): + qs = cls.objects.all() + if not user.is_authenticated: + qs = qs.filter(book__public=True) + return qs + + @classmethod + def get_revisions_visible_for(cls, user): + qs = cls.change_model.objects.all() + if not user.is_authenticated: + qs = qs.filter(tree__book__public=True) + return qs + # Representing # ============