diff --git a/dsfr/templates/dsfr/quote.html b/dsfr/templates/dsfr/quote.html new file mode 100644 index 000000000..ccba888dd --- /dev/null +++ b/dsfr/templates/dsfr/quote.html @@ -0,0 +1,23 @@ + \ No newline at end of file diff --git a/dsfr/templatetags/dsfr_tags.py b/dsfr/templatetags/dsfr_tags.py index 2f95a2028..66febd1da 100644 --- a/dsfr/templatetags/dsfr_tags.py +++ b/dsfr/templatetags/dsfr_tags.py @@ -419,6 +419,43 @@ def dsfr_pagination(context: Context, page_obj: Page) -> dict: return {"request": context["request"], "page_obj": page_obj} +@register.inclusion_tag("dsfr/quote.html") +def dsfr_quote(*args, **kwargs) -> dict: + """ + Returns a quote item. Takes a dict as parameter, with the following structure: + + data_dict = { + "text": "Text of the quote", + "source_url": "(Optional) URL of the source of the quote", + "author": "(Optional) The author of the quote", + "source": "(Optional) The name of the source of the quote", + "details": "(Optional) A list containing detail dicts", + "image_url": "(Optional) URL of an illustrative image", + } + + The "details" dict entries have a mandatory "text" key and an optional "link" key. + + All of the keys of the dict can be passed directly as named parameters of the tag. + + **Tag name**:: + dsfr_quote + **Usage**:: + {% dsfr_quote data_dict %} + """ + + allowed_keys = [ + "text", + "source_url", + "author", + "source", + "details", + "image_url", + ] + tag_data = parse_tag_args(args, kwargs, allowed_keys) + + return {"self": tag_data} + + @register.inclusion_tag("dsfr/select.html") def dsfr_select(*args, **kwargs) -> dict: """ diff --git a/dsfr/test/test_templatetags.py b/dsfr/test/test_templatetags.py index 4d7241dd9..217745b3e 100644 --- a/dsfr/test/test_templatetags.py +++ b/dsfr/test/test_templatetags.py @@ -439,6 +439,51 @@ def test_link_tag_rendered(self): ) +class DsfrQuoteTagTest(SimpleTestCase): + test_data = { + "text": "Développer vos sites et applications en utilisant des composants prêts à l'emploi, accessibles et ergonomiques", + "source_url": "https://www.systeme-de-design.gouv.fr/", + "author": "Auteur", + "source": "Système de Design de l'État", + "details": [ + {"text": "Detail sans lien"}, + { + "text": "Detail avec lien", + "link": "https://template.incubateur.net/", + }, + ], + "image_url": "https://via.placeholder.com/150x150", + } + context = Context({"test_data": test_data}) + template_to_render = Template("{% load dsfr_tags %} {% dsfr_quote test_data %}") + + def test_quote_tag_rendered(self): + rendered_template = self.template_to_render.render(self.context) + self.assertInHTML( + """ + + """, + rendered_template, + ) + + class DsfrSidemenuTagTest(SimpleTestCase): test_data = { "title": "Menu", diff --git a/example_app/tag_specifics.py b/example_app/tag_specifics.py index 0db3e651c..3c34bba14 100644 --- a/example_app/tag_specifics.py +++ b/example_app/tag_specifics.py @@ -136,6 +136,26 @@ "title": "Pagination (pagination)", "doc_url": "https://gouvfr.atlassian.net/wiki/spaces/DB/pages/223051980/Pagination+-+Pagination", }, + "quote": { + "title": "Citation (quote)", + "sample_data": [ + { + "text": "Développer vos sites et applications en utilisant des composants prêts à l'emploi, accessibles et ergonomiques", + "source_url": "https://www.systeme-de-design.gouv.fr/", + "author": "Auteur", + "source": "Système de Design de l'État", + "details": [ + {"text": "Detail sans lien"}, + { + "text": "Detail avec lien", + "link": "https://template.incubateur.net/", + }, + ], + "image_url": "https://via.placeholder.com/150x150", + } + ], + "doc_url": "https://gouvfr.atlassian.net/wiki/spaces/DB/pages/771358744/Citation+-+Quote", + }, "select": { "title": "Listes déroulantes (selects)", "sample_data": [ @@ -306,7 +326,6 @@ "doc_url": "https://gouvfr.atlassian.net/wiki/spaces/DB/pages/368935129/Boutons+radio+riches+-+Radio+buttons+extended", }, "checkbox": {"title": "Case à cocher (checkbox)"}, - "quote": {"title": "Citation (quote)"}, "media_content": {"title": "Contenu média (media_content)"}, "consent": {"title": "Gestionnaire de consentement (consent)"}, "toggle": {"title": "Interrupteur (toggle)"}, diff --git a/example_app/templates/example_app/page_tag.html b/example_app/templates/example_app/page_tag.html index d92f94346..8f5d75b12 100644 --- a/example_app/templates/example_app/page_tag.html +++ b/example_app/templates/example_app/page_tag.html @@ -68,6 +68,8 @@