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

Flag les features d'export pour les billets #6197

Merged
merged 4 commits into from
Mar 7, 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
14 changes: 13 additions & 1 deletion doc/source/back-end/contents.rst
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,10 @@ devoir migrer les différents tutoriels. Pour cela, il faudra simplement exécut
Récapitulatif des paramètres du module
======================================

Ces paramètres sont à surcharger dans le dictionnaire ZDS_APP['content']
Paramètres globaux
------------------

Ces paramètres sont à surcharger dans le dictionnaire ``ZDS_APP['content']``:

- ``repo_private_path`` : chemin vers le dossier qui contiend les contenus durant leur rédaction, par défaut le dossier sera contents-private à la racine de l'application
- ``repo_public_path``: chemin vers le dossier qui contient les fichiers permettant l'affichage des contenus publiés ainsi que les fichiers téléchargeables, par défaut contents-public
Expand All @@ -618,6 +621,15 @@ Ces paramètres sont à surcharger dans le dictionnaire ZDS_APP['content']
- ``build_pdf_when_published``: indique que la publication générera un PDF (quelque soit la politique, si ``False``, les PDF ne seront pas générés, sauf à appeler la commande adéquate),
- ``maximum_slug_size``: taille maximale du slug d'un contenu

Paramètres propres aux tribunes libres
--------------------------------------

Ces paramètres sont à surcharger dans le dictionnaire ``ZDS_APP['opinions']``:

- ``allow_pdf``: par défaut à ``True`` elle permet d'activer (et de désactiver si ``False``) la génération des PDF à la publication des billets.
- ``allow_epub``: par défaut à ``True`` elle permet d'activer (et de désactiver si ``False``) la génération des EPUB à la publication des billets.
- ``allow_zip``: par défaut à ``True`` elle permet d'activer (et de désactiver si ``False``) la génération de l'archive du contenu à la publication des billets.

Statistiques
============

Expand Down
7 changes: 6 additions & 1 deletion zds/settings/abstract_base/zds.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@
"home_number": 4,
},
"article": {"home_number": 3},
"opinions": {"home_number": 5},
"opinions": {
"home_number": 5,
"allow_pdf": zds_config.get("opinions_allow_pdf", True),
"allow_epub": zds_config.get("opinions_allow_epub", True),
"allow_zip": zds_config.get("opinions_allow_zip", True),
},
"content": {
"repo_private_path": BASE_DIR / "contents-private",
"repo_public_path": BASE_DIR / "contents-public",
Expand Down
10 changes: 9 additions & 1 deletion zds/tutorialv2/publication_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ def publish(self, md_file_path, base_name, **kwargs):
published_content_entity = self.get_published_content_entity(md_file_path)
if published_content_entity is None:
raise ValueError("published_content_entity is None")
if published_content_entity.content.type == "OPINION" and not settings.ZDS_APP["opinions"]["allow_zip"]:
logger.info("ZIP not allowed for opinions.")
return
make_zip_file(published_content_entity)
# no need to move zip file because it is already dumped to the public directory
except (OSError, ValueError) as e:
Expand Down Expand Up @@ -365,6 +368,9 @@ def __init__(self, extension=".pdf", latex_classes=""):

def publish(self, md_file_path, base_name, **kwargs):
published_content_entity = self.get_published_content_entity(md_file_path)
if published_content_entity.content.type == "OPINION" and not settings.ZDS_APP["opinions"]["allow_pdf"]:
logger.info("PDF not allowed for opinions")
return
gallery_pk = published_content_entity.content.gallery.pk
depth_to_size_map = {
1: "small", # in fact this is an "empty" tutorial (i.e it is empty or has intro and/or conclusion)
Expand Down Expand Up @@ -502,7 +508,6 @@ def handle_tex_compiler_error(latex_file_path, ext):
errors = [f"Error occured, log file {log_file_path} not found."]
with contextlib.suppress(FileNotFoundError, UnicodeDecodeError):
with Path(log_file_path).open(encoding="utf-8") as latex_log:
# TODO zmd: see if the lines we extract here contain enough info for debugging purpose
print_context = 25
lines = []
relevant_line = -print_context
Expand All @@ -528,6 +533,9 @@ class ZMarkdownEpubPublicator(Publicator):
def publish(self, md_file_path, base_name, **kwargs):
try:
published_content_entity = self.get_published_content_entity(md_file_path)
if published_content_entity.content.type == "OPINION" and not settings.ZDS_APP["opinions"]["allow_epub"]:
logger.info("EPUB not allowed for opinions")
return
epub_file_path = Path(base_name + ".epub")
logger.info("Start generating epub")
build_ebook(published_content_entity, path.dirname(md_file_path), epub_file_path)
Expand Down