Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importer une nouvelle version d'un contenu ne mélange plus les introductions et conclusions #6350

Merged
merged 2 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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