from django.db import models from django.utils.encoding import force_text from django.utils.text import Truncator from cms.models import Page from .utils import strip_tags LANGUAGE = 'ru' class PageProxy(Page): """Proxy model for Page. Add a prefix `proxy_` to method names to avoid base class override. """ class Meta: proxy = True def proxy_get_content(self): if getattr(self, '_cache_content', None) is None: content = [ plugin.render_plugin().strip() for placeholder in self.placeholders.all() for plugin in placeholder.get_plugins() if plugin.plugin_type == u'TextPlugin' ] self._cache_content = strip_tags(' '.join(content).strip()) return self._cache_content def proxy_get_teaser(self): if getattr(self, '_cache_teaser', None) is None: self._cache_teaser = Truncator(self.proxy_get_content()).chars(500) return self._cache_teaser def proxy_get_title(self): return super(PageProxy, self).get_title(language=LANGUAGE) def proxy_get_path(self): return super(PageProxy, self).get_path(language=LANGUAGE)