We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
L'export à la demande ne fonctionne pas
Plus précisement, l'export Markdown ne fonctionne pas quand on clique sur le bouton "Exporter le contenu" alors qu'il fonctionne lors de la publication.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `zds/tutorialv2/api/views.py`
Content:
```
1 import contextlib
2 from pathlib import Path
3 
4 from django.http import Http404
5 from django.utils import translation
6 from django.utils.translation import gettext as _
7 from rest_framework import status
8 from rest_framework.fields import empty
9 from rest_framework.generics import UpdateAPIView, ListCreateAPIView, get_object_or_404
10 from rest_framework.response import Response
11 from rest_framework.serializers import Serializer, CharField, BooleanField
12 from rest_framework.permissions import IsAuthenticatedOrReadOnly
13 
14 from zds.member.api.permissions import CanReadAndWriteNowOrReadOnly, IsNotOwnerOrReadOnly, IsAuthorOrStaff
15 from zds.tutorialv2.publication_utils import PublicatorRegistry
16 from zds.tutorialv2.utils import search_container_or_404
17 from zds.utils.api.views import KarmaView
18 from zds.tutorialv2.models.database import ContentReaction, PublishableContent, PublicationEvent
19 
20 
21 class ContainerReadinessSerializer(Serializer):
22     parent_container_slug = CharField(allow_blank=True, allow_null=True, required=False)
23     container_slug = CharField(required=True)
24     ready_to_publish = BooleanField(required=True)
25 
26     def run_validation(self, data=empty):
27         init = super().run_validation(data)
28         if not init:
29             return init
30         if not data.get('parent_container_slug', ''):
31             init.pop('parent_container_slug', '')
32         return init
33 
34     def save(self, **kwargs):
35         if not self.validated_data:
36             self.is_valid(True)
37         versioned = self.instance.load_version()
38         container = search_container_or_404(versioned, self.validated_data)
39         container.ready_to_publish = self.validated_data['ready_to_publish']
40         sha = versioned.repo_update(versioned.title, versioned.get_introduction(), versioned.get_conclusion(),
41                                     commit_message=_('{} est {} à la publication.').format(
42                                         container.get_path(True),
43                                         _('prêt') if container.ready_to_publish else _('ignoré')))
44         PublishableContent.objects.filter(pk=self.instance.pk).update(sha_draft=sha)
45 
46     def to_representation(self, instance):
47         return {}
48 
49 
50 class ContentReactionKarmaView(KarmaView):
51     queryset = ContentReaction.objects.all()
52     permission_classes = (IsAuthenticatedOrReadOnly, CanReadAndWriteNowOrReadOnly, IsNotOwnerOrReadOnly)
53 
54 
55 class ContainerPublicationReadinessView(UpdateAPIView):
56     permission_classes = (IsAuthorOrStaff, )
57     serializer_class = ContainerReadinessSerializer
58 
59     def get_object(self):
60         content = PublishableContent.objects.prefetch_related('authors')\
61             .filter(pk=int(self.kwargs.get('pk', 0)))\
62             .first()
63         if not content:
64             raise Http404()
65         self.check_object_permissions(self.request, object)
66         return content
67 
68 
69 class ExportView(ListCreateAPIView):
70     permission_classes = (IsAuthorOrStaff,)
71     serializer_class = Serializer
72 
73     def get_queryset(self):
74         return PublicationEvent.objects.filter(published_object__content__pk=self.kwargs.get('pk', 0))
75 
76     def ensure_directories(self, content: PublishableContent):
77         final_directory = Path(content.public_version.get_extra_contents_directory())
78         building_directory = Path(str(final_directory.parent) + '__building', final_directory.name)
79         with contextlib.suppress(FileExistsError):
80             final_directory.mkdir(parents=True)
81         with contextlib.suppress(FileExistsError):
82             building_directory.mkdir(parents=True)
83         return building_directory, final_directory
84 
85     def create(self, request, *args, **kwargs):
86         try:
87             publishable_content = get_object_or_404(PublishableContent.objects, pk=int(kwargs.get('pk')))
88             if not publishable_content.public_version:
89                 raise Http404('Not public content')
90             tmp_dir, _ = self.ensure_directories(publishable_content)
91             versioned = publishable_content.public_version.load_public_version()
92             base_name = str(Path(tmp_dir, versioned.slug))
93             md_file_path = str(Path(tmp_dir, versioned.slug + '.md'))
94 
95             PublicatorRegistry.get('md').publish(md_file_path, base_name,
96                                                  versioned=versioned,
97                                                  cur_language=translation.get_language())
98             PublicatorRegistry.get('watchdog').publish_from_published_content(publishable_content.public_version)
99         except ValueError:
100             return Response({}, status=status.HTTP_400_BAD_REQUEST, headers={})
101         else:
102             return Response({}, status=status.HTTP_201_CREATED, headers={})
103
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/zds/tutorialv2/api/views.py b/zds/tutorialv2/api/views.py
--- a/zds/tutorialv2/api/views.py
+++ b/zds/tutorialv2/api/views.py
@@ -88,7 +88,7 @@
             if not publishable_content.public_version:
                 raise Http404('Not public content')
             tmp_dir, _ = self.ensure_directories(publishable_content)
-            versioned = publishable_content.public_version.load_public_version()
+            versioned = publishable_content.load_version(public=True)
             base_name = str(Path(tmp_dir, versioned.slug))
             md_file_path = str(Path(tmp_dir, versioned.slug + '.md'))

{"golden_diff": "diff --git a/zds/tutorialv2/api/views.py b/zds/tutorialv2/api/views.py\n--- a/zds/tutorialv2/api/views.py\n+++ b/zds/tutorialv2/api/views.py\n@@ -88,7 +88,7 @@\n             if not publishable_content.public_version:\n                 raise Http404('Not public content')\n             tmp_dir, _ = self.ensure_directories(publishable_content)\n-            versioned = publishable_content.public_version.load_public_version()\n+            versioned = publishable_content.load_version(public=True)\n             base_name = str(Path(tmp_dir, versioned.slug))\n             md_file_path = str(Path(tmp_dir, versioned.slug + '.md'))\n", "issue": "L'export \u00e0 la demande ne fonctionne pas\nPlus pr\u00e9cisement, l'export Markdown ne fonctionne pas quand on clique sur le bouton \"Exporter le contenu\" alors qu'il fonctionne lors de la publication.\n", "before_files": [{"content": "import contextlib\nfrom pathlib import Path\n\nfrom django.http import Http404\nfrom django.utils import translation\nfrom django.utils.translation import gettext as _\nfrom rest_framework import status\nfrom rest_framework.fields import empty\nfrom rest_framework.generics import UpdateAPIView, ListCreateAPIView, get_object_or_404\nfrom rest_framework.response import Response\nfrom rest_framework.serializers import Serializer, CharField, BooleanField\nfrom rest_framework.permissions import IsAuthenticatedOrReadOnly\n\nfrom zds.member.api.permissions import CanReadAndWriteNowOrReadOnly, IsNotOwnerOrReadOnly, IsAuthorOrStaff\nfrom zds.tutorialv2.publication_utils import PublicatorRegistry\nfrom zds.tutorialv2.utils import search_container_or_404\nfrom zds.utils.api.views import KarmaView\nfrom zds.tutorialv2.models.database import ContentReaction, PublishableContent, PublicationEvent\n\n\nclass ContainerReadinessSerializer(Serializer):\n    parent_container_slug = CharField(allow_blank=True, allow_null=True, required=False)\n    container_slug = CharField(required=True)\n    ready_to_publish = BooleanField(required=True)\n\n    def run_validation(self, data=empty):\n        init = super().run_validation(data)\n        if not init:\n            return init\n        if not data.get('parent_container_slug', ''):\n            init.pop('parent_container_slug', '')\n        return init\n\n    def save(self, **kwargs):\n        if not self.validated_data:\n            self.is_valid(True)\n        versioned = self.instance.load_version()\n        container = search_container_or_404(versioned, self.validated_data)\n        container.ready_to_publish = self.validated_data['ready_to_publish']\n        sha = versioned.repo_update(versioned.title, versioned.get_introduction(), versioned.get_conclusion(),\n                                    commit_message=_('{} est {} \u00e0 la publication.').format(\n                                        container.get_path(True),\n                                        _('pr\u00eat') if container.ready_to_publish else _('ignor\u00e9')))\n        PublishableContent.objects.filter(pk=self.instance.pk).update(sha_draft=sha)\n\n    def to_representation(self, instance):\n        return {}\n\n\nclass ContentReactionKarmaView(KarmaView):\n    queryset = ContentReaction.objects.all()\n    permission_classes = (IsAuthenticatedOrReadOnly, CanReadAndWriteNowOrReadOnly, IsNotOwnerOrReadOnly)\n\n\nclass ContainerPublicationReadinessView(UpdateAPIView):\n    permission_classes = (IsAuthorOrStaff, )\n    serializer_class = ContainerReadinessSerializer\n\n    def get_object(self):\n        content = PublishableContent.objects.prefetch_related('authors')\\\n            .filter(pk=int(self.kwargs.get('pk', 0)))\\\n            .first()\n        if not content:\n            raise Http404()\n        self.check_object_permissions(self.request, object)\n        return content\n\n\nclass ExportView(ListCreateAPIView):\n    permission_classes = (IsAuthorOrStaff,)\n    serializer_class = Serializer\n\n    def get_queryset(self):\n        return PublicationEvent.objects.filter(published_object__content__pk=self.kwargs.get('pk', 0))\n\n    def ensure_directories(self, content: PublishableContent):\n        final_directory = Path(content.public_version.get_extra_contents_directory())\n        building_directory = Path(str(final_directory.parent) + '__building', final_directory.name)\n        with contextlib.suppress(FileExistsError):\n            final_directory.mkdir(parents=True)\n        with contextlib.suppress(FileExistsError):\n            building_directory.mkdir(parents=True)\n        return building_directory, final_directory\n\n    def create(self, request, *args, **kwargs):\n        try:\n            publishable_content = get_object_or_404(PublishableContent.objects, pk=int(kwargs.get('pk')))\n            if not publishable_content.public_version:\n                raise Http404('Not public content')\n            tmp_dir, _ = self.ensure_directories(publishable_content)\n            versioned = publishable_content.public_version.load_public_version()\n            base_name = str(Path(tmp_dir, versioned.slug))\n            md_file_path = str(Path(tmp_dir, versioned.slug + '.md'))\n\n            PublicatorRegistry.get('md').publish(md_file_path, base_name,\n                                                 versioned=versioned,\n                                                 cur_language=translation.get_language())\n            PublicatorRegistry.get('watchdog').publish_from_published_content(publishable_content.public_version)\n        except ValueError:\n            return Response({}, status=status.HTTP_400_BAD_REQUEST, headers={})\n        else:\n            return Response({}, status=status.HTTP_201_CREATED, headers={})\n", "path": "zds/tutorialv2/api/views.py"}], "after_files": [{"content": "import contextlib\nfrom pathlib import Path\n\nfrom django.http import Http404\nfrom django.utils import translation\nfrom django.utils.translation import gettext as _\nfrom rest_framework import status\nfrom rest_framework.fields import empty\nfrom rest_framework.generics import UpdateAPIView, ListCreateAPIView, get_object_or_404\nfrom rest_framework.response import Response\nfrom rest_framework.serializers import Serializer, CharField, BooleanField\nfrom rest_framework.permissions import IsAuthenticatedOrReadOnly\n\nfrom zds.member.api.permissions import CanReadAndWriteNowOrReadOnly, IsNotOwnerOrReadOnly, IsAuthorOrStaff\nfrom zds.tutorialv2.publication_utils import PublicatorRegistry\nfrom zds.tutorialv2.utils import search_container_or_404\nfrom zds.utils.api.views import KarmaView\nfrom zds.tutorialv2.models.database import ContentReaction, PublishableContent, PublicationEvent\n\n\nclass ContainerReadinessSerializer(Serializer):\n    parent_container_slug = CharField(allow_blank=True, allow_null=True, required=False)\n    container_slug = CharField(required=True)\n    ready_to_publish = BooleanField(required=True)\n\n    def run_validation(self, data=empty):\n        init = super().run_validation(data)\n        if not init:\n            return init\n        if not data.get('parent_container_slug', ''):\n            init.pop('parent_container_slug', '')\n        return init\n\n    def save(self, **kwargs):\n        if not self.validated_data:\n            self.is_valid(True)\n        versioned = self.instance.load_version()\n        container = search_container_or_404(versioned, self.validated_data)\n        container.ready_to_publish = self.validated_data['ready_to_publish']\n        sha = versioned.repo_update(versioned.title, versioned.get_introduction(), versioned.get_conclusion(),\n                                    commit_message=_('{} est {} \u00e0 la publication.').format(\n                                        container.get_path(True),\n                                        _('pr\u00eat') if container.ready_to_publish else _('ignor\u00e9')))\n        PublishableContent.objects.filter(pk=self.instance.pk).update(sha_draft=sha)\n\n    def to_representation(self, instance):\n        return {}\n\n\nclass ContentReactionKarmaView(KarmaView):\n    queryset = ContentReaction.objects.all()\n    permission_classes = (IsAuthenticatedOrReadOnly, CanReadAndWriteNowOrReadOnly, IsNotOwnerOrReadOnly)\n\n\nclass ContainerPublicationReadinessView(UpdateAPIView):\n    permission_classes = (IsAuthorOrStaff, )\n    serializer_class = ContainerReadinessSerializer\n\n    def get_object(self):\n        content = PublishableContent.objects.prefetch_related('authors')\\\n            .filter(pk=int(self.kwargs.get('pk', 0)))\\\n            .first()\n        if not content:\n            raise Http404()\n        self.check_object_permissions(self.request, object)\n        return content\n\n\nclass ExportView(ListCreateAPIView):\n    permission_classes = (IsAuthorOrStaff,)\n    serializer_class = Serializer\n\n    def get_queryset(self):\n        return PublicationEvent.objects.filter(published_object__content__pk=self.kwargs.get('pk', 0))\n\n    def ensure_directories(self, content: PublishableContent):\n        final_directory = Path(content.public_version.get_extra_contents_directory())\n        building_directory = Path(str(final_directory.parent) + '__building', final_directory.name)\n        with contextlib.suppress(FileExistsError):\n            final_directory.mkdir(parents=True)\n        with contextlib.suppress(FileExistsError):\n            building_directory.mkdir(parents=True)\n        return building_directory, final_directory\n\n    def create(self, request, *args, **kwargs):\n        try:\n            publishable_content = get_object_or_404(PublishableContent.objects, pk=int(kwargs.get('pk')))\n            if not publishable_content.public_version:\n                raise Http404('Not public content')\n            tmp_dir, _ = self.ensure_directories(publishable_content)\n            versioned = publishable_content.load_version(public=True)\n            base_name = str(Path(tmp_dir, versioned.slug))\n            md_file_path = str(Path(tmp_dir, versioned.slug + '.md'))\n\n            PublicatorRegistry.get('md').publish(md_file_path, base_name,\n                                                 versioned=versioned,\n                                                 cur_language=translation.get_language())\n            PublicatorRegistry.get('watchdog').publish_from_published_content(publishable_content.public_version)\n        except ValueError:\n            return Response({}, status=status.HTTP_400_BAD_REQUEST, headers={})\n        else:\n            return Response({}, status=status.HTTP_201_CREATED, headers={})\n", "path": "zds/tutorialv2/api/views.py"}]}