-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ajoute les actions nécessaires niveau utilisateur
J'ai fait en sorte que tout soit ajaxifié.
- Loading branch information
Showing
7 changed files
with
105 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
(function ($, undefined) { | ||
$("li").on("click", ".readiness", function (e) { | ||
var url = $(e.target).data("url"); | ||
var readiness = $(e.target).data("is-ready") === "true"; | ||
var csrf = $("input[name=csrfmiddlewaretoken]").val(); | ||
|
||
$.ajax(url, {method: "PUT", data: { | ||
"ready_to_publish": readiness, | ||
"container_slug": $(e.target).data("container-slug"), | ||
"parent_container_slug": $(e.target).data("parent-container-slug") || "" | ||
}, success: function () { | ||
$(e.target).data("is-ready", readiness?"false":"true") | ||
.children("span") | ||
.removeClass("glyphicon-remove-sign") | ||
.removeClass("glyphicon-ok-sign") | ||
.addClass(readiness?"glyphicon-remove-sign":"glyphicon-ok-sign"); | ||
}, headers: { | ||
"X-CSRFToken": csrf | ||
}}); | ||
}); | ||
})($); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
from django.conf.urls import url | ||
|
||
from zds.tutorialv2.api.views import ContentReactionKarmaView | ||
from zds.tutorialv2.api.views import ContentReactionKarmaView, ContainerPublicationReadinessView | ||
|
||
urlpatterns = [ | ||
url(r'^reactions/(?P<pk>\d+)/karma/?$', ContentReactionKarmaView.as_view(), name='reaction-karma'), | ||
url(r'^publication/preparation/(?P<pk>[0-9]+)/', ContainerPublicationReadinessView.as_view(), name='readiness') | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,57 @@ | ||
from django.http import Http404 | ||
from django.utils.translation import gettext as _ | ||
from rest_framework.fields import empty | ||
from rest_framework.generics import UpdateAPIView | ||
from rest_framework.serializers import Serializer, CharField, BooleanField | ||
from rest_framework.permissions import IsAuthenticatedOrReadOnly | ||
from zds.member.api.permissions import CanReadAndWriteNowOrReadOnly, IsNotOwnerOrReadOnly | ||
from zds.member.api.permissions import CanReadAndWriteNowOrReadOnly, IsNotOwnerOrReadOnly, IsStaffUser, IsOwner | ||
from zds.tutorialv2.utils import search_container_or_404 | ||
from zds.utils.api.views import KarmaView | ||
from zds.tutorialv2.models.database import ContentReaction | ||
from zds.tutorialv2.models.database import ContentReaction, PublishableContent | ||
|
||
|
||
class ContainerReadinessSerializer(Serializer): | ||
parent_container_slug = CharField() | ||
container_slug = CharField(required=True) | ||
ready_to_publish = BooleanField(required=True) | ||
|
||
def run_validation(self, data=empty): | ||
init = super().run_validation(data) | ||
if not init: | ||
return init | ||
if not data.get('parent_container_slug', ''): | ||
init.pop('parent_container_slug', '') | ||
return init | ||
|
||
def save(self, **kwargs): | ||
if not self.validated_data: | ||
self.is_valid(True) | ||
versioned = self.instance.load_version() | ||
container = search_container_or_404(versioned, self.validated_data) | ||
container.ready_to_publish = self.validated_data['ready_to_publish'] | ||
sha = versioned.repo_update(versioned.title, versioned.get_introduction(), versioned.get_conclusion(), | ||
commit_message=_('{} est {} à la publication.').format( | ||
container.get_path(True), | ||
_('prêt') if container.ready_to_publish else _('ignoré'))) | ||
PublishableContent.objects.filter(pk=self.instance.pk).update(sha_draft=sha) | ||
|
||
def to_representation(self, instance): | ||
return {} | ||
|
||
|
||
class ContentReactionKarmaView(KarmaView): | ||
queryset = ContentReaction.objects.all() | ||
permission_classes = (IsAuthenticatedOrReadOnly, CanReadAndWriteNowOrReadOnly, IsNotOwnerOrReadOnly) | ||
|
||
|
||
class ContainerPublicationReadinessView(UpdateAPIView): | ||
permission_classes = (IsStaffUser, IsOwner) | ||
serializer_class = ContainerReadinessSerializer | ||
|
||
def get_object(self): | ||
content = PublishableContent.objects.prefetch_related('authors')\ | ||
.filter(pk=int(self.kwargs['pk']))\ | ||
.first() | ||
if not content: | ||
raise Http404() | ||
return content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters