From df0c1b057bc7f81dd11404fe4c8396f9ca99458b Mon Sep 17 00:00:00 2001 From: Arnaud-D <35631001+Arnaud-D@users.noreply.github.com> Date: Sun, 27 Jun 2021 21:57:11 +0200 Subject: [PATCH] =?UTF-8?q?Petites=20avanc=C3=A9es=20sur=20l'affichage=20d?= =?UTF-8?q?es=20contenus=20partag=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../includes/shared_content_child.html | 2 +- .../tutorialv2/view/shared_container.html | 98 +++++++++++++++++++ templates/tutorialv2/view/shared_content.html | 3 +- zds/tutorialv2/models/versioned.py | 3 + zds/tutorialv2/urls/urls_contents.py | 15 ++- zds/tutorialv2/views/shared_content.py | 38 +++++-- 6 files changed, 147 insertions(+), 12 deletions(-) create mode 100644 templates/tutorialv2/view/shared_container.html 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 @@

{% else %}
- {{ child.get_text|emarkdown:is_js }} + {{ child.get_text|emarkdown }}
{% endif %} {% else %} diff --git a/templates/tutorialv2/view/shared_container.html b/templates/tutorialv2/view/shared_container.html new file mode 100644 index 0000000000..4c2dfcdc47 --- /dev/null +++ b/templates/tutorialv2/view/shared_container.html @@ -0,0 +1,98 @@ +{% extends "tutorialv2/base.html" %} +{% load set %} +{% load thumbnail %} +{% load emarkdown %} +{% load i18n %} +{% load times %} +{% load feminize %} +{% load pluralize_fr %} + +{% block title %} + {{ container.title }} - {{ content.title }} +{% endblock %} + + + +{% block breadcrumb %} + + {% if container.parent.parent %} +
  • + {{ container.parent.parent.title }} +
  • + {% endif %} + + {% if container.parent %} +
  • + {{ container.parent.title }} +
  • + {% endif %} + +
  • {{ container.title }}
  • + +{% endblock %} + + +{% block headline %} + + {% if content.licence %} +

    {{ content.licence }}

    + {% endif %} + +

    {{ container.title }}

    + + {% include 'tutorialv2/includes/tags_authors.part.html' with publishablecontent=content online=False %} + +{% endblock %} + + +{% block content %} + + {% include "tutorialv2/includes/chapter_pager.part.html" with position="top" %} + + {% if container.introduction and container.get_introduction %} + {{ container.get_introduction|emarkdown:is_js }} + {% endif %} + + {% if container.has_extracts %} + + {% endif %} + + {% for child in container.children %} + {% include "tutorialv2/includes/shared_content_child.html" with child=child %} + {% empty %} + {% if not container.is_chapter %} +
    +

    + {{ "Ce"|feminize:container.get_level_as_string }} {{ container.get_level_as_string|lower }} {% trans " est actuellement vide." %} +

    +
    + {% endif %} + {% endfor %} + +
    + + {% if container.conclusion and container.get_conclusion %} + {{ container.get_conclusion|emarkdown }} + {% endif %} + + {% include "tutorialv2/includes/chapter_pager.part.html" with position="bottom" %} + + {% if content.is_beta and container.has_extracts %} + {% include "tutorialv2/includes/warn_typo.part.html" with content=content %} + {% endif %} +{% endblock %} + + +{% block sidebar_blocks %} + + {% include "tutorialv2/includes/summary.part.html" with current_container=container %} + +{% endblock %} diff --git a/templates/tutorialv2/view/shared_content.html b/templates/tutorialv2/view/shared_content.html index 5d7ad31c90..bbcaf4535f 100644 --- a/templates/tutorialv2/view/shared_content.html +++ b/templates/tutorialv2/view/shared_content.html @@ -30,7 +30,8 @@

    {% endif %} - {% include 'tutorialv2/includes/tags_authors.part.html' with publishablecontent=content online=False %}{% if content.is_opinion %} + {% include 'tutorialv2/includes/tags_authors.part.html' with publishablecontent=content online=False %} + {% if content.is_opinion %} {% if content.converted_to %} {% if content.converted_to.get_absolute_url_online %}
    diff --git a/zds/tutorialv2/models/versioned.py b/zds/tutorialv2/models/versioned.py index dc00532d36..24672f9b26 100644 --- a/zds/tutorialv2/models/versioned.py +++ b/zds/tutorialv2/models/versioned.py @@ -945,6 +945,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 68e34bd7f3..cce44a81b4 100644 --- a/zds/tutorialv2/urls/urls_contents.py +++ b/zds/tutorialv2/urls/urls_contents.py @@ -11,9 +11,9 @@ DeleteShareableLink, ) from zds.tutorialv2.views.shared_content import DisplaySharedContent -from zds.tutorialv2.views.shareable_links import ListShareableLinks, CreateShareableLink, RevokeShareableLink from zds.tutorialv2.views.events import EventsList from zds.tutorialv2.views.goals import EditGoals +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, @@ -52,6 +52,7 @@ FollowContentReaction, ) + urlpatterns = [ # Flux path("flux/rss/", RedirectView.as_view(pattern_name="publication:feed-rss", permanent=True), name="feed-rss"), @@ -204,5 +205,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)