From ae48a0a1052cb12330b795ddb8a5f9897f78ab62 Mon Sep 17 00:00:00 2001 From: artragis Date: Sat, 23 Oct 2021 14:40:56 +0200 Subject: [PATCH 1/3] Flag features --- zds/settings/abstract_base/zds.py | 7 ++++++- zds/tutorialv2/publication_utils.py | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/zds/settings/abstract_base/zds.py b/zds/settings/abstract_base/zds.py index caedc2dc16..453ac8a103 100644 --- a/zds/settings/abstract_base/zds.py +++ b/zds/settings/abstract_base/zds.py @@ -154,7 +154,12 @@ "home_number": 4, }, "article": {"home_number": 3}, - "opinions": {"home_number": 5}, + "opinions": { + "home_number": 5, + "allow_pdf": True, + "allow_epub": True, + "allow_zip": True, + }, "content": { "repo_private_path": BASE_DIR / "contents-private", "repo_public_path": BASE_DIR / "contents-public", diff --git a/zds/tutorialv2/publication_utils.py b/zds/tutorialv2/publication_utils.py index 7bcb3a9402..d39d46311c 100644 --- a/zds/tutorialv2/publication_utils.py +++ b/zds/tutorialv2/publication_utils.py @@ -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 oinions.") + 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: @@ -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) @@ -528,6 +534,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) From 040d279eacc464a4a632182a1599ff92ba59eac6 Mon Sep 17 00:00:00 2001 From: artragis Date: Sun, 24 Oct 2021 10:15:59 +0200 Subject: [PATCH 2/3] typo & doc --- doc/source/back-end/contents.rst | 14 +++++++++++++- zds/tutorialv2/publication_utils.py | 7 +++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/doc/source/back-end/contents.rst b/doc/source/back-end/contents.rst index 749f01edbe..e4f110c446 100644 --- a/doc/source/back-end/contents.rst +++ b/doc/source/back-end/contents.rst @@ -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 @@ -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 ============ diff --git a/zds/tutorialv2/publication_utils.py b/zds/tutorialv2/publication_utils.py index d39d46311c..e3aa5e84be 100644 --- a/zds/tutorialv2/publication_utils.py +++ b/zds/tutorialv2/publication_utils.py @@ -324,7 +324,7 @@ def publish(self, md_file_path, base_name, **kwargs): 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 oinions.") + 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 @@ -508,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 @@ -535,8 +534,8 @@ 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 + 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) From d5f6ac87fed85c1fd7d2edb39995e2f1885fce0d Mon Sep 17 00:00:00 2001 From: artragis Date: Mon, 7 Mar 2022 20:22:32 +0100 Subject: [PATCH 3/3] Update zds/settings/abstract_base/zds.py Co-authored-by: Situphen --- zds/settings/abstract_base/zds.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zds/settings/abstract_base/zds.py b/zds/settings/abstract_base/zds.py index 453ac8a103..4480cda26c 100644 --- a/zds/settings/abstract_base/zds.py +++ b/zds/settings/abstract_base/zds.py @@ -156,9 +156,9 @@ "article": {"home_number": 3}, "opinions": { "home_number": 5, - "allow_pdf": True, - "allow_epub": True, - "allow_zip": True, + "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",