Skip to content

Commit

Permalink
(Export Markdown) Enlève les titres des conteneurs non validés (#6266)
Browse files Browse the repository at this point in the history
* Enlève les titres des conteneurs non validés
* Ajoute un test pour s'assurer que seuls les parties ready_to_publish sont exportées

Co-authored-by: Ph. SW <philippe.milink@gmx.fr>
  • Loading branch information
Situphen and philippemilink authored Mar 27, 2022
1 parent b879b69 commit edfb4ec
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
12 changes: 7 additions & 5 deletions templates/tutorialv2/export/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@
{% endif %}

{% for child in content.children %}
{% if child.ready_to_publish %}
# {{ child.title|safe }}
{% if content.has_extracts %} {# minituto or article #}
{% if content.has_extracts %} {# minituto or article #}
{% if child.text %}{{ child.get_text|safe|shift_heading_1 }}{% endif %}
{% elif child.ready_to_publish %}{# midsize or bigtuto #}
{% else %} {# midsize or bigtuto #}
{% if child.introduction %}{{ child.get_introduction|safe|shift_heading_1 }}{% endif %}
{% for subchild in child.children %}
{% if subchild.ready_to_publish %}
## {{ subchild.title|safe }}

{% if child.has_extracts %} {# midsize tuto #}
{% if subchild.text %}{{ subchild.get_text|safe|shift_heading_2 }}{% endif %}
{% elif subchild.ready_to_publish %}
{% else %} {# bigtuto #}
{% if subchild.introduction %}{{ subchild.get_introduction|safe|shift_heading_2 }}{% endif %}
{% for extract in subchild.children %}

Expand All @@ -33,14 +35,14 @@
---------

{{ conclu }}{% endif %}{% endif %}
{% endif %}{% endfor %}
{% endif %}{% endif %}{% endfor %}
{% if child.conclusion %}
{% captureas conclu %}{{ child.get_conclusion|safe|shift_heading_1 }}{% endcaptureas %}
{% if conclu.strip != '' %}
---------

{{ conclu }}{% endif %}{% endif %}
{% endif %}{% endfor %}
{% endif %}{% endif %}{% endfor %}
{% if content.conclusion %}
{% captureas conclu %}{{ content.get_conclusion|safe }}{% endcaptureas %}
{% if conclu.strip != '' %}
Expand Down
47 changes: 47 additions & 0 deletions zds/tutorialv2/tests/tests_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,53 @@ def test_publish_content_big_tuto(self):
self.assertIsNone(chapter.introduction)
self.assertIsNone(chapter.conclusion)

def test_export_only_ready_to_publish(self):
"""
Test exported contents contain only ready_to_publish==True parts.
"""
# Medium-size tutorial
midsize_tuto = PublishableContentFactory(type="TUTORIAL")

midsize_tuto.authors.add(self.user_author)
UserGalleryFactory(gallery=midsize_tuto.gallery, user=self.user_author, mode="W")
midsize_tuto.licence = self.licence
midsize_tuto.save()

# populate with 3 chapters (1 extract each), one not being ready for pubication
midsize_tuto_draft = midsize_tuto.load_version()
chapter1 = ContainerFactory(parent=midsize_tuto_draft, db_object=midsize_tuto, title="Chapter 1 ready")
ExtractFactory(container=chapter1, db_object=midsize_tuto)
chapter2 = ContainerFactory(parent=midsize_tuto_draft, db_object=midsize_tuto, title="Chapter 2 ready")
ExtractFactory(container=chapter2, db_object=midsize_tuto)
chapter3 = ContainerFactory(parent=midsize_tuto_draft, db_object=midsize_tuto, title="Chapter 3 not ready")
chapter3.ready_to_publish = False
ExtractFactory(container=chapter3, db_object=midsize_tuto)

# publish it
midsize_tuto = PublishableContent.objects.get(pk=midsize_tuto.pk)
published = publish_content(midsize_tuto, midsize_tuto_draft)
public = midsize_tuto.load_version(sha=published.sha_public, public=published)

# test creation of files:
self.assertTrue(Path(published.get_prod_path()).is_dir())
self.assertTrue(Path(published.get_prod_path(), "manifest.json").is_file())

self.assertTrue(Path(public.get_prod_path(), public.introduction).is_file())
self.assertTrue(Path(public.get_prod_path(), public.conclusion).is_file())

self.assertEqual(len(public.children), 2)
for child in public.children:
self.assertTrue(os.path.isfile(child.get_prod_path())) # an HTML file for each chapter
self.assertIsNone(child.introduction)
self.assertIsNone(child.conclusion)

self.assertTrue(published.has_md())
with Path(published.get_extra_contents_directory(), published.content_public_slug + ".md").open("r") as md:
content = md.read()
self.assertIn(chapter1.title, content)
self.assertIn(chapter2.title, content)
self.assertNotIn(chapter3.title, content)

def test_tagged_tree_extract(self):
midsize = PublishableContentFactory(author_list=[self.user_author])
midsize_draft = midsize.load_version()
Expand Down

0 comments on commit edfb4ec

Please sign in to comment.