Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nimasmi
nimasmi / README.md
Last active October 7, 2020 10:29
Wagtail internationalisation dev builds

This is just a place to host builds of Wagtail on the in-development i18n-combined branch, and wagtail-localize on the beta branch.

Wagtail

This largely follows the CI process nightly-build at https://github.com/wagtail/wagtail/blob/7eeb44ad0408cf72060f19db577de2159859cd74/.circleci/config.yml#L49

  1. Check out the version of Wagtail with the corresponding features needed, currently https://github.com/kaedroho/wagtail/tree/i18n-combined
    git clone git@github.com:kaedroho/wagtail.git wagtail

cd wagtail

@nimasmi
nimasmi / get_start_date_choices.py
Created October 17, 2017 10:02
List today, start of next month, start of 2 months hence, etc. up to start of 12 months hence
from django.utils.timezone import now
from dateutil.rrule import MONTHLY, rrule
def get_start_date_choices():
today = now().date()
choices = [(today, "Now")]
for start_date in rrule(MONTHLY, count=12, dtstart=today,
bymonthday=1):
@nimasmi
nimasmi / pecha_kucha_clue_almanac.markdown
Last active March 31, 2017 08:12
PECHA KUCHA cryptic clue almanac

PECHA KUCHA cryptic clue almanac

Presentation cupcake? - hah! Blast it.

Helen

*[CUPCAKEHAH]

Presentation is hacky hack, a little French tea consumed.

Keybase proof

I hereby claim:

  • I am nimasmi on github.
  • I am nimasmi (https://keybase.io/nimasmi) on keybase.
  • I have a public key ASCIYTT_Z-NcSxohQ7JrWt1c54bo6vKaiNIydDcY8CvQxQo

To claim this, I am signing this object:

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import json
from django.core.serializers.json import DjangoJSONEncoder
from django.db import migrations, models
from wagtail.wagtailcore.rich_text import RichText
@nimasmi
nimasmi / colours.md
Last active October 17, 2017 10:04
Notes, archived from some very old posts

There are only 11 colours

I've been aware for a couple of years now that there are only really 11 colours. In my experience, this feels like a boy/girl distinction.

Let me explain: most colours that girls talk about are in fact just different names for the same thing (Death Cab for Cutie reference intended). For example: 'teal'. What's that if it's not a shade of green?

I will reveal what these colours are shortly, but before that, let me tell you why we have to stop somewhere—why we shouldn't go the whole hog and pare it down to just three, red, green and blue. Although you can describe most colours humans can see with just an RGB value, everyday experience necessitates a wider vocabulary, particularly in the surprisingly different subjective appearance of yellow from its red and green constituent primaries.

Starting with the rainbow then, we see that there is

@nimasmi
nimasmi / provision.sh
Last active December 10, 2015 10:59
Vagrant provision—Node installation snippet
#!/bin/bash
NODE_VERSION=v4.2.3 # amend this line only, to change Node version
# Node.js
if ! command -v npm; then
INSTALL_NODE=1
elif [ $NODE_VERSION != `node --version` ]; then
rm -rf /opt/node-`node --version`-linux-x64/
rm /usr/local/bin/node
@nimasmi
nimasmi / import_export_views.py
Last active November 4, 2022 16:28
Django Import Export admin functionality in a Class Based View
from django.views.generic import FormView
from django.utils.translation import ugettext_lazy as _
from django.contrib import messages
from import_export.formats import base_formats
from import_export.forms import ImportForm, ConfirmImportForm
from import_export.resources import modelresource_factory
from django.http import HttpResponseRedirect
from import_export.tmp_storages import TempFolderStorage
try:
class TranslatedField(object):
def __init__(self, fieldname):
self.fieldname = fieldname
def get_translated_field(self, instance, language):
return getattr(instance, "_".join([self.fieldname, language]))
def __get__(self, instance, owner):
language = get_language()
translation = self.get_translated_field(instance, language)
from wagtail.wagtailcore.models import get_page_models
from wagtail.wagtailcore.utils import resolve_model_string
class SinglePageInstanceMixin(object):
@classmethod
def clean_parent_page_types(cls):
"""
Rewrite wagtailcore.models.Page.clean_parent_page_models to ensure that