Skip to content

Commit 6af9edd

Browse files
committed
🗑️ [#2062] Remove card templatetags
issue: https://taiga.maykinmedia.nl/project/open-inwoner/issue/2062
1 parent fefb1f5 commit 6af9edd

File tree

11 files changed

+37
-176
lines changed

11 files changed

+37
-176
lines changed

src/open_inwoner/components/templates/components/Card/CardContainer.html

+10-6
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,35 @@
44
{% for category in categories %}
55
{% url 'products:category_detail' slug=category.slug as category_url %}
66
{% if category.icon %}
7-
{% card src=category.icon.file.url alt=category.icon.name title=category.name href=category_url compact=True image_object_fit=image_object_fit %}
7+
{% include "components/Card/Card.html" with alt=category.icon.name title=category.name href=category_url compact=True image_object_fit=image_object_fit %}
88
{% else %}
9-
{% card src=category.image.file.url alt=category.image.name title=category.name href=category_url compact=True image_object_fit=image_object_fit %}
9+
{% include "components/Card/Card.html" with src=category.image.file.url alt=category.image.name title=category.name href=category_url compact=True image_object_fit=image_object_fit %}
1010
{% endif %}
1111
{% endfor %}
1212
{% endif %}
1313

1414
{% if subcategories %}
1515
{% for subcategory in subcategories %}
16-
{% category_card category=subcategory parent_category=parent_category compact=True image_object_fit=image_object_fit %}
16+
{% include "components/Card/CategoryCard.html" with category=subcategory parent_category=parent_category compact=True image_object_fit=image_object_fit %}
1717
{% endfor %}
1818
{% endif %}
1919

2020
{% if products %}
2121
{% for product in products %}
2222
{% get_product_url product as product_url %}
23-
{% product_card title=product.name description=product.summary url=product_url image=product.icon compact=True image_object_fit=image_object_fit %}
23+
{% include "components/Card/ProductCard.html" with title=product.name description=product.summary url=product_url image=product.icon compact=True image_object_fit=image_object_fit %}
2424
{% endfor %}
2525
{% endif %}
2626

2727
{% if plans %}
2828
{% for plan in plans %}
29-
{% description_card title=plan.title description=plan.goal|truncatechars:51 url=plan.get_absolute_url elypsis=True object=plan compact=True image_object_fit=image_object_fit %}
29+
{% include "components/Card/DescriptionCard.html" with title=plan.title description=plan.goal|truncatechars:51 url=plan.get_absolute_url elypsis=True object=plan compact=True image_object_fit=image_object_fit %}
3030
{% endfor %}
3131
{% endif %}
3232

33-
{{ contents }}
33+
{% if locations %}
34+
{% for location in locations %}
35+
{% include "components/Card/LocationCard.html" with location_name=location.name compact=True phonenumber=location.phonenumber email=location.email %}
36+
{% endfor %}
37+
{% endif %}
3438
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{% load link_tags string_tags %}
2+
<div class="card card__body">
3+
{% if location_name %}
4+
{% link href=location.get_absolute_url primary=True text=location_name extra_classes="h3" %}
5+
{% endif %}
6+
<div class="card__body--flex p--no-margin">
7+
<p class="p">{{ location.address_line_1 }}</p>
8+
<p class="p">{{ location.address_line_2 }}</p>
9+
{% if phonenumber %}
10+
{% link href='tel:'|addstr:phonenumber secondary=True text=phonenumber %}
11+
{% endif %}
12+
{% if email %}
13+
{% link href='mailto:'|addstr:email secondary=True text=email %}
14+
{% endif %}
15+
</div>
16+
</div>

src/open_inwoner/components/templatetags/card_tags.py

-139
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,9 @@
22

33
from open_inwoner.components.utils import ContentsNode, parse_component_with_args
44

5-
from ...pdc.models import Category
6-
75
register = template.Library()
86

97

10-
@register.inclusion_tag("components/Card/Card.html")
11-
def card(href, title, **kwargs):
12-
"""
13-
Render in a card. Only using variables.
14-
15-
Usage:
16-
{% card href="https://maykinmedia.nl" %}
17-
18-
Variables:
19-
+ href: url | where the card links to.
20-
+ title: string | this will be the card title.
21-
- alt: string | the alt of the header image.
22-
- compact: bool | Whether to use compact styling.
23-
- direction: string | can be set to "horizontal" to show contents horizontally.
24-
- inline: bool | Whether the card should be rendered inline.
25-
- src: string | the src of the header image.
26-
- compact: bool | Whether the card has uniform padding on all sides.
27-
- stretch: bool | Whether to stretch the card vertically.
28-
- tinted: bool | whether to use gray as background color.
29-
- type: string (info) | Set to info for an info card.
30-
- image: FilerImageField | an image that should be used.
31-
- image_object_fit: string | Can be set to either "cover" (default) or "contain".
32-
- grid: boolean | if the card should be a grid.
33-
"""
34-
return {**kwargs, "href": href, "title": title}
35-
36-
378
@register.tag
389
def render_card(parser, token):
3910
"""
@@ -55,113 +26,3 @@ def render_card(parser, token):
5526
nodelist = parser.parse(("endrender_card",))
5627
parser.delete_first_token()
5728
return ContentsNode(nodelist, "components/Card/RenderCard.html", **context_kwargs)
58-
59-
60-
@register.inclusion_tag("components/Card/CategoryCard.html")
61-
def category_card(category: Category, **kwargs):
62-
"""
63-
Renders a card prepopulated based on `category`.
64-
65-
Usage:
66-
{% category_card category %}
67-
68-
Available options:
69-
- category: Category | the category to render card for.
70-
"""
71-
return {**kwargs, "category": category}
72-
73-
74-
@register.inclusion_tag("components/Card/DescriptionCard.html")
75-
def description_card(title, description, url, **kwargs):
76-
"""
77-
Renders a card prepopulated based on `product`.
78-
79-
Usage:
80-
{% description_card title=product.title description=product.intro url=product.get_absolute_url %}
81-
{% description_card title="title" description="description" url="https://maykinmedia.nl" %}
82-
83-
Available options:
84-
+ title: string | The title of the card that needs to be displayed.
85-
+ description: string | The description that needs to be displayed.
86-
+ url: string | The url that the card should point to.
87-
- object: any | The object that needs to render aditional data.
88-
- image: FilerImageField | an image that should be used.
89-
"""
90-
kwargs.update(title=title, description=description, url=url)
91-
return kwargs
92-
93-
94-
@register.inclusion_tag("components/Card/ProductCard.html")
95-
def product_card(description, url, **kwargs):
96-
"""
97-
Renders a card with or without an image prepopulated based on `product`.
98-
99-
Usage:
100-
{% product_card title=product.title description=product.intro url=product.get_absolute_url %}
101-
102-
Available options:
103-
+ description: string | The description that needs to be displayed.
104-
+ url: string | The url that the card should point to.
105-
- title: string | The title of the card that may be displayed if there is no image.
106-
- object: any | The object that needs to render aditional data.
107-
- image: FilerImageField | an image that should be used.
108-
"""
109-
kwargs.update(description=description, url=url)
110-
return kwargs
111-
112-
113-
@register.inclusion_tag("components/Card/CardContainer.html")
114-
def card_container(categories=[], subcategories=[], products=[], plans=[], **kwargs):
115-
"""
116-
A card container where the category card or product card will be rendered in.
117-
118-
Usage:
119-
{% card_container categories=categories %}
120-
121-
Variables:
122-
- categories: Category[] | categories to render.
123-
- subcategories: Category[] | subcategories to render.
124-
- products: Product[] | products to render.
125-
- parent: Category | The parent of the given card_container
126-
- image_object_fit: string | Can be set to either "cover" (default) or "contain".
127-
"""
128-
if (
129-
categories is None
130-
and subcategories is None
131-
and products is None
132-
and plans is None
133-
):
134-
assert False, "provide categories, subcategories, products or plans"
135-
136-
return {
137-
**kwargs,
138-
"categories": categories,
139-
"subcategories": subcategories,
140-
"products": products,
141-
"plans": plans,
142-
}
143-
144-
145-
@register.tag()
146-
def render_card_container(parser, token):
147-
"""
148-
Nested content supported.
149-
150-
Usage:
151-
{% render_card_container %}
152-
{% card href='https://www.example.com' title='example.com' %}
153-
{% endrender_card_container %}
154-
155-
Variables:
156-
Supports all options from card, but optional.
157-
158-
Extra context:
159-
- contents: string (HTML) | this is the context between the render_card and endrender_card tags
160-
"""
161-
bits = token.split_contents()
162-
context_kwargs = parse_component_with_args(parser, bits, "render_list")
163-
nodelist = parser.parse(("endrender_card_container",)) # End tag
164-
parser.delete_first_token()
165-
return ContentsNode(
166-
nodelist, "components/Card/CardContainer.html", **context_kwargs
167-
) # Template

src/open_inwoner/templates/cms/products/categories_plugin.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ <h2 class="h2">
88
</h2>
99
<p class="p">{{configurable_text.home_page.home_theme_intro|linebreaksbr}}</p>
1010

11-
{% card_container categories=categories columns=4 image_object_fit="cover" %}
11+
{% include "components/Card/CardContainer.html" with categories=categories columns=4 image_object_fit="cover" %}
1212
{% endif %}

src/open_inwoner/templates/pages/category/detail.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ <h1 class="utrecht-heading-1">
2020
{{ category_rendered_description|safe }}
2121

2222
{% if subcategories %}
23-
{% card_container subcategories=subcategories parent_category=object %}
23+
{% include "components/Card/CardContainer.html" with subcategories=subcategories parent_category=object %}
2424
{% endif %}
2525

2626
{% if products %}
2727
<div class="categories__products">
28-
{% card_container products=products small=True parent=object %}
28+
{% include "components/Card/CardContainer.html" with products=products small=True parent=object %}
2929
</div>
3030
{% endif %}
3131

src/open_inwoner/templates/pages/category/list.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
<h1 class="h1">{{configurable_text.theme_page.theme_title}}</h1>
77
<p class="p">{{configurable_text.theme_page.theme_intro|linebreaksbr}}</p>
88

9-
{% card_container categories=object_list %}
9+
{% include "components/Card/CardContainer.html" with categories=object_list %}
1010
</div>
1111
{% endblock content %}

src/open_inwoner/templates/pages/home.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ <h2 class="h2">
2525
<p class="p">{{configurable_text.home_page.home_theme_intro|linebreaksbr}}</p>
2626

2727
{% if request.user.is_authenticated %}
28-
{% card_container categories=categories columns=4 image_object_fit="cover" %}
28+
{% include "components/Card/CardContainer.html" with categories=categories columns=4 image_object_fit="cover" %}
2929
{% else %}
30-
{% card_container categories=categories image_object_fit="cover" %}
30+
{% include "components/Card/CardContainer.html" with categories=categories image_object_fit="cover" %}
3131
{% endif %}
3232

3333
{% if questionnaire_roots.exists %}

src/open_inwoner/templates/pages/plans/list.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ <h1 class="h1">
6565
</tbody>
6666
</table>
6767
{% else %}
68-
{% card_container plans=plans.plan_list columns=2 %}
68+
{% include "components/Card/CardContainer.html" with plans=plans.plan_list columns=2 %}
6969
{% endif %}
7070

7171
{% pagination page_obj=page_obj paginator=paginator request=request %}

src/open_inwoner/templates/pages/product/detail.html

+1-21
Original file line numberDiff line numberDiff line change
@@ -90,27 +90,7 @@ <h3 class="h3">{% trans "U komt niet in aanmerking" %}</h3>
9090
{% map centroid.lat centroid.lng id="locations" title=_('Locaties') geojson_feature_collection=object.locations.get_geojson_feature_collection %}
9191
{% endwith %}
9292

93-
{% render_card_container columns=3 %}
94-
{% for location in object.locations.all %}
95-
{% with location_name=location.name phonenumber=location.phonenumber email=location.email %}
96-
<div class="card card__body">
97-
{% if location_name %}
98-
{% link href=location.get_absolute_url primary=True text=location_name extra_classes="h3" %}
99-
{% endif %}
100-
<div class="card__body--flex p--no-margin">
101-
<p class="p">{{ location.address_line_1 }}</p>
102-
<p class="p">{{ location.address_line_2 }}</p>
103-
{% if phonenumber %}
104-
{% link href='tel:'|addstr:phonenumber secondary=True text=phonenumber %}
105-
{% endif %}
106-
{% if email %}
107-
{% link href='mailto:'|addstr:email secondary=True text=email %}
108-
{% endif %}
109-
</div>
110-
</div>
111-
{% endwith %}
112-
{% endfor %}
113-
{% endrender_card_container %}
93+
{% include "components/Card/CardContainer.html" with locations=object.locations.all columns=3 %}
11494
{% endif %}
11595

11696
{% render_grid %}

src/open_inwoner/templates/pages/product/location_detail.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ <h1 class="h1">{{ object.name }}</h1>
2323
</div>
2424
</div>
2525
</div>
26-
26+
2727
{% if products %}
28-
{% card_container products=products small=True %}
28+
{% include "components/Card/CardContainer.html" with products=products small=True %}
2929
{% else %}
3030
{% trans "There are no products available at this location." %}
3131
{% endif %}

src/open_inwoner/templates/pages/questionnaire/questionnaire-step.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ <h1 class="h1" data-title="{{ form.instance.get_title }}" data-code="{{ form.ins
5151

5252
{% if form.instance.related_products.published.exists %}
5353
<hr class="divider">
54-
{% card_container products=form.instance.related_products.published small=True %}
54+
{% include "components/Card/CardContainer.html" with products=form.instance.related_products.published small=True %}
5555
{% endif %}
5656
{% endrender_form %}
5757
</fieldset>

0 commit comments

Comments
 (0)