Example #1
0
 def save(self, *args, **kwargs):
     """Override the default ``save`` method."""
     if not self.status:
         self.status = self.DRAFT
     # Published pages should always have a publication date
     if self.publication_date is None and self.status == self.PUBLISHED:
         self.publication_date = get_now()
     # Drafts should not, unless they have been set to the future
     if self.status == self.DRAFT:
         if settings.PAGE_SHOW_START_DATE:
             if (self.publication_date and
                     self.publication_date <= get_now()):
                 self.publication_date = None
         else:
             self.publication_date = None
     self.last_modification_date = get_now()
     # let's assume there is no more broken links after a save
     cache.delete(self.PAGE_BROKEN_LINK_KEY % self.id)
     super(Page, self).save(*args, **kwargs)
     # fix sites many-to-many link when the're hidden from the form
     if settings.PAGE_HIDE_SITES and self.sites.count() == 0:
         self.sites.add(Site.objects.get(pk=global_settings.SITE_ID))
Example #2
0
    def invalidate(self):
        """Invalidate cached data for this page."""

        cache.delete(self.PAGE_LANGUAGES_KEY % (self.id))
        cache.delete('PAGE_FIRST_ROOT_ID')
        cache.delete(self.CHILDREN_KEY % self.id)
        cache.delete(self.PUB_CHILDREN_KEY % self.id)
        # XXX: Should this have a depth limit?
        if self.parent_id:
            self.parent.invalidate()
        self._languages = None
        self._complete_slug = None
        self._content_dict = dict()

        p_names = [p.name for p in get_placeholders(self.get_template())]
        if 'slug' not in p_names:
            p_names.append('slug')
        if 'title' not in p_names:
            p_names.append('title')
        # delete content cache, frozen or not
        for name in p_names:
            # frozen
            cache.delete(PAGE_CONTENT_DICT_KEY %
                (self.id, name, 1))
            # not frozen
            cache.delete(PAGE_CONTENT_DICT_KEY %
                (self.id, name, 0))

        cache.delete(self.PAGE_URL_KEY % (self.id))
Example #3
0
 def invalidate(self, content_type):
     key = ContentManager.PAGE_CONTENT_DICT_KEY % (
         self.id, content_type, 0)
     cache.delete(key)
     self._content_dict = None
Example #4
0
    def invalidate(self):
        """Invalidate cached data for this page."""

        cache.delete(self.PAGE_LANGUAGES_KEY % (self.pk))
        cache.delete('PAGE_FIRST_ROOT_ID')
        cache.delete(self.CHILDREN_KEY % self.pk)
        cache.delete(self.PUB_CHILDREN_KEY % self.pk)
        # XXX: Should this have a depth limit?
        if self.parent_id:
            self.parent.invalidate()
        self._languages = None
        self._complete_slug = None
        self._content_dict = dict()

        placeholders = get_placeholders(self.get_template())

        p_names = [p.ctype for p in placeholders]
        if 'slug' not in p_names:
            p_names.append('slug')
        if 'title' not in p_names:
            p_names.append('title')

        from pages.managers import fake_page
        shared = [p for p in placeholders if p.shared]
        for share in shared:
            fake_page.invalidate(share.ctype)

        # delete content cache, frozen or not
        for name in p_names:
            # frozen
            cache.delete(
                PAGE_CONTENT_DICT_KEY %
                (self.pk, name, 1))
            # not frozen
            cache.delete(
                PAGE_CONTENT_DICT_KEY %
                (self.pk, name, 0))

        cache.delete(self.PAGE_URL_KEY % (self.pk))
Example #5
0
 def invalidate(self):
     content = self.get_content('slug')
     for obj in content:
         cache_key = settings.PAGES_PAGE_CACHE_KEY + obj.language + ':' + obj.slug
         cache_key_version = settings.PAGES_PAGE_VERSION_KEY + obj.language + ':' + obj.slug
         cache_version = str(cache.get(cache_key_version))
         if cache_version is None:
             cache.set(cache_key_version, 1, settings.PAGES_PAGE_CACHE_TIMEOUT)
             cache_version = 1
         try:
             cache.incr(cache_key_version, 1)
             if settings.PAGES_CACHE_DELETE:
                 # try delete cache for anonymous and authenticated users
                 cache_key_yauth = cache_key + ':' + 'True'
                 cache_key_nauth = cache_key + ':' + 'False'
                 cache.delete(cache_key_yauth, version=cache_version)
                 cache.delete(cache_key_nauth, version=cache_version)
                 cache.delete(cache_key_yauth + 'content', version=cache_version)
                 cache.delete(cache_key_nauth + 'content', version=cache_version)
                 cache.delete(cache_key_yauth + 'ext_content', version=cache_version)
                 cache.delete(cache_key_nauth + 'ext_content', version=cache_version)
                 cache.delete(cache_key_yauth + 'redirect', version=cache_version)
                 cache.delete(cache_key_nauth + 'redirect', version=cache_version)
         except ValueError:
             cache.set(cache_key_version, 1, settings.PAGES_PAGE_CACHE_TIMEOUT)
Example #6
0
 def invalidate(self, content_type):
     key = ContentManager.PAGE_CONTENT_DICT_KEY % (self.id, content_type, 0)
     cache.delete(key)
     self._content_dict = None