-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcms_components.py
More file actions
965 lines (830 loc) · 27.3 KB
/
cms_components.py
File metadata and controls
965 lines (830 loc) · 27.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
from django import forms
from django.conf import settings
from django.core.exceptions import ValidationError
from django.core.validators import MinValueValidator
from django.utils.translation import gettext_lazy as _
from djangocms_frontend.component_base import CMSFrontendComponent, Slot
from djangocms_frontend.component_pool import components
from djangocms_frontend.contrib.icon.fields import IconPickerField
from djangocms_frontend.contrib.image.fields import ImageFormField
from djangocms_frontend.fields import ButtonGroup, ColoredButtonGroup, HTMLFormField, IconGroup
from djangocms_frontend.helpers import first_choice
from djangocms_frontend import settings as frontend_settings
def _hero_clip_path_choices():
"""Return (id, label) pairs for the Hero clip_path ChoiceField."""
clip_paths = getattr(settings, "CMS_HERO_CLIP_PATHS", [("none", _("None"), None)])
return [(cp[0], cp[1]) for cp in clip_paths]
@components.register
class Hero(CMSFrontendComponent):
"""Hero component with background grid option"""
class Meta:
name = _("Hero")
render_template = "hero/hero.html"
allow_children = True
child_classes = []
slots = (
Slot("links", _("Links"), child_classes=["TextLinkPlugin"]),
Slot("satellites", _("Satellite Images or Counters"), child_classes=["ImagePlugin", "CounterPlugin"]),
)
mixins = ["Background", "Spacing", "Attributes"]
frontend_editable_fields = ("heading", "overline", "body")
heading = forms.CharField(
label=_("Heading"),
required=True,
initial="",
)
overline = forms.CharField(
label=_("Eyebrow text"),
required=False,
initial="",
)
body = HTMLFormField(
label=_("Body"),
required=False,
)
background_grid = forms.BooleanField(
label=_("Show background grid"),
required=False,
initial=False,
)
main_image = ImageFormField(
label=_("Main image"),
required=False,
help_text=_("Primary image for the hero section, typically displayed on the right side. Add satellite images as child plugins."),
)
clip_path = forms.ChoiceField(
label=_("Clip path"),
choices=_hero_clip_path_choices,
required=False,
initial="none",
help_text=_("Optional SVG clip path applied to the hero image."),
)
def get_short_description(self):
return self.heading if self.config.get("heading") else ""
@components.register
class Features(CMSFrontendComponent):
"""Features section container with accordion and content area"""
class Meta:
plugin_name = _("Features")
render_template = "features/features.html"
allow_children = True
child_classes = [
"TextPlugin",
"HeadingPlugin",
"AccordionPlugin",
"TextLinkPlugin",
]
mixins = ["Background", "Spacing", "Attributes"]
background_grid = forms.BooleanField(
label=_("Show background grid"),
required=False,
initial=False,
)
mirror_layout = forms.BooleanField(
label=_("Mirror layout"),
required=False,
initial=False,
help_text=_(
"Enable to display images on the left and the accordion on the right."
),
)
accordion_header_color = forms.ChoiceField(
label=_("Accordion header text color"),
choices=[
("default", _("Default (Black)")),
("primary", _("Primary")),
("secondary", _("Secondary")),
("white", _("White")),
("muted", _("Muted")),
],
required=False,
initial="default",
)
@components.register
class TimelineContainer(CMSFrontendComponent):
"""Timeline component with vertical layout option"""
class Meta:
name = _("Timeline")
render_template = "timeline/timeline.html"
allow_children = True
child_classes = [
"CardPlugin",
"TextPlugin",
"HeadingPlugin",
"SpacingPlugin",
]
mixins = [
"Background",
"Spacing",
"Attributes",
]
divider_color = forms.ChoiceField(
label=_("Divider line color"),
choices=frontend_settings.COLOR_STYLE_CHOICES,
required=False,
initial="primary",
help_text=_("Color of the vertical timeline line."),
widget=ColoredButtonGroup(attrs={"class": "flex-wrap"}),
)
circle_color = forms.ChoiceField(
label=_("Circle color"),
choices=frontend_settings.COLOR_STYLE_CHOICES,
required=False,
initial="secondary",
help_text=_("Color of the timeline circles."),
widget=ColoredButtonGroup(attrs={"class": "flex-wrap"}),
)
@components.register
class Footer(CMSFrontendComponent):
"""Footer component with divider color option"""
class Meta:
name = _("Footer")
render_template = "footer/footer.html"
allow_children = True
mixins = ["Background", "Spacing", "Attributes"]
frontend_editable_fields = ("left_label", "middle_label", "right_label")
slots = (
Slot("left", _("Links left column"), child_classes=["TextLinkPlugin"]),
Slot("middle", _("Links middle column"), child_classes=["TextLinkPlugin"]),
Slot("right", _("Links right column"), child_classes=["TextLinkPlugin"]),
Slot("bottom", _("Bottom links"), child_classes=["TextLinkPlugin", "TextPlugin"]),
)
child_classes = [] # Only slots, no direct children allowed
fieldsets = (
(
None,
{
"fields": (
("left_label", "middle_label", "right_label"),
"divider_color",
)
},
),
)
left_label = forms.CharField(
label=_("Left column heading"),
required=True,
initial=_("Community"),
)
middle_label = forms.CharField(
label=_("Middle column heading"),
required=True,
initial=_("Developer"),
)
right_label = forms.CharField(
label=_("Right column heading"),
required=True,
initial=_("Follow us"),
)
divider_color = forms.ChoiceField(
label=_("Divider line color"),
choices=frontend_settings.COLOR_STYLE_CHOICES,
required=False,
initial="white",
help_text=_("Color of the horizontal divider line."),
widget=ColoredButtonGroup(attrs={"class": "flex-wrap"}),
)
@components.register
class LinksListContainer(CMSFrontendComponent):
"""Footer Links List component"""
class Meta:
name = _("Links List Container")
render_template = "footer/footer_links_list.html"
requires_parent = True
parent_classes = ["Footer", "GridColumnPlugin"]
allow_children = True
child_classes = [
"TextLinkPlugin",
]
mixins = ["Attributes", "Spacing"]
item_spacing = forms.ChoiceField(
label=_("Item Spacing"),
choices=settings.DJANGOCMS_FRONTEND_SPACER_SIZES,
required=False,
)
item_alignment = forms.ChoiceField(
label=_("Item Alignment"),
choices=[
("flex-row", _("One line")),
("flex-column", _("Stacked")),
],
required=False,
initial="flex-column",
)
@components.register
class CTAPanel(CMSFrontendComponent):
"""CTAPanel component with background grid option"""
class Meta:
name = _("CTA Panel")
module = _("Sections")
render_template = "cta/cta_panel.html"
allow_children = True
child_classes = [
"TextLinkPlugin",
]
mixins = ["Background", "Spacing", "Attributes"]
background_grid = forms.BooleanField(
label=_("Show background grid"),
required=False,
initial=False,
)
main_heading = HTMLFormField(
label=_("Main heading"),
required=False,
)
eyebrow_text = forms.CharField(
label=_("Eyebrow text"),
required=False,
)
content_alignment = forms.ChoiceField(
label=_("Content alignment"),
choices=[
("start", _("Start")),
("center", _("Center (Default)")),
("end", _("End")),
],
initial="center",
help_text=_("Controls horizontal alignment of all content"),
)
@components.register
class LogoCarousel(CMSFrontendComponent):
"""LogoCarousel component"""
class Meta:
name = _("Carousel")
render_template = "carousel/logo_carousel.html"
allow_children = True
child_classes = ["CarouselItemPlugin"]
mixins = ["Background", "Spacing", "Attributes"]
frontend_editable_fields = ("heading",)
fieldsets = (
(
None,
{
"fields": (
"heading",
"text_color",
"bg_color",
)
},
),
(
_("Settings"),
{
"fields": (
"loop",
"space_between_slides",
"autoplay",
"delay",
"btn_color",
),
"classes": ("collapse",),
},
),
)
heading = forms.CharField(
label=_("Heading"),
required=False,
)
text_color = forms.ChoiceField(
label=_("Text color"),
choices=frontend_settings.EMPTY_CHOICE + frontend_settings.COLOR_STYLE_CHOICES,
initial=frontend_settings.EMPTY_CHOICE[0][0],
widget=ColoredButtonGroup(attrs={"class": "flex-wrap"}),
required=False,
)
bg_color = forms.ChoiceField(
label=_("Background color"),
choices=frontend_settings.EMPTY_CHOICE + frontend_settings.COLOR_STYLE_CHOICES,
initial=frontend_settings.EMPTY_CHOICE[0][0],
widget=ColoredButtonGroup(attrs={"class": "flex-wrap"}),
required=False,
)
loop = forms.BooleanField(
label=_("Loop Carousel"),
required=False,
initial=False,
help_text=_(
"Turn on to make the slides loop continuously from the last slide back to the first."
),
)
space_between_slides = forms.IntegerField(
label=_("Space Between Slides"),
required=False,
initial=20,
validators=[MinValueValidator(0)],
help_text=_("Set the space (in pixels) between each slide in the carousel."),
)
autoplay = forms.BooleanField(
label=_("AutoPlay"),
required=False,
initial=True,
help_text=_(
"Turn on to make the slides move automatically without manual navigation."
),
)
delay = forms.IntegerField(
label=_("Autoplay delay"),
required=False,
initial=3000,
validators=[MinValueValidator(500)],
help_text=_(
"Set the time (in milliseconds) each slide stays visible before moving to the next one."
),
)
btn_color = forms.ChoiceField(
label=_("Button Color"),
choices=frontend_settings.COLOR_STYLE_CHOICES,
required=False,
initial="primary",
widget=ColoredButtonGroup(attrs={"class": "flex-wrap"}),
help_text=_("Color for the carousel button."),
)
def get_short_description(self):
return self.heading if self.config.get("heading") else ""
@components.register
class BenefitsPanel(CMSFrontendComponent):
"""Benefits panel component"""
class Meta:
name = _("Benefits Panel")
module = _("Sections")
render_template = "benefits/benefits_panel.html"
allow_children = True
child_classes = [
"BenefitsCardPlugin",
"TextPlugin",
"HeadingPlugin",
]
mixins = ["Background", "Spacing", "Attributes"]
background_grid = forms.BooleanField(
label=_("Show background grid"),
required=False,
initial=False,
)
@components.register
class BenefitsCard(CMSFrontendComponent):
"""Benefits card component"""
class Meta:
name = _("Benefits Card")
render_template = "benefits/benefits_card.html"
allow_children = True
parent_classes = ["BenefitsPanelPlugin"]
child_classes = [
"TextLinkPlugin",
]
mixins = ["Background", "Spacing", "Attributes"]
text_color = forms.ChoiceField(
label=_("Text color"),
choices=frontend_settings.COLOR_STYLE_CHOICES,
required=False,
initial="default",
widget=ColoredButtonGroup(attrs={"class": "flex-wrap"}),
)
card_title = forms.CharField(
label=_("Card title"),
required=False,
)
card_content = HTMLFormField(
label=_("Card content"),
required=False,
)
card_icon = IconPickerField(
label=_("Icon"),
required=False,
)
@components.register
class Navbar(CMSFrontendComponent):
"""Navbar component with background grid option"""
class Meta:
name = _("Navbar")
render_template = "navbar/navbar.html"
allow_children = True
child_classes = [
"TextLinkPlugin",
]
mixins = ["Background", "Spacing", "Attributes"]
image = ImageFormField(
label=_("Logo Image"),
required=False,
)
@components.register
class RelatedPeople(CMSFrontendComponent):
"""Related People component"""
class Meta:
name = _("Related People")
render_template = "related_people/related_people.html"
allow_children = True
child_classes = [
"HeadingPlugin",
"PeopleCardPlugin",
]
mixins = ["Background", "Spacing", "Attributes"]
eyebrow_text = forms.CharField(
label=_("Eyebrow text"),
required=False,
)
eyebrow_text_color = forms.ChoiceField(
label=_("Eyebrow text color"),
choices=frontend_settings.COLOR_STYLE_CHOICES,
required=False,
initial="default",
widget=ColoredButtonGroup(attrs={"class": "flex-wrap"}),
help_text=_("Eyebrow text color."),
)
grid_columns = forms.ChoiceField(
label=_("Grid columns"),
choices=[
("1", _("1")),
("2", _("2")),
("3", _("3")),
],
initial="3",
help_text=_("Number of grid columns."),
)
@components.register
class PeopleCard(CMSFrontendComponent):
"""People card component"""
class Meta:
name = _("People Card")
render_template = "related_people/person_card.html"
allow_children = True
parent_classes = [
"RelatedPeoplePlugin",
"GridColumnPlugin",
]
child_classes = [
"ImagePlugin",
"TextPlugin",
"HeadingPlugin",
"TextLinkPlugin",
]
mixins = ["Background", "Spacing", "Attributes"]
image_accent = forms.BooleanField(
label=_("Image accent"),
required=False,
initial=False,
help_text=_("Add image accent"),
)
image_accent_color = forms.ChoiceField(
label=_("Image accent color"),
choices=frontend_settings.COLOR_STYLE_CHOICES,
required=False,
initial="primary",
help_text=_("Image accent color."),
widget=ColoredButtonGroup(attrs={"class": "flex-wrap"}),
)
role = forms.CharField(
label=_("Role"),
required=False,
help_text=_("Role displayed in people card."),
)
description = HTMLFormField(
label=_("Description"),
required=False,
help_text=_("Description displayed in people card."),
)
text_color = forms.ChoiceField(
label=_("Text Color"),
choices=frontend_settings.COLOR_STYLE_CHOICES,
required=False,
initial="dark",
help_text=_("Card content text color."),
widget=ColoredButtonGroup(attrs={"class": "flex-wrap"}),
)
@components.register
class MembershipPlans(CMSFrontendComponent):
"""Membership component"""
class Meta:
name = _("Membership Plans")
render_template = "membership/membership_plans.html"
allow_children = True
child_classes = [
"HeadingPlugin",
"PlanCardPlugin",
"HorizontalPlanCardPlugin",
]
mixins = ["Background", "Spacing", "Attributes"]
eyebrow_text = forms.CharField(
label=_("Eyebrow text"),
required=False,
help_text=_("Eyebrow text"),
)
eyebrow_text_color = forms.ChoiceField(
label=_("Text color"),
choices=frontend_settings.COLOR_STYLE_CHOICES,
required=False,
initial="default",
widget=ColoredButtonGroup(attrs={"class": "flex-wrap"}),
help_text=_("Color for eyebrow text."),
)
@components.register
class PlanCard(CMSFrontendComponent):
"""Membership plan card component"""
class Meta:
name = _("Plan Card")
render_template = "membership/cards/plan_card.html"
allow_children = True
child_classes = [
"TextPlugin",
"SpacingPlugin",
"FeatureItemPlugin",
"TextLinkPlugin",
]
parent_classes = [
"MembershipPlansPlugin",
]
mixins = ["Background", "Spacing", "Attributes"]
card_heading = forms.CharField(
label=_("Card heading"),
required=False,
help_text=_("Card heading"),
)
card_sub_heading = forms.CharField(
label=_("Card sub heading"),
required=False,
help_text=_("Card sub heading"),
)
tier_color = forms.ChoiceField(
label=_("Tier Color"),
choices=frontend_settings.COLOR_STYLE_CHOICES,
required=False,
initial="default",
widget=ColoredButtonGroup(attrs={"class": "flex-wrap"}),
help_text=_("Tier style / Color."),
)
@components.register
class FeatureItem(CMSFrontendComponent):
"""Feature item component to render icon and text"""
class Meta:
name = _("Feature Item")
render_template = "membership/groups/feature_item.html"
allow_children = True
child_classes = [
"IconPlugin",
"TextPlugin",
]
parent_classes = [
"PlanCardPlugin",
]
@components.register
class HorizontalPlanCard(CMSFrontendComponent):
"""Membership Horizontal plan card component"""
class Meta:
name = _("Horizontal Plan Card")
render_template = "membership/cards/horizontal_plan_card.html"
allow_children = True
child_classes = [
"TextPlugin",
"SpacingPlugin",
"FeatureItemPlugin",
"TextLinkPlugin",
"ImagePlugin",
]
parent_classes = [
"MembershipPlansPlugin",
]
mixins = ["Background", "Spacing", "Attributes"]
card_heading = forms.CharField(
label=_("Card heading"),
required=True,
help_text=_("Card heading"),
)
card_sub_heading = forms.CharField(
label=_("Card sub heading"),
required=False,
help_text=_("Card sub heading"),
)
text_color = forms.ChoiceField(
label=_("Text color"),
choices=frontend_settings.COLOR_STYLE_CHOICES,
required=False,
initial="default",
widget=ColoredButtonGroup(attrs={"class": "flex-wrap"}),
)
@components.register
class ContentTeaser(CMSFrontendComponent):
"""Content Teaser component"""
class Meta:
name = _("Content Teaser")
render_template = "content_teaser/content_teaser.html"
allow_children = True
child_classes = [
"TeaserContentPlugin",
"TeaserMediaPlugin",
]
mixins = ["Background", "Spacing", "Attributes"]
@components.register
class TeaserContent(CMSFrontendComponent):
"""Teaser Content component to render text"""
class Meta:
name = _("Teaser Content")
render_template = "content_teaser/components/content.html"
allow_children = True
parent_classes = [
"ContentTeaserPlugin",
]
child_classes = [
"TextPlugin",
"HeadingPlugin",
"SpacingPlugin",
"TextLinkPlugin",
]
text_color = forms.ChoiceField(
label=_("Text color"),
choices=frontend_settings.COLOR_STYLE_CHOICES,
required=False,
initial="default",
widget=ColoredButtonGroup(attrs={"class": "flex-wrap"}),
)
@components.register
class TeaserMedia(CMSFrontendComponent):
"""Media Teaser component"""
class Meta:
name = _("Teaser Media")
render_template = "content_teaser/components/media.html"
allow_children = True
parent_classes = [
"ContentTeaserPlugin",
]
child_classes = [
"ImagePlugin",
"VideoPlayerPlugin",
]
@components.register
class QuotePanelContainer(CMSFrontendComponent):
"""Quote Panel component with background grid option"""
class Meta:
name = _("Quote Panel")
module = _("Sections")
render_template = "quote_panel/quote_panel.html"
allow_children = True
child_classes = [
"HeadingPlugin",
"QuotePanelItemPlugin",
]
mixins = ["Background", "Spacing", "Attributes"]
background_grid = forms.BooleanField(
label=_("Show background grid"),
required=False,
initial=False,
)
@components.register
class QuotePanelItem(CMSFrontendComponent):
"""Quote Panel Item component to render quote text and author"""
class Meta:
name = _("Quote Panel Item")
render_template = "quote_panel/quote_item.html"
allow_children = True
parent_classes = [
"QuotePanelContainerPlugin",
]
child_classes = [
"ImagePlugin",
]
eyebrow_text = forms.CharField(
label=_("Eyebrow text"),
required=False,
help_text=_("Eyebrow text for quote item."),
)
quote_text = HTMLFormField(
label=_("Quote text"),
required=False,
help_text=_("Main quote text for quote item."),
)
author_name = forms.CharField(
label=_("Author name"),
required=False,
help_text=_("Author name for quote item."),
)
author_role = forms.CharField(
label=_("Author role"),
required=False,
help_text=_("Author role for quote item."),
)
text_color = forms.ChoiceField(
label=_("Text color"),
choices=frontend_settings.COLOR_STYLE_CHOICES,
required=False,
initial="dark",
widget=ColoredButtonGroup(attrs={"class": "flex-wrap"}),
help_text=_("Text color for quote item."),
)
@components.register
class Heading(CMSFrontendComponent):
"""Heading component with text color option"""
HEADINGS = (
("h1", _("Heading 1")),
("h2", _("Heading 2")),
("h3", _("Heading 3")),
("h4", _("Heading 4")),
("h5", _("Heading 5")),
)
class Meta:
name = _("Heading")
render_template = "heading/heading.html"
allow_children = True
child_classes = []
frontend_editable_fields = ("heading", "overline")
heading_level = forms.ChoiceField(
label=_("Heading level"),
choices=getattr(frontend_settings, "DJANGO_FRONTEND_HEADINGS", HEADINGS),
required=True,
)
overline = forms.CharField(
label=_("Eyebrow text"),
required=False,
)
heading = forms.CharField(
label=_("Heading"),
required=True,
)
heading_context = forms.ChoiceField(
label=_("Heading context"),
required=False,
choices=frontend_settings.EMPTY_CHOICE + frontend_settings.COLOR_STYLE_CHOICES,
initial=frontend_settings.EMPTY_CHOICE,
widget=ColoredButtonGroup(),
)
def get_short_description(self):
return f"{self.heading} ({self.heading_level})" if self.config.get("heading") else ""
@components.register
class Spacing(CMSFrontendComponent):
"""Spacing component to add vertical spacing between components"""
class Meta:
name = _("Spacing")
render_template = "spacing/spacing.html"
allow_children = True
mixins = ["Attributes"]
space_property = forms.ChoiceField(
label=_("Property"),
choices=frontend_settings.SPACER_PROPERTY_CHOICES,
initial=first_choice(frontend_settings.SPACER_PROPERTY_CHOICES),
widget=ButtonGroup(attrs=dict(property="text")),
)
space_sides = forms.ChoiceField(
label=_("Sides"),
choices=frontend_settings.SPACER_SIDE_CHOICES,
initial=first_choice(frontend_settings.SPACER_SIDE_CHOICES),
required=False,
widget=ButtonGroup(attrs=dict(property="text")),
)
space_size = forms.ChoiceField(
label=_("Size"),
choices=frontend_settings.SPACER_SIZE_CHOICES + (("auto", _("Auto")),),
initial=first_choice(frontend_settings.SPACER_SIZE_CHOICES),
widget=ButtonGroup(attrs=dict(property="text")),
)
space_device = forms.ChoiceField(
label=_("Device"),
choices=frontend_settings.EMPTY_CHOICE + frontend_settings.DEVICE_CHOICES,
initial=frontend_settings.EMPTY_CHOICE[0][0],
required=False,
widget=IconGroup(),
)
def clean(self):
super().clean()
if self.cleaned_data["space_property"] == "p" and self.cleaned_data["space_size"] == "auto":
raise ValidationError(
{
"space_property": _(
"Padding does not have an auto spacing. Either switch to margin or a defined size."
),
"space_size": _(
"Padding does not have an auto spacing. Either "
"switch to a defined size or change the spacing property."
),
}
)
@components.register
class CodeBlock(CMSFrontendComponent):
"""Code card component to render code snippets with syntax highlighting"""
class Media:
js = (
"admin/vendor/ace/ace.js"
if "djangocms_static_ace" in settings.INSTALLED_APPS
else "https://cdnjs.cloudflare.com/ajax/libs/ace/1.43.3/ace.js",
)
class Meta:
name = _("Code Block")
render_template = "code_block/code_block.html"
change_form_template = "code_block/admin/code_block.html"
allow_children = True
child_classes = []
mixins = ["Background", "Spacing", "Attributes"]
frontend_editable_fields = ("heading",)
heading = forms.CharField(
label=_("Heading"),
required=False,
help_text=_("Heading for the code block."),
)
dark_mode = forms.BooleanField(
label=_("Dark mode"),
required=False,
initial=False,
help_text=_("Enable dark mode for code block."),
)
code_content = forms.CharField(
label=_("Code"),
initial="",
required=True,
widget=forms.widgets.Textarea(attrs={"class": "js-ckeditor-use-selected-text"}),
)