Skip to content

Commit

Permalink
Permet d'écrire des billets ou articles avec une structure de tutoriel
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud-D committed Dec 24, 2022
1 parent 324f5b4 commit 6a31d96
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
7 changes: 0 additions & 7 deletions zds/tutorialv2/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
# verbose_name_plural User-friendly pluralized type name
# category_name User-friendly category name which contains this content
# requires_validation Boolean; whether this content has to be validated before publication
# single_container Boolean; True if the content is a single container
# beta Boolean; True if the content can be in beta
{
"name": "TUTORIAL",
"verbose_name": "tutoriel",
"verbose_name_plural": "tutoriels",
"category_name": "tutoriel",
"requires_validation": True,
"single_container": False,
"beta": True,
},
{
Expand All @@ -25,7 +23,6 @@
"verbose_name_plural": "articles",
"category_name": "article",
"requires_validation": True,
"single_container": True,
"beta": True,
},
{
Expand All @@ -34,7 +31,6 @@
"verbose_name_plural": "billets",
"category_name": "tribune",
"requires_validation": False,
"single_container": True,
"beta": False,
},
)
Expand All @@ -49,9 +45,6 @@
# a list of contents which have to be validated before publication
CONTENT_TYPES_REQUIRING_VALIDATION = [content["name"] for content in CONTENT_TYPES if content["requires_validation"]]

# a list of contents which have one big container containing at least one small container
SINGLE_CONTAINER_CONTENT_TYPES = [content["name"] for content in CONTENT_TYPES if content["single_container"]]

# a list of contents which can be in beta
CONTENT_TYPES_BETA = [content["name"] for content in CONTENT_TYPES if content["beta"]]

Expand Down
29 changes: 12 additions & 17 deletions zds/tutorialv2/models/versioned.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import contextlib
import copy
from pathlib import Path
from typing import List

from zds import json_handler
from git import Repo
Expand All @@ -15,7 +16,7 @@
from django.template.loader import render_to_string

from zds.tutorialv2.models.mixins import TemplatableContentModelMixin
from zds.tutorialv2.models import SINGLE_CONTAINER_CONTENT_TYPES, CONTENT_TYPES_BETA, CONTENT_TYPES_REQUIRING_VALIDATION
from zds.tutorialv2.models import CONTENT_TYPES_BETA, CONTENT_TYPES_REQUIRING_VALIDATION
from zds.tutorialv2.utils import default_slug_pool, export_content, get_commit_author, InvalidOperationError
from zds.tutorialv2.utils import get_blob
from zds.utils.validators import InvalidSlugError, check_slug
Expand Down Expand Up @@ -238,8 +239,7 @@ def can_add_container(self):
"""
if not self.has_extracts():
if self.get_tree_depth() < settings.ZDS_APP["content"]["max_tree_depth"] - 1:
if not self.top_container().type in SINGLE_CONTAINER_CONTENT_TYPES:
return True
return True
return False

def can_add_extract(self):
Expand Down Expand Up @@ -1320,21 +1320,16 @@ def get_prod_path(self, relative=False, file_ext="html"):

return path

def get_list_of_chapters(self):
"""
:return: a list of chapters (Container which contains Extracts) in the reading order
:rtype: list[Container]
"""
def get_list_of_chapters(self) -> List[Container]:
continuous_list = []
if self.type not in SINGLE_CONTAINER_CONTENT_TYPES: # cannot be paginated
if len(self.children) != 0 and isinstance(self.children[0], Container): # children must be Containers!
for child in self.children:
if len(child.children) != 0:
if isinstance(child.children[0], Extract):
continuous_list.append(child) # it contains Extract, this is a chapter, so paginated
else: # Container is a part
for sub_child in child.children:
continuous_list.append(sub_child) # even if empty `sub_child.childreen`, it's chapter
if len(self.children) != 0 and isinstance(self.children[0], Container): # children must be Containers!
for child in self.children:
if len(child.children) != 0:
if isinstance(child.children[0], Extract):
continuous_list.append(child) # it contains Extract, this is a chapter, so paginated
else: # Container is a part
for sub_child in child.children:
continuous_list.append(sub_child) # even if empty `sub_child.childreen`, it's chapter
return continuous_list

def get_json(self):
Expand Down

0 comments on commit 6a31d96

Please sign in to comment.