Skip to content

Instantly share code, notes, and snippets.

@dopry
dopry / login.html
Created September 12, 2024 18:49
Wagtail OIDC example
{% extends "wagtailadmin/login.html" %}
{% block branding_login %}CMS{% endblock %}
{% block login_form %}
{% if user.is_authenticated %}
<p>Current user: {{ user.email }}</p>
<form action="{% url 'oidc_logout' %}" method="post">
{% csrf_token %}
<input type="submit" value="logout" />
</form>
{% else %}
import json
from graphene_django.utils.testing import GraphQLTestCase
class GraphQLIntrospectionTestCase(GraphQLTestCase):
graphql = """
query IntrospectionQuery {
__schema {
queryType { name }
class OauthEndSessionView(views.APIView):
"""Impements an endpoint to end the session
https://openid.net/specs/openid-connect-rpinitiated-1_0.html
* Works on both GET and POST
OpenID Providers MUST support the use of the HTTP GET and POST methods defined in RFC 7231 [RFC7231] at the Logout
Endpoint. RPs MAY use the HTTP GET or POST methods to send the logout request to the OP. If using the HTTP GET
method, the request parameters are serialized using URI Query String Serialization. If using the HTTP POST method,
the request parameters are serialized using Form Serialization.
* Runs the normal django logout
* The spec doesn't state what http response codes to use, so we'll use 204 no content
@dopry
dopry / admin-tag-blocks-widget-adapter.js
Created November 11, 2022 04:32
Wagtail Tags Block
// static/js/admin/admin-tag-blocks-widget-adapter.js
// inspired by:
// see: https://stackoverflow.com/questions/70359932/wagtail-how-to-get-tags-to-work-with-telepath-tags-in-streamfield
// copied and adapted from
// see: https://github.com/wagtail/wagtail/blob/v4.0.1/client/src/entrypoints/admin/telepath/widgets.js
class BoundTagItWidget {
constructor(element, name, idForLabel, initialState, parentCapabilities) {
var selector = ':input[name="' + name + '"]';
this.input = element.find(selector).addBack(selector); // find, including element itself
@dopry
dopry / jest-mochawesome.js
Last active April 13, 2023 11:25
jest-mochawesome-reporter
// based on https://gist.github.com/Prophet32j/05a2ceda3743b9fd93e98e56a9227309
const fs = require('fs');
const uuid = require('uuid-v4');
const buildMargeInput = (testResults) => {
let elapsed = buildElapsedTime(testResults.testResults);
let testSuites = testResults.testResults.map(createSuite);
var input = {};
input.stats = {
suites: testResults.numTotalTestSuites,
<!DOCTYPE html>
<html>
<head>
<script data-require="[email protected]" data-semver="3.1.1" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/3.15/themes/css/cartodb.css" />
<script src="http://libs.cartocdn.com/cartodb.js/v3/3.15/cartodb.js"></script>
</head>
<body>
@dopry
dopry / Vagrantfile
Last active August 29, 2015 14:09
Example for Ansible copy module error,
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/trusty64"
# forward gulp hosted client from vagrant to host.
config.vm.network "forwarded_port", guest: 8080, host: 8080
@dopry
dopry / hosts.py
Last active August 29, 2015 14:05
Ansible static inventory proxy for Vagrant, using Ansible's INI parser.
#!/usr/bin/env python
from ansible.inventory.ini import InventoryParser
import json
import os
file_path = os.path.dirname(os.path.realpath(__file__))
static_file = os.path.join(file_path, "hosts")