Skip to content

Commit

Permalink
Importer une nouvelle version d'un contenu ne supprime plus l'intro e…
Browse files Browse the repository at this point in the history
…t la conclu
  • Loading branch information
Situphen committed Jul 5, 2022
1 parent b9e68a8 commit 26c808a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
6 changes: 5 additions & 1 deletion zds/tutorialv2/models/versioned.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,9 @@ def repo_update(self, title, introduction, conclusion, commit_message="", do_com
if do_commit:
return self.top_container().commit_changes(commit_message)

def repo_add_container(self, title, introduction, conclusion, commit_message="", do_commit=True, slug=None):
def repo_add_container(
self, title, introduction, conclusion, commit_message="", do_commit=True, slug=None, ready_to_publish=None
):
"""
:param title: title of the new container
:param introduction: text of its introduction
Expand Down Expand Up @@ -610,6 +612,8 @@ def repo_add_container(self, title, introduction, conclusion, commit_message="",
if not commit_message:
commit_message = _("Création du conteneur « {} »").format(title)

if ready_to_publish is not None:
subcontainer.ready_to_publish = ready_to_publish
return subcontainer.repo_update(
title, introduction, conclusion, commit_message=commit_message, do_commit=do_commit
)
Expand Down
8 changes: 7 additions & 1 deletion zds/tutorialv2/tests/tests_views/tests_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -1803,6 +1803,9 @@ def test_import_ready_to_publish(self):
content.sha_draft = sha
content.save()

original_intro = versioned.get_introduction()
original_conclu = versioned.get_conclusion()

# Download archive of initial state for content
result = self.client.get(reverse("content:download-zip", args=[content.pk, content.slug]), follow=False)
self.assertEqual(result.status_code, 200)
Expand All @@ -1814,7 +1817,7 @@ def test_import_ready_to_publish(self):
# Failure to import this information defaults also to True, this is to make sure.
versioned.children[0].children[0].ready_to_publish = True
versioned.children[1].ready_to_publish = True
sha = versioned.repo_update_top_container(content.title, content.slug, "introduction", "conclusion")
sha = versioned.repo_update_top_container(content.title, content.slug, original_intro, original_conclu)
content.sha_draft = sha
content.save()

Expand All @@ -1833,6 +1836,9 @@ def test_import_ready_to_publish(self):
self.assertFalse(versioned.children[0].children[0].ready_to_publish)
self.assertFalse(versioned.children[1].ready_to_publish)

self.assertEqual(original_intro, versioned.get_introduction())
self.assertEqual(original_conclu, versioned.get_conclusion())

def test_display_history(self):
"""Test DisplayHistory view"""

Expand Down
11 changes: 8 additions & 3 deletions zds/tutorialv2/views/archives.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,14 @@ def update_from_new_version_in_zip(copy_to, copy_from, zip_file):
except UnicodeDecodeError:
raise BadArchiveError(_(f"Le fichier « {child.conclusion} » n'est pas encodé en UTF-8"))

copy_to.repo_add_container(child.title, introduction, conclusion, do_commit=False, slug=child.slug)
copy_to.children[-1].ready_to_publish = child.ready_to_publish
copy_to.repo_update(copy_to.title, introduction, conclusion, do_commit=False)
copy_to.repo_add_container(
child.title,
introduction,
conclusion,
do_commit=False,
slug=child.slug,
ready_to_publish=child.ready_to_publish,
)
UpdateContentWithArchive.update_from_new_version_in_zip(copy_to.children[-1], child, zip_file)

elif isinstance(child, Extract):
Expand Down

0 comments on commit 26c808a

Please sign in to comment.