2
2
3
3
from open_inwoner .components .utils import ContentsNode , parse_component_with_args
4
4
5
- from ...pdc .models import Category
6
-
7
5
register = template .Library ()
8
6
9
7
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
-
37
8
@register .tag
38
9
def render_card (parser , token ):
39
10
"""
@@ -55,113 +26,3 @@ def render_card(parser, token):
55
26
nodelist = parser .parse (("endrender_card" ,))
56
27
parser .delete_first_token ()
57
28
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
0 commit comments