Skip to content

Instantly share code, notes, and snippets.

View KalobTaulien's full-sized avatar

Kalob Taulien KalobTaulien

View GitHub Profile
@KalobTaulien
KalobTaulien / models.py
Created February 22, 2022 20:51
Nested Wagtail StreamBlocks for nested sidebar content
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
/* 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
# 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
# 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
"""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
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
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
{% 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/
# ...
INSTALLED_APPS = [
# ...
'subscribers',
'wagtail.contrib.modeladmin',
# ...
]
# ...
#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."""