Skip to content

Commit

Permalink
Mets les bons liens sur la page principale d'un contenu
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud-D committed Jun 27, 2021
1 parent f5a9952 commit e9964c6
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 12 deletions.
63 changes: 63 additions & 0 deletions templates/tutorialv2/includes/shared_content_child.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{% load emarkdown %}
{% load i18n %}
{% load times %}
{% load target_tree %}

{% if not hide_title %}
<h2 id="{{ child.position_in_parent }}-{{ child.slug }}">
<a href="{{ child.get_relative_url }}">
{{ child.title }}
</a>
</h2>
{% endif %}
{% if child.text %}
{# child is an extract #}
{% if child.get_text.strip|length == 0 %}
<p class="ico-after warning">
{% trans "Cette section est actuellement vide." %}
</p>
{% else %}
<div class="extract-wrapper">
{{ child.get_text|emarkdown:is_js }}
</div>
{% endif %}
{% else %}
{# child is a container #}

{% if child.has_extracts %}
<ol>
{% for extract in child.children %}
<li>
<a href="{{ extract.container.get_relative_url }}#{{ extract.position_in_parent }}-{{ extract.slug }}">{{ extract.title }}</a>
</li>
{% endfor %}
</ol>
{% elif child.has_sub_containers %}
<ol class="summary-part">
{% for subchild in child.children %}
<li>
<h3>
<a
href="{{ subchild.get_relative_url }}"

>{{ subchild.title }}</a>
</h3>
<ol class="summary-part">
{% for extract in subchild.children %}
<li>
<h4>
<a href="{{ extract.container.get_relative_url }}#{{ extract.position_in_parent }}-{{ extract.slug }}">{{ extract.title }}</a>
</h4>
</li>
{% endfor %}
</ol>
</li>
{% endfor %}
</ol>
{% endif %}
{% endif %}


{% if not child.has_sub_containers %}
</li>
{% endif %}
92 changes: 90 additions & 2 deletions templates/tutorialv2/view/shared_content.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,96 @@
{% extends "tutorialv2/base.html" %}
{% extends "tutorialv2/base_online.html" %}
{% load i18n %}
{% load captureas %}

{% block title %}
{{ content.title }}
{% endblock %}

{% block breadcrumb %}
<li>{{ content.title }}</li>
{% endblock %}

{% block headline %}
{% if content.licence %}
<span class="license" itemprop="license">
{{ content.licence }}
</span>
{% endif %}

<h1 {% if content.image %}class="illu"{% endif %} itemprop="name">
{% if content.image %}
<img src="{{ content.image.physical.tutorial_illu.url }}" alt="" itemprop="thumbnailUrl">
{% endif %}
{{ content.title }}
</h1>

{% if content.description %}
<h2 class="subtitle" itemprop="description">
{{ content.description }}
</h2>
{% 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 %}
<div class="alert-box info">
{% blocktrans with url_article=content.converted_to.get_absolute_url_online %}
Ce billet a été promu en <a href="{{ url_article }}">article</a>.
{% endblocktrans %}
</div>
{% elif is_staff %}
<div class="alert-box info">
{% blocktrans with url_article=content.converted_to.get_absolute_url %}
Ce billet a fait l’objet d’une demande de publication <a href="{{ url_article }}">en tant qu’article</a>. Il est donc présent dans la zone de validation en attente de prise en charge par un validateur.
{% endblocktrans %}
</div>
{% 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 %}
<ol class="summary-part">
{% 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 %}
</ol>
{% endif %}

<hr class="clearfix" />
<hr />

{% 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 %}
3 changes: 3 additions & 0 deletions zds/tutorialv2/models/versioned.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
22 changes: 12 additions & 10 deletions zds/tutorialv2/views/shared_content.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit e9964c6

Please sign in to comment.