Skip to content

Commit

Permalink
Petites avancées sur l'affichage des contenus partagés
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud-D committed Jun 27, 2021
1 parent e9964c6 commit e48def2
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 12 deletions.
2 changes: 1 addition & 1 deletion templates/tutorialv2/includes/shared_content_child.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h2 id="{{ child.position_in_parent }}-{{ child.slug }}">
</p>
{% else %}
<div class="extract-wrapper">
{{ child.get_text|emarkdown:is_js }}
{{ child.get_text|emarkdown }}
</div>
{% endif %}
{% else %}
Expand Down
98 changes: 98 additions & 0 deletions templates/tutorialv2/view/shared_container.html
Original file line number Diff line number Diff line change
@@ -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 %}
<li>
<a href="{{ container.parent.parent.get_absolute_url }}">{{ container.parent.parent.title }}</a>
</li>
{% endif %}

{% if container.parent %}
<li>
<a href="{{ container.parent.get_absolute_url }}">{{ container.parent.title }}</a>
</li>
{% endif %}

<li>{{ container.title }}</li>

{% endblock %}


{% block headline %}

{% if content.licence %}
<p class="license">{{ content.licence }}</p>
{% endif %}

<h1>{{ container.title }}</h1>

{% 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 %}
<ul>
{% for extract in container.children %}
<li>
<a href="#{{ extract.position_in_parent }}-{{ extract.slug }}">
{{ extract.title }}
</a>
</li>
{% endfor %}
</ul>
{% endif %}

{% for child in container.children %}
{% include "tutorialv2/includes/shared_content_child.html" with child=child %}
{% empty %}
{% if not container.is_chapter %}
<div class="ico-after warning">
<p>
{{ "Ce"|feminize:container.get_level_as_string }} {{ container.get_level_as_string|lower }} {% trans " est actuellement vide." %}
</p>
</div>
{% endif %}
{% endfor %}

<hr />

{% 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 %}
3 changes: 2 additions & 1 deletion templates/tutorialv2/view/shared_content.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ <h2 class="subtitle" itemprop="description">
</h2>
{% 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 %}
<div class="alert-box info">
Expand Down
3 changes: 3 additions & 0 deletions zds/tutorialv2/models/versioned.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions zds/tutorialv2/urls/urls_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -207,5 +208,15 @@
re_path(r"^partage/desactiver/(?P<id>.+)/$", DeactivateShareableLink.as_view(), name="deactivate-shareable-link"),
re_path(r"^partage/reactiver/(?P<id>.+)/$", ReactivateShareableLink.as_view(), name="reactivate-shareable-link"),
re_path(r"^partage/supprimer/(?P<id>.+)/$", DeleteShareableLink.as_view(), name="delete-shareable-link"),
re_path(r"^partage/(?P<id>.+)/$", DisplaySharedContent.as_view(), name="shareable-link"),
re_path(r"^partage/(?P<id>[^/]+)/$", DisplaySharedContent.as_view(), name="shareable-link"),
re_path(
r"^partage/(?P<id>[^/]+)/(?P<parent_container_slug>.+)/(?P<container_slug>.+)/$",
DisplaySharedContainer.as_view(),
name="shareable-link-container",
),
re_path(
r"^partage/(?P<id>[^/]+)/(?P<container_slug>.+)/$",
DisplaySharedContainer.as_view(),
name="shareable-link-container",
),
]
38 changes: 30 additions & 8 deletions zds/tutorialv2/views/shared_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit e48def2

Please sign in to comment.