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 @@ +
+
+

{{ self.text }}

+
+
+ {% if self.author %}

{{ self.author }}

{% endif %} + {% if self.details or self.source %}{% endif %} + {% if self.image_url %}
+ +
{% endif %} +
+
\ 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( + """ +
+
+

Développer vos sites et applications en utilisant des composants prêts à l'emploi, accessibles et ergonomiques

+
+
+

Auteur

+ +
+ +
+
+
+ """, + 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 @@

Résultat

{% dsfr_input sample_data_item %} {% elif tag_name == "link" %} {% dsfr_link sample_data_item %} + {% elif tag_name == "quote" %} + {% dsfr_quote sample_data_item %} {% elif tag_name == "select" %} {% dsfr_select sample_data_item %} {% elif tag_name == "sidemenu" %} diff --git a/pyproject.toml b/pyproject.toml index 4c6dd4bbf..5c1fdd33d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,50 +1,49 @@ [tool.poetry] -name = "django-dsfr" -version = "0.4.5" -description = "Integrate the French government Design System into a Django app" authors = ["Sylvain Boissel "] +description = "Integrate the French government Design System into a Django app" license = "MIT" +name = "django-dsfr" +version = "0.4.6" -readme = "README.rst" -homepage = "https://github.com/entrepreneur-interet-general/django-dsfr" -repository = "https://github.com/entrepreneur-interet-general/django-dsfr" -documentation = "https://entrepreneur-interet-general.github.io/django-dsfr" -keywords = ["django"] classifiers = [ - "Development Status :: 3 - Alpha", - "Environment :: Web Environment", - "Framework :: Django", - "Framework :: Django :: 3.2", - "Operating System :: OS Independent", - "Intended Audience :: Developers", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Topic :: Software Development :: Libraries", - "Topic :: Utilities", + "Development Status :: 3 - Alpha", + "Environment :: Web Environment", + "Framework :: Django", + "Framework :: Django :: 3.2", + "Operating System :: OS Independent", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Topic :: Software Development :: Libraries", + "Topic :: Utilities", ] +documentation = "https://entrepreneur-interet-general.github.io/django-dsfr" +homepage = "https://github.com/entrepreneur-interet-general/django-dsfr" +keywords = ["django"] +readme = "README.rst" +repository = "https://github.com/entrepreneur-interet-general/django-dsfr" packages = [ - { include = "dsfr" }, + {include = "dsfr"}, ] -include = ["LICENSE", "README.rst", "dsfr/static/dsfr/dist/*/*.*" ] +include = ["LICENSE", "README.rst", "dsfr/static/dsfr/dist/*/*.*"] [tool.poetry.dependencies] -python = "^3.8" Django = "^3.2.5" +python = "^3.8" requests = "^2.26.0" [tool.poetry.dev-dependencies] -pytest = "^6.2.4" black = {version = "^21.7b0", allow-prereleases = true} -docutils = "^0.17.1" coverage = "^5.5" django-distill = "^2.9.0" - +docutils = "^0.17.1" +pytest = "^6.2.4" [build-system] -requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" +requires = ["poetry-core>=1.0.0"]