From 5ec9a59baf7c58ca811722090d1ba6fe8c943c4e Mon Sep 17 00:00:00 2001 From: artragis Date: Mon, 2 Jan 2017 21:00:58 +0100 Subject: [PATCH 1/2] No more error 500. Fix filter --- zds/tutorialv2/views/views_contents.py | 2 +- zds/tutorialv2/views/views_published.py | 16 +++++++++++----- zds/tutorialv2/views/views_validations.py | 6 ++++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/zds/tutorialv2/views/views_contents.py b/zds/tutorialv2/views/views_contents.py index a12c3021c3..31de0935da 100644 --- a/zds/tutorialv2/views/views_contents.py +++ b/zds/tutorialv2/views/views_contents.py @@ -1724,7 +1724,7 @@ class AddAuthorToContent(LoggedWithReadWriteHability, SingleContentFormViewMixin authorized_for_staff = True already_finished = False - def get(self): + def get(self, request, *args, **kwargs): content = self.get_object() url = 'content:find-{}'.format('tutorial' if content.is_tutorial() else content.type.lower()) return redirect(url, self.request.user) diff --git a/zds/tutorialv2/views/views_published.py b/zds/tutorialv2/views/views_published.py index f3a8a8a054..a642279880 100644 --- a/zds/tutorialv2/views/views_published.py +++ b/zds/tutorialv2/views/views_published.py @@ -10,7 +10,7 @@ from django.core.exceptions import PermissionDenied from django.db import transaction from django.http import Http404, HttpResponsePermanentRedirect, StreamingHttpResponse, HttpResponse -from django.db.models import F +from django.db.models import F, Q from django.shortcuts import get_object_or_404, redirect, render_to_response from django.template.loader import render_to_string from django.utils.datastructures import MultiValueDictKeyError @@ -331,13 +331,18 @@ def get_queryset(self): 'tutorialv2_publishablecontent.id' ) queryset = PublishedContent.objects \ - .filter(must_redirect=False) \ - + .filter(must_redirect=False) + # this condition got more complexe with development of zep13 + # if we do filter by content_type, then every published content can be + # displayed. Othewise, we have to be sure the content was expressly chosen by + # someone with staff authorization. Another way to say it "it has to be a + # validated content (article, tutorial) or a "chosen" opinion. if self.current_content_type: queryset = queryset.filter(content_type=self.current_content_type) else: - queryset = queryset.filter(content__sha_picked=F('sha_public')) - + validated_content_subqueryset = ~Q(content_type="OPINION") |\ + Q(content__sha_picked=F('sha_public')) + queryset = queryset.filter(validated_content_subqueryset) # prefetch: queryset = queryset\ .prefetch_related('content') \ @@ -761,6 +766,7 @@ def post(self, request, *args, **kwargs): class FollowContentReaction(LoggedWithReadWriteHability, SingleOnlineContentViewMixin, FormView): + redirection_is_needed = False def post(self, request, *args, **kwargs): response = {} diff --git a/zds/tutorialv2/views/views_validations.py b/zds/tutorialv2/views/views_validations.py index 9e4642a4de..e2c1f290bb 100644 --- a/zds/tutorialv2/views/views_validations.py +++ b/zds/tutorialv2/views/views_validations.py @@ -589,6 +589,7 @@ class UnpublishOpinion(LoginRequiredMixin, SingleOnlineContentFormViewMixin, NoV """Unpublish an opinion""" form_class = RevokeValidationForm + is_public = True modal_form = True @@ -640,7 +641,7 @@ def form_valid(self, form): class PickOpinion(PermissionRequiredMixin, NoValidationBeforeFormViewMixin): - """Add the opinion in the picked list """ + """Approve and Add the opinion in the picked list """ form_class = PickOpinionForm @@ -747,7 +748,8 @@ def form_valid(self, form): class PromoteOpinionToArticle(PermissionRequiredMixin, NoValidationBeforeFormViewMixin): - """Promote an opinion to article""" + """Promote an opinion to article. this duplicates the opinion and declares + the clone as an article.""" form_class = PromoteOpinionToArticleForm From d0356106ed645a4cd7ab7db5da78bf39658ca76f Mon Sep 17 00:00:00 2001 From: artragis Date: Sun, 8 Jan 2017 17:16:27 +0100 Subject: [PATCH 2/2] =?UTF-8?q?prend=20le=20comportement=20d=C3=A9sir?= =?UTF-8?q?=C3=A9=20sur=20le=20forum.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zds/tutorialv2/views/views_published.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/zds/tutorialv2/views/views_published.py b/zds/tutorialv2/views/views_published.py index a642279880..d1a9f03e0e 100644 --- a/zds/tutorialv2/views/views_published.py +++ b/zds/tutorialv2/views/views_published.py @@ -335,14 +335,13 @@ def get_queryset(self): # this condition got more complexe with development of zep13 # if we do filter by content_type, then every published content can be # displayed. Othewise, we have to be sure the content was expressly chosen by - # someone with staff authorization. Another way to say it "it has to be a - # validated content (article, tutorial) or a "chosen" opinion. + # someone with staff authorization. Another way to say it "it has to be a + # validated content (article, tutorial), `ContentWithoutValidation` live their + # own life in their own page. if self.current_content_type: queryset = queryset.filter(content_type=self.current_content_type) else: - validated_content_subqueryset = ~Q(content_type="OPINION") |\ - Q(content__sha_picked=F('sha_public')) - queryset = queryset.filter(validated_content_subqueryset) + queryset = queryset.filter(~Q(content_type="OPINION")) # prefetch: queryset = queryset\ .prefetch_related('content') \