1from wagtail.blocks import (
2 BooleanBlock,
3 StructBlock,
4 StreamBlock,
5 CharBlock,
6 RichTextBlock,
7 ListBlock,
8 TextBlock,
9)
10from wagtail.images.blocks import ImageChooserBlock
11from wagtail.fields import RichTextField, StreamField
12from django.db import models
13
14
15class CustomImageChooserBlock(ImageChooserBlock):
16 def get_api_representation(self, value, context=None):
17 if value:
18 return {
19 "id": value.id,
20 "title": value.title,
21 "url": value.get_rendition("original").url,
22 "thumbnail": value.get_rendition("fill-300x200").url,
23 "description": value.description,
24 }
25 return None
26
27
28class NoteBlock(StructBlock):
29 content = RichTextBlock(help_text="Conteúdo da nota")
30 type = CharBlock(
31 choices=[
32 ("info", "Informação"),
33 ("warning", "Aviso"),
34 ("danger", "Perigo"),
35 ("success", "Sucesso"),
36 ],
37 default="info",
38 help_text="Tipo de nota",
39 )
40
41 class Meta:
42 icon = "info"
43 label = "Nota"
44 block_api_representation = "expand"
45
46
47class TableBlock(StructBlock):
48 headers = ListBlock(CharBlock(), help_text="Cabeçalhos da tabela")
49 rows = ListBlock(
50 ListBlock(RichTextBlock(), min_num=1), help_text="Linhas da tabela"
51 )
52
53 class Meta:
54 icon = "table"
55 label = "Tabela"
56 block_api_representation = "expand"
57
58
59class CodeFileBlock(StructBlock):
60 filename = CharBlock(help_text="Name of the file")
61 language = CharBlock(
62 choices=[
63 ("bash", "Bash"),
64 ("django", "Django"),
65 ("dockerfile", "Dockerfile"),
66 ("pgsql", "Pgsql"),
67 ("shell", "Shell"),
68 ("python", "Python"),
69 ("makefile", "Makefile"),
70 ("javascript", "JavaScript"),
71 ("typescript", "TypeScript"),
72 ("css", "CSS"),
73 ("scss", "SCSS"),
74 ("json", "JSON"),
75 ("yaml", "YAML"),
76 ("markdown", "Markdown"),
77 ("rust", "Rust"),
78 ("go", "Go"),
79 ("dart", "Dart"),
80 ("shell", "Shell/Bash"),
81 ("sql", "SQL"),
82 ],
83 default="python",
84 )
85 code = TextBlock(help_text="Code content for the file")
86
87
88class NoteBlock(StructBlock):
89 content = RichTextBlock(help_text="Conteúdo da nota")
90 type = CharBlock(
91 choices=[
92 ("info", "Informação"),
93 ("warning", "Aviso"),
94 ("danger", "Perigo"),
95 ("success", "Sucesso"),
96 ],
97 default="info",
98 help_text="Tipo de nota",
99 )
100
101 class Meta:
102 icon = "info"
103 label = "Nota"
104 block_api_representation = "expand"
105
106
107class TableBlock(StructBlock):
108 headers = ListBlock(CharBlock(), help_text="Cabeçalhos da tabela")
109 rows = ListBlock(
110 ListBlock(RichTextBlock(), min_num=1), help_text="Linhas da tabela"
111 )
112
113 class Meta:
114 icon = "table"
115 label = "Tabela"
116 block_api_representation = "expand"
117
118
119class OrderedListBlock(StructBlock):
120 items = ListBlock(RichTextBlock(), help_text="Lista de items")
121
122 class Meta:
123 icon = "list-ol"
124 label = "Lista Ordenada"
125 block_api_representation = "expand"
126
127
128class UnorderedListBlock(StructBlock):
129 items = ListBlock(RichTextBlock(), help_text="Lista de items")
130
131 class Meta:
132 icon = "list-ul"
133 label = "Lista Não Ordenada"
134 block_api_representation = "expand"
135
136
137class CodeBlock(StructBlock):
138 files = ListBlock(CodeFileBlock(), help_text="Multiple code files")
139
140 class Meta:
141 icon = "code"
142 block_api_representation = "expand"
143
144
145class Image(StructBlock):
146 image = CustomImageChooserBlock()
147
148 class Meta:
149 icon = "image"
150 block_api_representation = "expand"
151
152
153class QuoteBlock(Image):
154 quote = RichTextBlock(help_text="Texto da citação")
155 attribution = CharBlock(required=False, help_text="Autor da citação")
156 role = CharBlock(required=False, help_text="Cargo ou função do autor")
157
158 class Meta:
159 icon = "openquote"
160 block_api_representation = "expand"
161
162
163class ImageText(Image):
164 reverse = BooleanBlock(required=False)
165 text = RichTextBlock()
166
167 class Meta:
168 block_api_representation = "expand"
169
170
171class EmbedBlock(StructBlock):
172 PROVIDER_CHOICES = [
173 ("youtube", "YouTube"),
174 ("vimeo", "Vimeo"),
175 ("instagram", "Instagram"),
176 ("twitter", "Twitter"),
177 ("tiktok", "TikTok"),
178 ("soundcloud", "SoundCloud"),
179 ("spotify", "Spotify"),
180 ("other", "Outro Site"),
181 ]
182
183 provider = CharBlock(
184 choices=PROVIDER_CHOICES, help_text="Selecione a plataforma de mídia"
185 )
186
187 embed_code = CharBlock(
188 required=False,
189 help_text="Código de incorporação fornecido pelo site (se disponível)",
190 )
191
192 url = CharBlock(help_text="URL completa do conteúdo a ser incorporado")
193 caption = CharBlock(required=False, help_text="Legenda opcional para o embed")
194
195 class Meta:
196 icon = "media"
197 label = "Incorporar Mídia"
198 block_api_representation = "expand"
199
200
201class BodyBlock(StreamBlock):
202 h1 = CharBlock()
203 h2 = CharBlock()
204 paragraph = RichTextBlock()
205 code = CodeBlock()
206 quote = QuoteBlock()
207 image = Image()
208 image_text = ImageText()
209 image_carousel = ListBlock(CustomImageChooserBlock())
210 thumbnail_gallery = ListBlock(CustomImageChooserBlock())
211 ordered_list = OrderedListBlock()
212 unordered_list = UnorderedListBlock()
213 note = NoteBlock()
214 table = TableBlock()
215 embed = EmbedBlock()