Skip to content

Commit

Permalink
Merge pull request #1 from entrepreneur-interet-general/hf
Browse files Browse the repository at this point in the history
[Quote] New component
  • Loading branch information
Ash-Crow authored Oct 26, 2021
2 parents 6a31d2a + 93bad30 commit d621b61
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 29 deletions.
23 changes: 23 additions & 0 deletions dsfr/templates/dsfr/quote.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<figure class="fr-quote fr-quote--column">
<blockquote {% if self.source_url %}cite="{{ self.source_url }}"{% endif %}>
<p>{{ self.text }}</p>
</blockquote>
<figcaption>
{% if self.author %}<p class="fr-quote__author">{{ self.author }}</p>{% endif %}
{% if self.details or self.source %}<ul class="fr-quote__source">
<li>
<cite>{{ self.source }}</cite>
</li>
{% for detail in self.details %}
{% if detail.link %}
<li><a target="_blank" rel="noopener noreferrer" href="{{ detail.link }}">{{ detail.text }}</a></li>
{% else %}
<li>{{ detail.text }}</li>
{% endif %}
{% endfor %}
</ul>{% endif %}
{% if self.image_url %}<div class="fr-quote__image">
<img src="{{ self.image_url }}" class="fr-responsive-img" alt="" />
</div>{% endif %}
</figcaption>
</figure>
37 changes: 37 additions & 0 deletions dsfr/templatetags/dsfr_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
45 changes: 45 additions & 0 deletions dsfr/test/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"""
<figure class="fr-quote fr-quote--column">
<blockquote cite="https://www.systeme-de-design.gouv.fr/">
<p>Développer vos sites et applications en utilisant des composants prêts à l&#x27;emploi, accessibles et ergonomiques</p>
</blockquote>
<figcaption>
<p class="fr-quote__author">Auteur</p>
<ul class="fr-quote__source">
<li>
<cite>Système de Design de l&#x27;État</cite>
</li>
<li>Detail sans lien</li>
<li><a target="_blank" rel="noopener noreferrer" href="https://template.incubateur.net/">Detail avec lien</a></li>
</ul>
<div class="fr-quote__image">
<img src="https://via.placeholder.com/150x150" class="fr-responsive-img" alt="" />
</div>
</figcaption>
</figure>
""",
rendered_template,
)


class DsfrSidemenuTagTest(SimpleTestCase):
test_data = {
"title": "Menu",
Expand Down
21 changes: 20 additions & 1 deletion example_app/tag_specifics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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)"},
Expand Down
2 changes: 2 additions & 0 deletions example_app/templates/example_app/page_tag.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ <h3>Résultat</h3>
{% 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" %}
Expand Down
55 changes: 27 additions & 28 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
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"]

0 comments on commit d621b61

Please sign in to comment.