From e9964c6d63eeb929391f1929b2594f4a90cba5c1 Mon Sep 17 00:00:00 2001
From: Arnaud-D <35631001+Arnaud-D@users.noreply.github.com>
Date: Sun, 27 Jun 2021 18:29:00 +0200
Subject: [PATCH] Mets les bons liens sur la page principale d'un contenu
---
.../includes/shared_content_child.html | 63 +++++++++++++
templates/tutorialv2/view/shared_content.html | 92 ++++++++++++++++++-
zds/tutorialv2/models/versioned.py | 3 +
zds/tutorialv2/views/shared_content.py | 22 +++--
4 files changed, 168 insertions(+), 12 deletions(-)
create mode 100644 templates/tutorialv2/includes/shared_content_child.html
diff --git a/templates/tutorialv2/includes/shared_content_child.html b/templates/tutorialv2/includes/shared_content_child.html
new file mode 100644
index 0000000000..51bd90285c
--- /dev/null
+++ b/templates/tutorialv2/includes/shared_content_child.html
@@ -0,0 +1,63 @@
+{% load emarkdown %}
+{% load i18n %}
+{% load times %}
+{% load target_tree %}
+
+{% if not hide_title %}
+
+{% endif %}
+{% if child.text %}
+ {# child is an extract #}
+ {% if child.get_text.strip|length == 0 %}
+
+ {% trans "Cette section est actuellement vide." %}
+
+ {% else %}
+
+ {% endif %}
+{% else %}
+ {# child is a container #}
+
+ {% if child.has_extracts %}
+
+ {% for extract in child.children %}
+ -
+ {{ extract.title }}
+
+ {% endfor %}
+
+ {% elif child.has_sub_containers %}
+
+ {% for subchild in child.children %}
+ -
+
+
+ {% for extract in subchild.children %}
+ -
+
+
+ {% endfor %}
+
+
+ {% endfor %}
+
+ {% endif %}
+{% endif %}
+
+
+{% if not child.has_sub_containers %}
+
+{% endif %}
diff --git a/templates/tutorialv2/view/shared_content.html b/templates/tutorialv2/view/shared_content.html
index 316c7455b8..5d7ad31c90 100644
--- a/templates/tutorialv2/view/shared_content.html
+++ b/templates/tutorialv2/view/shared_content.html
@@ -1,8 +1,96 @@
-{% extends "tutorialv2/base.html" %}
+{% extends "tutorialv2/base_online.html" %}
{% load i18n %}
+{% load captureas %}
+
+{% block title %}
+ {{ content.title }}
+{% endblock %}
+
+{% block breadcrumb %}
+ {{ content.title }}
+{% endblock %}
+
+{% block headline %}
+ {% if content.licence %}
+
+ {{ content.licence }}
+
+ {% endif %}
+
+
+ {% if content.image %}
+
+ {% endif %}
+ {{ content.title }}
+
+
+ {% if content.description %}
+
+ {{ content.description }}
+
+ {% endif %}
+
+ {% 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 %}
+
+ {% blocktrans with url_article=content.converted_to.get_absolute_url_online %}
+ Ce billet a été promu en
article.
+ {% endblocktrans %}
+
+ {% elif is_staff %}
+
+ {% blocktrans with url_article=content.converted_to.get_absolute_url %}
+ Ce billet a fait l’objet d’une demande de publication
en tant qu’article. Il est donc présent dans la zone de validation en attente de prise en charge par un validateur.
+ {% endblocktrans %}
+
+ {% endif %}
+ {% endif %}
+ {% endif %}
+
+{% endblock %}
{% block content %}
-Contenu : {{ content.title }}
+ {% captureas content_pager %}
+ {% include "tutorialv2/includes/content_pager.part.html" with content=content %}
+ {% endcaptureas %}
+
+ {{ content_pager }}
+
+ {% if content.has_extracts %}
+ {{ content.get_content_online|safe }}
+ {% else %}
+ {% if content.introduction %}
+ {{ content.get_introduction|default:""|safe }}
+ {% endif %}
+
+ {% if not content.has_sub_containers %}
+
+ {% endif %}
+
+ {% captureas url %}
+ {% url "content:shareable-link" link.id %}
+ {% endcaptureas %}
+
+ {% for child in content.children %}
+ {% include "tutorialv2/includes/shared_content_child.html" with url=url child=child %}
+ {% endfor %}
+
+ {% if not content.has_sub_containers %}
+
+ {% endif %}
+
+
+
+
+ {% if content.conclusion %}
+ {{ content.get_conclusion_online|default:""|safe }}
+ {% endif %}
+
+ {% endif %}
+ {{ content_pager }}
+ {% include "tutorialv2/includes/alert.html" with content=content current_content_type=current_content_type %}
+ {% include "tutorialv2/includes/warn_typo.part.html" with content=content %}
{% endblock %}
diff --git a/zds/tutorialv2/models/versioned.py b/zds/tutorialv2/models/versioned.py
index e4b9eea29f..29250d2de9 100644
--- a/zds/tutorialv2/models/versioned.py
+++ b/zds/tutorialv2/models/versioned.py
@@ -359,6 +359,9 @@ def get_absolute_url(self):
"""
return self.top_container().get_absolute_url() + self.get_path(relative=True, os_sensitive=False) + "/"
+ def get_relative_url(self):
+ return self.get_path(relative=True, os_sensitive=False) + "/"
+
def get_absolute_url_online(self):
"""
diff --git a/zds/tutorialv2/views/shared_content.py b/zds/tutorialv2/views/shared_content.py
index 36bae47edc..7ce529cd0f 100644
--- a/zds/tutorialv2/views/shared_content.py
+++ b/zds/tutorialv2/views/shared_content.py
@@ -1,23 +1,25 @@
from django.core.exceptions import PermissionDenied
from django.shortcuts import get_object_or_404
-from django.views.generic import TemplateView, DetailView
+from django.views.generic import TemplateView
+from zds.tutorialv2.mixins import ContentTypeMixin
from zds.tutorialv2.models.database import ShareableLink
-class DisplaySharedContent(TemplateView):
+class DisplaySharedContent(ContentTypeMixin, TemplateView):
"""View a shared version of a content."""
template_name = "tutorialv2/view/shared_content.html"
- def setup(self, request, *args, **kwargs):
- super().setup(request, *args, **kwargs)
- link = get_object_or_404(ShareableLink, id=kwargs["id"])
- if not link.active:
+ def dispatch(self, request, *args, **kwargs):
+ self.link = get_object_or_404(ShareableLink, id=kwargs["id"])
+ if not self.link.active:
raise PermissionDenied
- self.content = link.content
+ self.content = self.link.content
+ return super().dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
- kwargs = super().get_context_data()
- kwargs["content"] = self.content
- return kwargs
+ versioned_model = self.content.load_version_or_404(sha=self.content.sha_draft, public=self)
+ kwargs["link"] = self.link
+ kwargs["content"] = versioned_model
+ return super().get_context_data(**kwargs)