diff --git a/templates/tutorialv2/includes/shared_content_child.html b/templates/tutorialv2/includes/shared_content_child.html
index 51bd90285c..9450173084 100644
--- a/templates/tutorialv2/includes/shared_content_child.html
+++ b/templates/tutorialv2/includes/shared_content_child.html
@@ -18,7 +18,7 @@
diff --git a/zds/tutorialv2/models/versioned.py b/zds/tutorialv2/models/versioned.py
index 29250d2de9..a0aae91772 100644
--- a/zds/tutorialv2/models/versioned.py
+++ b/zds/tutorialv2/models/versioned.py
@@ -940,6 +940,9 @@ def get_absolute_url(self):
"""
return f"{self.container.get_absolute_url()}#{self.position_in_parent}-{self.slug}"
+ def get_relative_url(self):
+ return f"{self.container.get_relative_url()}#{self.position_in_parent}-{self.slug}"
+
def get_absolute_url_online(self):
"""
:return: the url to access the tutorial when online
diff --git a/zds/tutorialv2/urls/urls_contents.py b/zds/tutorialv2/urls/urls_contents.py
index f81480a70e..f2cea15dc3 100644
--- a/zds/tutorialv2/urls/urls_contents.py
+++ b/zds/tutorialv2/urls/urls_contents.py
@@ -10,7 +10,7 @@
ReactivateShareableLink,
DeleteShareableLink,
)
-from zds.tutorialv2.views.shared_content import DisplaySharedContent
+from zds.tutorialv2.views.shared_content import DisplaySharedContent, DisplaySharedContainer
from zds.tutorialv2.views.validations_contents import ActivateJSFiddleInContent
from zds.tutorialv2.views.containers_extracts import (
CreateContainer,
@@ -49,6 +49,7 @@
FollowContentReaction,
)
+
urlpatterns = [
# Flux
re_path(r"^flux/rss/$", RedirectView.as_view(pattern_name="publication:feed-rss", permanent=True), name="feed-rss"),
@@ -207,5 +208,15 @@
re_path(r"^partage/desactiver/(?P
.+)/$", DeactivateShareableLink.as_view(), name="deactivate-shareable-link"),
re_path(r"^partage/reactiver/(?P.+)/$", ReactivateShareableLink.as_view(), name="reactivate-shareable-link"),
re_path(r"^partage/supprimer/(?P.+)/$", DeleteShareableLink.as_view(), name="delete-shareable-link"),
- re_path(r"^partage/(?P.+)/$", DisplaySharedContent.as_view(), name="shareable-link"),
+ re_path(r"^partage/(?P[^/]+)/$", DisplaySharedContent.as_view(), name="shareable-link"),
+ re_path(
+ r"^partage/(?P[^/]+)/(?P.+)/(?P.+)/$",
+ DisplaySharedContainer.as_view(),
+ name="shareable-link-container",
+ ),
+ re_path(
+ r"^partage/(?P[^/]+)/(?P.+)/$",
+ DisplaySharedContainer.as_view(),
+ name="shareable-link-container",
+ ),
]
diff --git a/zds/tutorialv2/views/shared_content.py b/zds/tutorialv2/views/shared_content.py
index 7ce529cd0f..d387e44910 100644
--- a/zds/tutorialv2/views/shared_content.py
+++ b/zds/tutorialv2/views/shared_content.py
@@ -4,22 +4,44 @@
from zds.tutorialv2.mixins import ContentTypeMixin
from zds.tutorialv2.models.database import ShareableLink
+from zds.tutorialv2.utils import search_container_or_404
-class DisplaySharedContent(ContentTypeMixin, TemplateView):
- """View a shared version of a content."""
+class DisplaySharedContentMixin:
+ """
+ Base behavior for DisplaySharedContent and DisplaySharedContainer.
+ Modify this mixin to change what is common to DisplaySharedContent and DisplaySharedContainer.
+ """
- template_name = "tutorialv2/view/shared_content.html"
-
- def dispatch(self, request, *args, **kwargs):
+ def setup(self, request, *args, **kwargs):
+ super().setup(request, *args, **kwargs)
self.link = get_object_or_404(ShareableLink, id=kwargs["id"])
if not self.link.active:
raise PermissionDenied
self.content = self.link.content
- return super().dispatch(request, *args, **kwargs)
+ self.versioned_content = self.content.load_version_or_404(sha=self.content.sha_draft)
def get_context_data(self, **kwargs):
- versioned_model = self.content.load_version_or_404(sha=self.content.sha_draft, public=self)
kwargs["link"] = self.link
- kwargs["content"] = versioned_model
+ kwargs["content"] = self.versioned_content
+ return super().get_context_data(**kwargs)
+
+
+class DisplaySharedContent(DisplaySharedContentMixin, ContentTypeMixin, TemplateView):
+ """View a shared version of a content (main page)."""
+
+ template_name = "tutorialv2/view/shared_content.html"
+
+
+class DisplaySharedContainer(DisplaySharedContentMixin, ContentTypeMixin, TemplateView):
+ """View a shared version of a content (subpage)."""
+
+ template_name = "tutorialv2/view/shared_container.html"
+
+ def setup(self, request, *args, **kwargs):
+ super().setup(request, *args, **kwargs)
+ self.container = search_container_or_404(self.versioned_content, self.kwargs)
+
+ def get_context_data(self, **kwargs):
+ kwargs["container"] = self.container
return super().get_context_data(**kwargs)