Skip to content

Instantly share code, notes, and snippets.

View zerolab's full-sized avatar
🖖
Live long and prosper

Dan Braghiș zerolab

🖖
Live long and prosper
View GitHub Profile
@zerolab
zerolab / README.md
Last active July 7, 2025 14:06
Wagtail read-only workflow step

This is an example of a read-only Wagtail workflow task that still allows comments.

Note

This was written for Wagtail 6.3/6.4 and may need small adjustments in the monkey-patched EditView

The code was in a workflows app in a Django project with the layout

.
└── myproject/
 └── workflows/
@zerolab
zerolab / README.md
Last active September 2, 2025 13:54
Wagtail: Ignore StreamFields in migrations

Changes to Wagtail StreamField definitions will generate new migrations. This is in line with Django's philosophy and helps with data migrations. For complex definitions, the generated migrations were quite big. Wagtail 6.2 improved the generated migrations, making them much smaller, but they are still required. Reference: wagtail/wagtail#4298

However, for cases where data migrations are not necessary and are in active development, the need for the Django migration files become an unnecessary burden. To disable that you can use a modified version of StreamField as seen in fields.py.

Dev notes:

  • Add fields.py to your app.
  • Replace usages of from wagtail.fields import StreamField with from your_app.fields import StreamField
# myapp/management/commands/fix_alias_page_first_last_published.py
from django.core.management.base import BaseCommand
from django.db.models import Q
from wagtail.core.models import Page
class Command(BaseCommand):
def handle(self, **options):
@zerolab
zerolab / elasticsearch7.py
Created June 18, 2021 09:28
RootFilterField in Wagtail -- enables you to index the field without the specific page model string prefix
from wagtail.search.backends.elasticsearch7 import (
Elasticsearch7Mapping,
Elasticsearch7SearchBackend,
Elasticsearch7SearchQueryCompiler,
Elasticsearch7SearchResults,
)
from .index import RootFilterField
@zerolab
zerolab / black-pyproject.toml
Created August 7, 2020 15:28
Example black config with excludes for the migrations directory
[tool.black]
line-length = 120
target-version = ['py38']
exclude = '''
(
/(
\.eggs # exclude a few common directories in the
| \.git # root of the project
| \.mypy_cache
| \.tox
@zerolab
zerolab / mkdocs-to-netlify-action.yml
Last active October 28, 2023 15:06
Deploy your mkdocs to NETLIFY
name: Publish docs to Netlify
on:
push:
branches:
- master
jobs:
build:
name: Deploy docs
runs-on: ubuntu-latest
@zerolab
zerolab / cloudflare-bulk-404s.js
Last active April 2, 2020 08:45
Cloudflare Worker - bulk regex 404s
/**
* Sets up routes and 404 any that match the 404 map
* @param {Request} request
*/
async function handleRequest(request) {
let requestURL = new URL(request.url)
let path = requestURL.pathname
if (should404(path)) {
return new Response('Sorry, not found', {
status: 404
@zerolab
zerolab / cf-holding-page.js
Created March 30, 2020 08:09
Cloudflare Worker holding page
addEventListener("fetch", event => {
event.respondWith(fetchAndReplace(event.request))
})
async function fetchAndReplace(request) {
let modifiedHeaders = new Headers()
modifiedHeaders.set('Content-Type', 'text/html')
modifiedHeaders.append('Pragma', 'no-cache')
@zerolab
zerolab / github_actions_deploy-mkdocs-to-gh-pages.yaml
Created March 11, 2020 14:46
Sample mkdocs deployment to GitHub Pages action
name: MkDocs to GitHub Pages
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
deploy:
@zerolab
zerolab / menu_children.html
Last active February 24, 2020 22:45
Wagtail "native" menus
# myapp/templates/tags/menu_children.html
{% load wagtailcore_tags %}
<ul class="primary-children">
{% for child in menuitems_children %}
<li{% if child.is_active %} class="active"{% endif %}><a href="{% pageurl child %}">{{ child.title }}</a></li>
{% endfor %}
</ul>