Skip to content

Instantly share code, notes, and snippets.

View KalobTaulien's full-sized avatar

Kalob Taulien KalobTaulien

View GitHub Profile
@KalobTaulien
KalobTaulien / yourpage.py
Created July 21, 2018 18:38
Wagtail 2: How to limit one page type per site.
from wagtail.core.models import Page
class YourPage(Page):
"""Your Wagtail Page Type."""
template = "templates/home_page.html"
@classmethod
def can_create_at(cls, parent):
@KalobTaulien
KalobTaulien / INSTALL
Last active August 11, 2023 15:38
Force lowercase paths using NGINX. Does not affect query params.
# On Ubuntu run `sudo apt-get install nginx-extras` for perl scripts to run
# `sudo service nginx restart` (verify it restarted properly)
# Add nginx.conf perl function; add yoursite.conf location
@KalobTaulien
KalobTaulien / yourpage.py
Created July 21, 2018 19:11
Wagtail 2: Changing the title and help text of a default Wagtail Page field
from wagtail.core.models import Page
class YourPage(Page):
"""Your Wagtail Page Type."""
template = "templates/your_page.html"
# Other Page fields
@KalobTaulien
KalobTaulien / banner.py
Created July 21, 2018 23:06
Wagtail 2: Adding a Banner Mixin to your Wagtail Pages
from django.db import models
from wagtail.core.fields import RichTextField
from wagtail.search import index
from wagtail.admin.edit_handlers import FieldPanel, PageChooserPanel
from wagtail.images.edit_handlers import ImageChooserPanel
class Banner(models.Model):
"""Banner mixin for a page."""
#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."""
@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 / 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',
# ...
]