Esempio n. 1
0
    def get_content(self, language=None, show_draft_content=False):
        if not language:
            language = get_current_language()

        try:
            return self._content_cache[language]
        except KeyError:
            qs = self.contents.select_related(
                'alias__category', ).prefetch_related('placeholders').filter(
                    language=language)

            if show_draft_content and is_versioning_enabled():
                from djangocms_versioning.constants import DRAFT, PUBLISHED
                from djangocms_versioning.helpers import remove_published_where

                # Ensure that we are getting the latest valid content, the top most version can become
                # archived with a previous version re-published
                qs = remove_published_where(qs)
                qs = qs.filter(
                    Q(versions__state=DRAFT)
                    | Q(versions__state=PUBLISHED)).order_by(
                        '-versions__created')

            self._content_cache[language] = qs.first()
            return self._content_cache[language]
Esempio n. 2
0
    def test_versioned_queryset_return_full_with_helper_method(self):
        """With an extra helper method we can return the full queryset"""
        factories.PollVersionFactory()
        normal_count = PollContent.objects.all()
        full_count = remove_published_where(PollContent.objects.all())

        self.assertEqual(normal_count.count(), 0)
        self.assertEqual(full_count.count(), 1)
Esempio n. 3
0
    def get_languages(self):
        if not self._content_languages_cache:
            queryset = self.contents.all()

            if is_versioning_enabled():
                from djangocms_versioning.helpers import remove_published_where
                queryset = remove_published_where(queryset)

            self._content_languages_cache = queryset.values_list('language',
                                                                 flat=True)
        return self._content_languages_cache
Esempio n. 4
0
    def get_content(self, show_draft_content=False):
        qs = self.get_content_queryset()

        if show_draft_content and is_versioning_enabled():
            from djangocms_versioning.constants import DRAFT, PUBLISHED
            from djangocms_versioning.helpers import remove_published_where

            # Ensure that we are getting the latest valid content, the top most version can become
            # archived with a previous version re-published
            qs = remove_published_where(qs)
            qs = qs.filter(
                Q(versions__state=DRAFT)
                | Q(versions__state=PUBLISHED)).order_by('-versions__created')
        return qs.first()
Esempio n. 5
0
    def get_content(self, language=None, show_draft_content=False):
        if not language:
            language = get_current_language()

        try:
            return self._content_cache[language]
        except KeyError:
            qs = self.contents.select_related(
                'alias__category', ).prefetch_related('placeholders').filter(
                    language=language)

            if show_draft_content and is_versioning_enabled():
                from djangocms_versioning.helpers import remove_published_where
                qs = remove_published_where(qs)

            self._content_cache[language] = qs.first()
            return self._content_cache[language]
Esempio n. 6
0
def __init__(self, rel, queryset, to_field_name, *args, **kwargs):
    queryset = remove_published_where(queryset)
    init(self, rel, queryset, to_field_name, *args, **kwargs)