BE: MozFest Spaces Cards#7456
Conversation
| @@ -0,0 +1,23 @@ | |||
| # Generated by Django 3.1.11 on 2021-09-22 13:02 | |||
There was a problem hiding this comment.
It's usually helpful to give migrations names.
You can name your migrations with python manage.py makemigrations -n some_name_here.
Outputs: 0021_some_name_here.py
| class SpaceCardBlockStructValue(blocks.StructValue): | ||
| @property | ||
| def link(self): | ||
| link_url = self.get('link_url') | ||
| link_page = self.get('link_page') | ||
|
|
||
| if link_url: | ||
| return link_url | ||
| elif link_page: | ||
| return link_page.url |
There was a problem hiding this comment.
This seems like a common enough structure that it might makes sense to move this to somewhere shared.
| link_page = blocks.PageChooserBlock( | ||
| required=False, | ||
| help_text='Page that this card should link out to.', | ||
| ) | ||
|
|
||
| link_url = blocks.URLBlock( | ||
| required=False, | ||
| help_text='URL that this card should link out to.', | ||
| ) | ||
|
|
||
| def clean(self, value): | ||
| errors = {} | ||
|
|
||
| link_page = value.get('link_page') | ||
| link_url = value.get('link_url') | ||
|
|
||
| if (link_page and link_url) or (not link_page and not link_url): | ||
| errors['link_page'] = ErrorList(['Please specify either a link page or a link URL.']) | ||
| errors['link_url'] = ErrorList(['Please specify either a link page or a link URL.']) | ||
|
|
||
| if errors: | ||
| raise StructBlockValidationError(errors) | ||
|
|
||
| return super().clean(value) |
There was a problem hiding this comment.
I assume you put these here instead of SpaceCardBlockStructValue because of the field order in the editor?
|
Hey @SharmaineLim and @Pomax! Whenever it's convenient, would you mind reviewing this new StructBlock field? Thank you! |
SharmaineLim
left a comment
There was a problem hiding this comment.
Overall, LGTM. See comment.
| image = ImageChooserBlock() | ||
|
|
||
| title = blocks.CharBlock( | ||
| help_text='Heading for the card.' | ||
| ) | ||
|
|
||
| body = blocks.TextBlock( | ||
| help_text='Body text of the card.' | ||
| ) | ||
|
|
||
| link = blocks.StreamBlock( | ||
| [ | ||
| ('internal', blocks.PageChooserBlock(help_text='Page that this card should link out to.')), | ||
| ('external', blocks.URLBlock(help_text='URL that this card should link out to.')), | ||
| ], | ||
| max_num=1, | ||
| ) |
There was a problem hiding this comment.
Also, something to check: do pages here already have listing_image, listing_title and listing_summary (or similar)?
There was a problem hiding this comment.
This new StructBlock shares the most similarity to CardGrid.
Related PRs/issues #7428
Created a new StructBlock field called
SpaceCardListBlockcontaining a heading and a list of child blocks namedSpaceCardBlockthat have their own titles, plain-text bodies, images, and links to either a Wagtail page or an external URL.Also added a card template similar to an existing card block.
Checklist
Changes in Models: