Skip to content

Instantly share code, notes, and snippets.

View marteinn's full-sized avatar
✖️
🥕

Martin Sandström marteinn

✖️
🥕
View GitHub Profile
@marteinn
marteinn / _document.js
Created September 26, 2020 06:27
Next.js: How to capture and use page props in next/document
import Document, { Html, Head, Main, NextScript } from 'next/document';
class CustomDocument extends Document {
static async getInitialProps(ctx) {
let pageProps = null;
const originalRenderPage = ctx.renderPage;
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: (App) => (props) => {
@marteinn
marteinn / info.md
Last active September 16, 2020 19:07
Integrating a DAM solution in Wagtail

Integrating a DAM solution in Wagtail

Key arguments for using a DAM

First, what is the primary purpose with using a DAM (Digital Asset Management) solution? There are several, but these are the features:

  • Having a centralized digital asset management (keep your pictures in one place)
  • Keeping your assets in sync and making sure licenses are up to date (when does image X expire, are author information correct?)
  • Keep track on where your digital assets usage (my bird image are used on site X, Y and Z)

So, how would we go about integrating a DAM in Wagtail? These are the steps me (me and others) took in a real-world project.

@marteinn
marteinn / admin.py
Created August 11, 2020 09:39
How to set manual permissions in Wagtail ModelAdmin, by overriding the PermissionHelper
from wagtail.contrib.modeladmin.helpers.permission import PermissionHelper
from wagtail.contrib.modeladmin.options import (
ModelAdmin,
modeladmin_register
)
class MyModelPermissionHelper(PermissionHelper):
def user_can_create(self, _user):
return False
@marteinn
marteinn / all_user_report.html
Last active August 10, 2020 13:46
How to generate a report with all users in Wagtail
{% extends 'wagtailadmin/reports/base_report.html' %}
{% load i18n wagtailadmin_tags %}
{% block results %}
{% if object_list %}
<table class="listing">
<thead>
<tr>
<th class="title">
{% trans 'Name' %}
@marteinn
marteinn / edit_handlers.py
Last active August 2, 2022 20:17
How to create a native color panel for Wagtail (WIP)
from django.forms import widgets
from wagtail.admin.edit_handlers import FieldPanel
class ColorInputWidget(widgets.Input):
input_type = 'color'
class ColorPanel(FieldPanel):
def widget_overrides(self):

How to disable SSL verification for django-revproxy

You do this by supplying your own pool manager that disables any cert verification.

from revproxy.views import ProxyView
from urllib3 import PoolManager

class NoSSLVerifyProxyView(ProxyView):
 def __init__(self, *args, **kwargs):
@marteinn
marteinn / apikey_authentication.py
Created March 8, 2020 09:53
This is a Django Rest Framework authenticator to tastypie ApiKey
from django.utils.translation import ugettext_lazy as _
from rest_framework import exceptions
from rest_framework.authentication import TokenAuthentication
from tastypie.models import ApiKey
class ApiKeyAuthentication(TokenAuthentication):
model = ApiKey
keyword = 'ApiKey'
@marteinn
marteinn / bottleserver.hy
Last active July 13, 2019 08:56
An example on how to use [hy](https://github.com/hylang/hy) with bottle
#! /usr/bin/env hy
(import [bottle [route run template]])
(with-decorator (route "/hello/<name>")
(defn index [name]
(template "<b>Hello {{name}}</b>!" :name name)))
(run :host "localhost" :port 8080)
@marteinn
marteinn / example-how-to-return-utf8-based-cvs-from-django.md
Created June 6, 2019 06:23
How to return csv in utf-8 format from a Django view

How to return csv in utf-8 format from a Django view

This is a example on how to return a utf-8 encoded csv form a django view.

import csv
import codecs

from django.contrib.auth import get_user_model
from django.views import View
@marteinn
marteinn / code-retreat-2019.md
Last active April 22, 2019 08:51
Notes from my code retreat 2019

Code retreat 2019

Projects

  • wagtail-alt-generator
    • Added translation support with the google translate api
    • Battled with a bug that made tags not be generated when image is uploaded through a page, still unsolved and connected when tags beeing overriden by form handling in wagtail
    • Fixed a bug related to the azure implementation (endpoints had changed and regions was introduced)
    • Improved the test suite with mock stubs for providers
    • Added CI integration
  • Rewrote the docs