Skip to content

HTML Blocks

cjkcms.blocks.ButtonBlock

Bases: ButtonMixin, BaseLinkBlock

A link styled as a button.

Source code in cjkcms/blocks/html_blocks.py
32
33
34
35
36
37
38
39
40
41
42
class ButtonBlock(ButtonMixin, BaseLinkBlock):
    """
    A link styled as a button.
    """

    class Meta:
        template = "cjkcms/blocks/button_block.html"
        icon = "hand-pointer-o"
        label = _("Button Link")
        label_format = "{button_title} (Button Link)"
        value_class = LinkStructValue

cjkcms.blocks.ImageBlock

Bases: BaseBlock

An , by default styled responsively to fill its container.

Source code in cjkcms/blocks/html_blocks.py
141
142
143
144
145
146
147
148
149
150
151
152
153
154
class ImageBlock(BaseBlock):
    """
    An <img>, by default styled responsively to fill its container.
    """

    image = ImageChooserBlock(
        label=_("Image"),
    )

    class Meta:
        template = "cjkcms/blocks/image_block.html"
        icon = "image"
        label = _("Image")
        label_format = "Image: {image}"

cjkcms.blocks.ImageLinkBlock

Bases: BaseLinkBlock

An <a> with an image inside it, instead of text.

Source code in cjkcms/blocks/html_blocks.py
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
class ImageLinkBlock(BaseLinkBlock):
    """
    An &lt;a&gt; with an image inside it, instead of text.
    """

    image = ImageChooserBlock(
        label=_("Image"),
    )
    alt_text = blocks.CharBlock(
        max_length=255,
        required=True,
        help_text=_("Alternate text to show if the image doesn’t load"),
    )

    class Meta:
        template = "cjkcms/blocks/image_link_block.html"
        icon = "image"
        label = _("Image Link")
        value_class = LinkStructValue
        label_format = "Image link: {image}"

cjkcms.blocks.DownloadBlock

Bases: ButtonMixin, BaseBlock

Link to a file that can be downloaded.

Source code in cjkcms/blocks/html_blocks.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class DownloadBlock(ButtonMixin, BaseBlock):
    """
    Link to a file that can be downloaded.
    """

    automatic_download = blocks.BooleanBlock(
        required=False,
        label=_("Auto download"),
    )
    downloadable_file = DocumentChooserBlock(
        required=False,
        label=_("Document link"),
    )

    advsettings_class = CjkcmsAdvTrackingSettings

    class Meta:
        template = "cjkcms/blocks/download_block.html"
        icon = "download"
        label = _("Download")

cjkcms.blocks.EmbedVideoBlock

Bases: BaseBlock

Embedded media using stock wagtail functionality.

Source code in cjkcms/blocks/html_blocks.py
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
class EmbedVideoBlock(BaseBlock):
    """
    Embedded media using stock wagtail functionality.
    """

    url = EmbedBlock(
        required=True,
        label=_("URL"),
        help_text=_("Link to a YouTube/Vimeo video, tweet, facebook post, etc."),
    )

    class Meta:
        template = "cjkcms/blocks/embed_video_block.html"
        icon = "media"
        label = _("Embed Media")

cjkcms.blocks.PageListBlock

Bases: BaseBlock

Renders a preview of selected pages.

Source code in cjkcms/blocks/html_blocks.py
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
class PageListBlock(BaseBlock):
    """
    Renders a preview of selected pages.
    """

    # default miniview template, overridden by individual page models
    miniview_template = "cjkcms/pages/page.mini.html"

    indexed_by = blocks.PageChooserBlock(
        required=False,
        label=_("Parent page"),
        help_text=_(
            "Preview of pages that are children of the selected page (default to own parent). Uses ordering specified in the page’s LAYOUT tab."  # noqa
        ),
    )
    classified_by = ClassifierTermChooserBlock(
        required=False,
        label=_("Classified as"),
        help_text=_("Only show pages that are classified with this term."),
    )

    # DEPRECATED - replaced with mini-views
    show_preview = blocks.BooleanBlock(
        required=False,
        default=False,
        label=_("Show body preview"),
    )
    show_dates = blocks.BooleanBlock(
        required=False,
        default=True,
        label=_("Show publish dates"),
    )

    show_authors = blocks.BooleanBlock(
        required=False,
        default=True,
        label=_("Show authors"),
    )

    show_covers = blocks.BooleanBlock(
        required=False,
        default=True,
        label=_("Show cover images"),
        help_text=_("Show cover images"),
    )

    show_navigation = blocks.BooleanBlock(
        required=False,
        default=False,
        label=_("Show navigation"),
        help_text=_("Show prev / next navigation buttons"),
    )

    num_posts = blocks.IntegerBlock(
        default=10,
        label=_("Number of pages to show"),
    )

    title = blocks.CharBlock(
        required=False,
        max_length=255,
        label=_("Title"),
    )

    class Meta:
        template = "cjkcms/blocks/pagelist_block.html"
        icon = "list-ul"
        label = _("Latest Pages")

    def get_context(self, value, parent_context=None):
        context = super().get_context(value, parent_context=parent_context)

        if not parent_context:
            return context

        try:
            current_page = parent_context["page"]
        except KeyError:  # e.g. in search results
            return context

        if value["indexed_by"]:
            indexer = value["indexed_by"].specific
        else:
            indexer = current_page.get_parent().specific

        # try to use the CjkcmsPage `get_index_children()`,
        # but fall back to get_children if this is a non-CjkcmsPage
        if hasattr(indexer, "get_index_children"):
            pages = indexer.get_index_children().live()
            if value["classified_by"]:
                try:
                    pages = pages.filter(classifier_terms=value["classified_by"])
                except AttributeError:
                    # `pages` is not a queryset, or is not a queryset of CjkcmsPage.
                    logger.warning(
                        "Tried to filter by ClassifierTerm in PageListBlock, but <%s.%s ('%s')>.get_index_children()  # noqadid not return a queryset or is not a queryset of CjkcmsPage models.",  # noqa
                        indexer._meta.app_label,
                        indexer.__class__.__name__,
                        indexer.title,
                    )
        else:
            pages = indexer.get_children().live()

        pages_limited = pages[: value["num_posts"]]

        context["current_page"] = current_page

        # current_index = list(pages_limited.values_list("id", flat=True)).index(
        #     current_page.id
        # )
        # print(current_index)
        previous_page = None
        next_page = None
        current_index = -2

        page_count = len(list(pages_limited))
        for index, item in enumerate(pages_limited):
            if item.id == current_page.id:
                current_index = index

        for index, item in enumerate(pages_limited):
            if (index == current_index - 1) and (index >= 0):
                previous_page = item
            if (index == current_index + 1) and (index < page_count):
                next_page = item

        context["previous_page"] = previous_page
        context["next_page"] = next_page
        context["pages"] = pages_limited
        context["miniview_template"] = self.miniview_template
        return context

cjkcms.blocks.PagePreviewBlock

Bases: BaseBlock

Renders a preview of a specific page.

Source code in cjkcms/blocks/html_blocks.py
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
class PagePreviewBlock(BaseBlock):
    """
    Renders a preview of a specific page.
    """

    page = blocks.PageChooserBlock(
        required=True,
        label=_("Page to preview"),
        help_text=_("Show a mini preview of the selected page."),
    )

    class Meta:
        template = "cjkcms/blocks/pagepreview_block.html"
        icon = "doc-empty-inverse"
        label = _("Page Preview")

cjkcms.blocks.QuoteBlock

Bases: BaseBlock

A

.

Source code in cjkcms/blocks/html_blocks.py
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
class QuoteBlock(BaseBlock):
    """
    A <blockquote>.
    """

    text = blocks.TextBlock(
        required=True,
        rows=4,
        label=_("Quote Text"),
    )
    author = blocks.CharBlock(
        required=False,
        max_length=255,
        label=_("Author"),
    )

    class Meta:
        template = "cjkcms/blocks/quote_block.html"
        icon = "openquote"
        label = _("Quote")

cjkcms.blocks.RichTextBlock

Bases: RichTextBlock

Source code in cjkcms/blocks/html_blocks.py
351
352
353
class RichTextBlock(blocks.RichTextBlock):
    class Meta:
        template = "cjkcms/blocks/rich_text_block.html"

cjkcms.blocks.TableBlock

Bases: BaseBlock

Source code in cjkcms/blocks/html_blocks.py
132
133
134
135
136
137
138
class TableBlock(BaseBlock):
    table = WagtailTableBlock()

    class Meta:
        template = "cjkcms/blocks/table_block.html"
        icon = "table"
        label = _("Table")

cjkcms.blocks.SearchableHTMLBlock

Bases: RawHTMLBlock

RawHTMLBlock extended with basic search support

Source code in cjkcms/blocks/html_blocks.py
356
357
358
359
360
361
362
class SearchableHTMLBlock(blocks.RawHTMLBlock):
    """RawHTMLBlock extended with basic search support"""

    def get_searchable_content(self, value):
        # Strip HTML tags to prevent search backend from indexing them
        source = force_str(value)
        return [get_text_for_indexing(source)]