Skip to content

Commit a1ef7d8

Browse files
KhaRineee
authored andcommitted
academy/models.py & /blocks.py & block_topic_teaser.html & _blocks.scss
1 parent 41be358 commit a1ef7d8

File tree

6 files changed

+135
-14
lines changed

6 files changed

+135
-14
lines changed

apps/academy/blocks.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
from wagtail.blocks import (CharBlock, ListBlock, PageChooserBlock,
2-
RichTextBlock, StructBlock, TextBlock, URLBlock)
1+
from django.template.defaulttags import register
2+
from wagtail.blocks import (CharBlock, ChoiceBlock, ListBlock,
3+
PageChooserBlock, RichTextBlock, StructBlock,
4+
TextBlock, URLBlock)
35
from wagtail.images.blocks import ImageChooserBlock
46

7+
from apps.academy.choices import TOPIC_CHOICES
8+
59

610
class ChallengeStepBlock(StructBlock):
711
challenge_step_title = CharBlock()
@@ -82,3 +86,37 @@ class Meta:
8286
icon = 'plus-inverse'
8387
help_text = 'Add 1 or 2 column teaser with black '
8488
'background and white writing'
89+
90+
91+
class TopicBlock(StructBlock):
92+
topic_category = ChoiceBlock(
93+
choices=TOPIC_CHOICES,
94+
required=True,
95+
help_text='Select a topic'
96+
)
97+
topic_text = CharBlock(required=True, max_length=110)
98+
topic_link_text = CharBlock(required=True, max_length=40)
99+
100+
101+
class TopicBlockList(StructBlock):
102+
title = CharBlock(required=True, max_length=74)
103+
topics = ListBlock(TopicBlock(), min_num=3, max_num=3)
104+
topic_url = PageChooserBlock(
105+
required=True,
106+
page_type='academy.AcademyIndexPage'
107+
)
108+
109+
def get_context(self, value, parent_context=None):
110+
context = super().get_context(value, parent_context=parent_context)
111+
context['topics_dict'] = dict(TOPIC_CHOICES)
112+
return context
113+
114+
class Meta:
115+
template = 'academy/blocks/block_topic_teaser.html'
116+
icon = 'grip'
117+
label = '3 topic teasers'
118+
119+
120+
@register.filter
121+
def get_category_name(dict, key):
122+
return dict.get(key)

apps/academy/choices.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from django.utils.translation import gettext_lazy as _
2+
3+
LIQDTHEORY = 'LT'
4+
DIGITALCIVICSOCIETY = 'DS'
5+
PARTICIPATIONACTION = 'PA'
6+
7+
TOPIC_CHOICES = [
8+
(LIQDTHEORY, _('Liquid Democracy: Theory & Vision')),
9+
(DIGITALCIVICSOCIETY, _('Digital Civic Society')),
10+
(PARTICIPATIONACTION, _('Digital Participation In Action'))
11+
]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Generated by Django 3.2.13 on 2022-08-25 09:26
2+
3+
from django.db import migrations
4+
import wagtail.blocks
5+
import wagtail.fields
6+
import wagtail.images.blocks
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
dependencies = [
12+
('academy', '0012_fix_max_length'),
13+
]
14+
15+
operations = [
16+
migrations.AlterField(
17+
model_name='academylandingpage',
18+
name='body_de',
19+
field=wagtail.fields.StreamField([('single_teaser', wagtail.blocks.StructBlock([('category', wagtail.blocks.CharBlock(max_length=32, required=False)), ('headline', wagtail.blocks.CharBlock(max_length=74, required=True)), ('body_text', wagtail.blocks.TextBlock(max_length=164, required=True)), ('link', wagtail.blocks.PageChooserBlock(help_text='Please only add either an internal or external link', required=False)), ('external_link', wagtail.blocks.URLBlock(help_text='The external link overwrites the link to a local page.', label='External Link', required=False)), ('link_text', wagtail.blocks.CharBlock(max_length=24, required=True)), ('image', wagtail.images.blocks.ImageChooserBlock(required=True))])), ('call_to_action_teaser', wagtail.blocks.StructBlock([('columns', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('headline', wagtail.blocks.CharBlock(max_length=28, required=True)), ('image', wagtail.images.blocks.ImageChooserBlock(help_text='Please add image with transparent background', required=True)), ('body_text', wagtail.blocks.TextBlock(max_length=120, required=True)), ('cta_link', wagtail.blocks.StructBlock([('internal_link', wagtail.blocks.PageChooserBlock(help_text='The external link overwrites the link to a local page. Please only add 1 link.', required=False)), ('external_link', wagtail.blocks.URLBlock(required=False))])), ('link_text', wagtail.blocks.CharBlock(label='Link Text', max_length=28, required=False)), ('anchor_link', wagtail.blocks.CharBlock(help_text='Anchor link should be all one word.', label='Anchor Link', max_length=28, required=False))], label='List and Image'), max_num=2))])), ('topic_block_list', wagtail.blocks.StructBlock([('title', wagtail.blocks.CharBlock(max_length=74, required=True)), ('topics', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('topic_category', wagtail.blocks.ChoiceBlock(choices=[('LT', 'Liquid Democracy: Theory & Vision'), ('DS', 'Digital Civic Society'), ('PA', 'Digital Participation In Action')], help_text='Select a topic')), ('topic_text', wagtail.blocks.CharBlock(max_length=110, required=True)), ('topic_link_text', wagtail.blocks.CharBlock(max_length=40, required=True))]), max_num=3, min_num=3)), ('topic_url', wagtail.blocks.PageChooserBlock(page_type=['academy.AcademyIndexPage'], required=True))]))], blank=True, null=True, use_json_field=True, verbose_name='Body'),
20+
),
21+
migrations.AlterField(
22+
model_name='academylandingpage',
23+
name='body_en',
24+
field=wagtail.fields.StreamField([('single_teaser', wagtail.blocks.StructBlock([('category', wagtail.blocks.CharBlock(max_length=32, required=False)), ('headline', wagtail.blocks.CharBlock(max_length=74, required=True)), ('body_text', wagtail.blocks.TextBlock(max_length=164, required=True)), ('link', wagtail.blocks.PageChooserBlock(help_text='Please only add either an internal or external link', required=False)), ('external_link', wagtail.blocks.URLBlock(help_text='The external link overwrites the link to a local page.', label='External Link', required=False)), ('link_text', wagtail.blocks.CharBlock(max_length=24, required=True)), ('image', wagtail.images.blocks.ImageChooserBlock(required=True))])), ('call_to_action_teaser', wagtail.blocks.StructBlock([('columns', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('headline', wagtail.blocks.CharBlock(max_length=28, required=True)), ('image', wagtail.images.blocks.ImageChooserBlock(help_text='Please add image with transparent background', required=True)), ('body_text', wagtail.blocks.TextBlock(max_length=120, required=True)), ('cta_link', wagtail.blocks.StructBlock([('internal_link', wagtail.blocks.PageChooserBlock(help_text='The external link overwrites the link to a local page. Please only add 1 link.', required=False)), ('external_link', wagtail.blocks.URLBlock(required=False))])), ('link_text', wagtail.blocks.CharBlock(label='Link Text', max_length=28, required=False)), ('anchor_link', wagtail.blocks.CharBlock(help_text='Anchor link should be all one word.', label='Anchor Link', max_length=28, required=False))], label='List and Image'), max_num=2))])), ('topic_block_list', wagtail.blocks.StructBlock([('title', wagtail.blocks.CharBlock(max_length=74, required=True)), ('topics', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('topic_category', wagtail.blocks.ChoiceBlock(choices=[('LT', 'Liquid Democracy: Theory & Vision'), ('DS', 'Digital Civic Society'), ('PA', 'Digital Participation In Action')], help_text='Select a topic')), ('topic_text', wagtail.blocks.CharBlock(max_length=110, required=True)), ('topic_link_text', wagtail.blocks.CharBlock(max_length=40, required=True))]), max_num=3, min_num=3)), ('topic_url', wagtail.blocks.PageChooserBlock(page_type=['academy.AcademyIndexPage'], required=True))]))], null=True, use_json_field=True, verbose_name='Body'),
25+
),
26+
]

apps/academy/models.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,18 @@
1616
from wcag_contrast_ratio import contrast
1717

1818
from apps.academy.blocks import (AcademyCallToActionBlock,
19-
AcademySingleTeaserBlock, ChallengeStepBlock)
19+
AcademySingleTeaserBlock, ChallengeStepBlock,
20+
TopicBlockList)
21+
from apps.academy.choices import TOPIC_CHOICES
2022
from apps.blog.models import AbstractBlogPage
2123
from contrib.translations.translations import TranslatedField
2224

23-
LIQDTHEORY = 'LT'
24-
DIGITALCIVICSOCIETY = 'DS'
25-
PARTICIPATIONACTION = 'PA'
26-
2725
VIDEO = 'VD'
2826
WORKSHOP = 'WS'
2927
LINKLIST = 'LL'
3028
ARTICLE = 'AR'
3129
EVENT = 'EV'
3230

33-
TOPIC_CHOICES = [
34-
(LIQDTHEORY, _('Liquid Democracy: Theory & Vision')),
35-
(DIGITALCIVICSOCIETY, _('Digital Civic Society')),
36-
(PARTICIPATIONACTION, _('Digital Participation In Action')),
37-
]
38-
3931
CONTENT_TYPE_CHOICES = [
4032
(VIDEO, _('video')),
4133
(WORKSHOP, _('workshop')),
@@ -50,7 +42,8 @@
5042

5143
STREAMFIELD_LP_BLOCKS = [
5244
('single_teaser', AcademySingleTeaserBlock()),
53-
('call_to_action_teaser', AcademyCallToActionBlock())
45+
('call_to_action_teaser', AcademyCallToActionBlock()),
46+
('topic_block_list', TopicBlockList())
5447
]
5548

5649
STREAMFIELD_EXTRA_BLOCKS = [
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{% load static wagtailimages_tags i18n %}
2+
3+
<section class="row block" aria-label="three topic teasers">
4+
<h2 class="academy-block__title">{{value.title}}</h2>
5+
{% for topic in value.topics %}
6+
<article class="col-md-4 col-sm-12 container">
7+
<figure class="mb-4">
8+
{% with 'images/'|add:topic.topic_category|add:'-topic.svg' as topic_svg %}
9+
<img
10+
class="academy-block__img mx-auto"
11+
src="{% static topic_svg %}"
12+
alt="{{ topics_dict|get_category_name:topic.topic_category }}"
13+
width="70"
14+
/>
15+
{% endwith %}
16+
</figure>
17+
<h3 class="academy-block__title">
18+
{{ topics_dict|get_category_name:topic.topic_category }}
19+
</h3>
20+
<p class="academy-block__text">{{topic.topic_text}}</p>
21+
<div class="academy-block__link mb-4">
22+
<a
23+
href="{{ value.topic_url.url }}?topic={{ topic.topic_category }}&academy_content_type=&alphabetical="
24+
>
25+
{{topic.topic_link_text}}
26+
</a>
27+
</div>
28+
</article>
29+
{% endfor %}
30+
</section>

apps/core/static/scss/_blocks.scss

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,26 @@
153153
}
154154
}
155155
}
156+
157+
.academy-block__img {
158+
width: 81px;
159+
height: 75px;
160+
object-fit: contain;
161+
display: block;
162+
}
163+
164+
.academy-block__title {
165+
font-family: $font-family-monospace;
166+
font-size: $font-size-xs;
167+
text-align: center;
168+
text-transform: uppercase;
169+
}
170+
171+
.academy-block__text {
172+
font-size: $font-size-sm;
173+
text-align: center;
174+
}
175+
176+
.academy-block__link {
177+
text-align: center;
178+
}

0 commit comments

Comments
 (0)