Esempio n. 1
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))
Esempio n. 2
0
def modify_placeholder(request, page_id):
    """Modify the content of a page."""
    content_type = request.GET.get('content_type')
    language_id = request.GET.get('language_id')
    page = get_object_or_404(Page, pk=page_id)
    perm = request.user.has_perm('pages.change_page')
    if perm and request.method == 'POST':
        placeholders = get_placeholders(page.get_template())
        for placeholder in placeholders:
            if placeholder.name == content_type:
                initial = placeholder.get_content(page,
                                                  language_id,
                                                  lang_fallback=False)
                form = forms.Form(request.POST, request.FILES)
                form.fields[content_type] = placeholder.get_field(
                    page, language_id, initial=initial)
                if not form.is_valid():
                    return HttpResponse(form.as_p())

                if placeholder.shared:
                    save_page = None
                else:
                    save_page = page

                extra_data = placeholder.get_extra_data(form.data)

                placeholder.save(save_page, language_id,
                                 form.cleaned_data[content_type], True,
                                 extra_data)
                if save_page:
                    page.invalidate()
                    # to update last modification date
                    page.save()
                else:
                    fake_page.invalidate(content_type)

                return HttpResponse('ok')
        raise Http404("Content type not found in placeholders")

    raise Http404
Esempio n. 3
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()

        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:
            print(share.ctype)
            fake_page.invalidate(share.ctype)

        # 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))
Esempio n. 4
0
def modify_placeholder(request, page_id):
    """Modify the content of a page."""
    content_type = request.GET.get('content_type')
    language_id = request.GET.get('language_id')
    page = get_object_or_404(Page, pk=page_id)
    perm = request.user.has_perm('pages.change_page')
    if perm and request.method == 'POST':
        placeholders = get_placeholders(page.get_template())
        for placeholder in placeholders:
            if placeholder.name == content_type:
                initial = placeholder.get_content(
                    page, language_id, lang_fallback=False)
                form = forms.Form(request.POST, request.FILES)
                form.fields[content_type] = placeholder.get_field(
                    page, language_id, initial=initial)
                if not form.is_valid():
                    return HttpResponse(form.as_p())

                if placeholder.shared:
                    save_page = None
                else:
                    save_page = page

                extra_data = placeholder.get_extra_data(form.data)

                placeholder.save(
                    save_page, language_id,
                    form.cleaned_data[content_type], True, extra_data)
                if save_page:
                    page.invalidate()
                    # to update last modification date
                    page.save()
                else:
                    fake_page.invalidate(content_type)

                return HttpResponse('ok')
        raise Http404("Content type not found in placeholders")

    raise Http404
Esempio n. 5
0
def modify_content(request, page_id, content_type, language_id):
    """Modify the content of a page."""
    page = get_object_or_404(Page, pk=page_id)
    perm = request.user.has_perm('pages.change_page')
    if perm and request.method == 'POST':
        content = request.POST.get('content', False)
        if not content:
            raise Http404
        if settings.PAGE_CONTENT_REVISION:
            Content.objects.create_content_if_changed(page, language_id,
                                                      content_type, content)
        else:
            Content.objects.set_or_create_content(page, language_id,
                                                  content_type, content)
        if page:
            page.invalidate()
            # to update last modification date
            page.save()
        else:
            fake_page.invalidate(content_type)

        return HttpResponse('ok')
    raise Http404
Esempio n. 6
0
def modify_content(request, page_id, content_type, language_id):
    """Modify the content of a page."""
    page = get_object_or_404(Page, pk=page_id)
    perm = request.user.has_perm('pages.change_page')
    if perm and request.method == 'POST':
        content = request.POST.get('content', False)
        if not content:
            raise Http404
        if settings.PAGE_CONTENT_REVISION:
            Content.objects.create_content_if_changed(page, language_id,
                                                      content_type, content)
        else:
            Content.objects.set_or_create_content(page, language_id,
                                                  content_type, content)
        if page:
            page.invalidate()
            # to update last modification date
            page.save()
        else:
            fake_page.invalidate(content_type)

        return HttpResponse('ok')
    raise Http404