Skip to content

Commit a41dabf

Browse files
committed
display value for LinkBlocks
1 parent f8aa3b0 commit a41dabf

File tree

5 files changed

+42
-30
lines changed

5 files changed

+42
-30
lines changed

api/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class CustomizationRequest(models.Model):
1919
complete = models.BooleanField(default=False)
2020
created = models.DateTimeField(auto_now_add=True)
2121

22+
2223
class FeatureFlag(models.Model):
2324
name = models.CharField(max_length=255, unique=True, help_text='Create flag names with underscores to be more machine friendly. Eg. awesome_feature')
2425
description = models.TextField(blank=True, default='')
@@ -29,6 +30,7 @@ class FeatureFlag(models.Model):
2930
def __str__(self):
3031
return self.name
3132

33+
3234
class WebviewSettings(models.Model):
3335
name = models.CharField(max_length=255, unique=True)
3436
value = models.CharField(max_length=255)

api/serializers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from wagtail.documents.models import Document
55
from api.models import ProgressTracker, CustomizationRequest
66

7+
78
class AdopterSerializer(serializers.HyperlinkedModelSerializer):
89

910
class Meta:
@@ -72,6 +73,7 @@ class ModuleListingField(serializers.StringRelatedField):
7273
def to_internal_value(self, value):
7374
return value
7475

76+
7577
class CustomizationRequestSerializer(serializers.ModelSerializer):
7678
modules = ModuleListingField(many=True)
7779

openstax/settings/base.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,10 @@
406406
WAGTAIL_USAGE_COUNT_ENABLED = False
407407
WAGTAIL_USER_CUSTOM_FIELDS = ['is_staff']
408408
WAGTAIL_GRAVATAR_PROVIDER_URL = '//www.gravatar.com/avatar'
409+
# serve wagtail documents direct for use with remote (s3) storage
410+
WAGTAILADMIN_EXTERNAL_LINK_CONVERSION = 'exact'
411+
WAGTAIL_REDIRECTS_FILE_STORAGE = 'cache'
412+
WAGTAILFORMS_HELP_TEXT_ALLOW_HTML = True
409413

410414
WAGTAILSEARCH_BACKENDS = {
411415
'default': {
@@ -455,6 +459,14 @@
455459
},
456460
}
457461

462+
from wagtail.embeds.oembed_providers import youtube, vimeo
463+
WAGTAILEMBEDS_FINDERS = [
464+
{
465+
'class': 'wagtail.embeds.finders.oembed',
466+
'providers': [youtube, vimeo]
467+
}
468+
]
469+
458470
##########
459471
# Sentry #
460472
##########

pages/custom_blocks.py

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
from django import forms
2-
from filetype.types import document
32

43
from wagtail import blocks
5-
from wagtail.blocks import FieldBlock, StructBlock, StructValue
4+
from wagtail.blocks import FieldBlock, StructBlock
65
from wagtail.images.blocks import ImageChooserBlock
76
from wagtail.documents.blocks import DocumentChooserBlock
8-
from wagtail.models import Page
97

108
from api.serializers import ImageSerializer
119
from openstax.functions import build_image_url, build_document_url
@@ -21,27 +19,6 @@ class Meta:
2119
icon = 'doc-full'
2220

2321

24-
class LinkStructValue(StructValue):
25-
def url(self):
26-
if self['external']:
27-
return self['external']
28-
elif self['internal']:
29-
return self['internal']
30-
elif self['document']:
31-
return build_document_url(self['document'].url)
32-
else:
33-
return 'link issue'
34-
35-
def text(self):
36-
return self['text']
37-
38-
def link_aria_label(self):
39-
return self['link_aria_label']
40-
41-
def __bool__(self):
42-
return bool(self.url())
43-
44-
4522
class LinkBlock(blocks.StreamBlock):
4623
external = blocks.URLBlock(required=False)
4724
internal = blocks.PageChooserBlock(required=False)
@@ -52,7 +29,26 @@ class Meta:
5229
max_num = 1
5330

5431
def get_api_representation(self, value, context=None):
55-
return self.render_basic(value)
32+
for child in value:
33+
if child.block_type == 'document':
34+
return {
35+
'value': child.value.url,
36+
'type': child.block_type,
37+
'metadata': child.value.content_type,
38+
}
39+
elif child.block_type == 'external':
40+
return {
41+
'value': child.block.get_prep_value(child.value),
42+
'type': child.block_type,
43+
}
44+
elif child.block_type == 'internal':
45+
return {
46+
'value': child.value.url_path,
47+
'type': child.block_type,
48+
}
49+
else:
50+
return None
51+
5652

5753
class CTALinkBlock(blocks.StructBlock):
5854
text = blocks.CharBlock(required=True)
@@ -62,7 +58,7 @@ class CTALinkBlock(blocks.StructBlock):
6258
class Meta:
6359
icon = 'placeholder'
6460
label = "Call to Action"
65-
value_class = LinkStructValue
61+
6662

6763
class CTAButtonBarBlock(blocks.StructBlock):
6864
actions=blocks.ListBlock(CTALinkBlock(required=False, label="Button"),
@@ -74,7 +70,6 @@ class CTAButtonBarBlock(blocks.StructBlock):
7470
class Meta:
7571
icon = 'placeholder'
7672
label = "Calls to Action"
77-
value_class = LinkStructValue
7873

7974
class ImageFormatChoiceBlock(FieldBlock):
8075
field = forms.ChoiceField(required=False, choices=(

pages/models.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
AllyLogoBlock, \
3434
AssignableBookBlock, \
3535
DividerBlock, \
36-
APIRichTextBlock, CTAButtonBarBlock, CTALinkBlock, FAQBlock
36+
APIRichTextBlock, \
37+
CTAButtonBarBlock
3738

38-
from .custom_fields import \
39-
Group
39+
from .custom_fields import Group
4040
import snippets.models as snippets
4141

4242
# Constants for styling options on Root/Flex pages
@@ -78,6 +78,7 @@
7878
('cta_block', CTAButtonBarBlock()),
7979
]
8080

81+
8182
class LayoutSnippetSerializer(Field):
8283
def to_representation(self, value):
8384
return {

0 commit comments

Comments
 (0)