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
# 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>
@zerolab
zerolab / _README.md
Created October 8, 2019 15:52
fetch_git_sha for Sentry
@zerolab
zerolab / responsiveimage_tags.py
Created June 20, 2019 09:55
Wagtail responsive image tag
from django import template
from wagtail.images.models import SourceImageIOError
from wagtail.images.shortcuts import get_rendition_or_not_found
from wagtail.images.templatetags.wagtailimages_tags import ImageNode
register = template.Library()
@register.tag(name="responsiveimage")