Skip to content

Instantly share code, notes, and snippets.

Avatar

Kalob Taulien KalobTaulien

View GitHub Profile
@KalobTaulien
KalobTaulien / models.py
Created February 22, 2022 20:51
Nested Wagtail StreamBlocks for nested sidebar content
View models.py
from wagtail.core.models import Page
from wagtail.core import blocks
from wagtail.images.blocks import ImageChooserBlock
class NestedSidebarContent(blocks.StructBlock):
sidebar_alignment = blocks.ChoiceBlock(choices=(
("left", "Left"),
("right", "Right"),
))
main_content2 = blocks.StreamBlock([
@KalobTaulien
KalobTaulien / button-block.css
Created October 4, 2019 16:55
Wagtail/Draftail button links
View button-block.css
/* Goes into /static/css/button-block.css */
/**
* Add some spacing to the button-section inside of Draftail.
*/
.Draftail-block--button-block {
padding-top: 25px;
padding-bottom: 15px;
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
@KalobTaulien
KalobTaulien / blog models.py
Created April 23, 2019 17:16
Wagtail: Adding author filtering
View blog models.py
# blog/models.py
# Nothing in this class has changed. I just put it here for reference.
class BlogAuthor(models.Model):
"""Blog author for snippets."""
name = models.CharField(max_length=100)
website = models.URLField(blank=True, null=True)
image = models.ForeignKey(
"wagtailimages.Image",
@KalobTaulien
KalobTaulien / dev[dot]py
Created April 8, 2019 15:01
Enabling the Wagtail Styleguide
View dev[dot]py
# dev.py
INSTALLED_APPS = INSTALLED_APPS + [
# ...
'wagtail.contrib.styleguide',
# ...
]
@KalobTaulien
KalobTaulien / home page models
Created April 3, 2019 15:11
Typing Text On HomePage with Orderable
View home page models
"""Home page."""
from django.db import models
from modelcluster.fields import ParentalKey
from wagtail.admin.edit_handlers import (
FieldPanel,
InlinePanel,
MultiFieldPanel,
)
from wagtail.core.models import Orderable, Page
@KalobTaulien
KalobTaulien / custom_streamfield.py
Created March 24, 2019 23:16
StructBlock StreamField Validation
View custom_streamfield.py
from django.core.exceptions import ValidationError
from django.forms.utils import ErrorList
from wagtail.core import blocks
class CTABlock(blocks.StructBlock):
"""A simple call to action section."""
button_url = blocks.URLBlock(required=False)
@KalobTaulien
KalobTaulien / paste into your browsers console
Created March 20, 2019 15:40
Testing your Wagtail V2 API with JavaScript
View paste into your browsers console
fetch('http://localhost:8000/api/v2/pages/')
.then(res => res.json())
.then(response => console.log(response))
@KalobTaulien
KalobTaulien / staff author_page.html
Created February 28, 2019 22:02
Getting BlogPostPages by their assigned authors
View staff author_page.html
{% extends 'base.html' %}
{% block content %}
{% for post in posts %}
{{ post.title }}
{% endfor %}
{% endblock %}
@KalobTaulien
KalobTaulien / base.py
Last active February 8, 2019 23:34
Adding a new Subscribers model to the Wagtail ModelAdmin. Tutorial at: https://learnwagtail.com/tutorials/how-register-django-model-wagtails-modeladmin/
View base.py
# ...
INSTALLED_APPS = [
# ...
'subscribers',
'wagtail.contrib.modeladmin',
# ...
]
# ...
View site_settings models.py
#site_settings/models.py
from django.db import models
from wagtail.admin.edit_handlers import FieldPanel, MultiFieldPanel
from wagtail.contrib.settings.models import BaseSetting, register_setting
@register_setting
class SocialMediaSettings(BaseSetting):
"""Social media settings for our custom website."""