This short recipe demonstrates how to create Wagtail pages programmatically. It may also be useful for testing Wagtail development against a reasonable volume of page data (about 35,000 film plots, from English Wikipedia).
In a virtualenv:
<?php | |
use Behat\Mink\Driver\GoutteDriver; | |
use Behat\Mink\Exception\ElementNotFoundException; | |
use Behat\Mink\Exception\ExpectationException; | |
use Drupal\DrupalExtension\Context\RawDrupalContext; | |
use Behat\Behat\Context\SnippetAcceptingContext; | |
/** | |
* Defines application features from the specific context. |
All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.
Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.
elem.offsetLeft
, elem.offsetTop
, elem.offsetWidth
, elem.offsetHeight
, elem.offsetParent
from django.utils.safestring import mark_safe | |
from markdown import markdown | |
from pygments import highlight | |
from pygments.formatters import get_formatter_by_name | |
from pygments.lexers import get_lexer_by_name | |
from wagtail.wagtailcore import blocks | |
class CodeBlock(blocks.StructBlock): |
# Notes: | |
# Python 3 assumed, but shouldn't be hard to backport to Python 2 | |
# Cobbled together from two slightly different implementations, sorry for any inconsistencies. | |
# This creates two models, NavigationMenu, and NavigationMenuItem. A site can have many NavigationMenus, which are referenced from | |
# the template by location. E.g., 'footer', 'left_nav'. You can also create single-item lists for special purpose links/buttons, | |
# such a privacy_policy or homepage_cta. This helps to reduce hard coding in templates. | |
# NavigationMenuItem mixes in some different link types (Page, Document, URL) and presents them in a consistent way. It provides | |
# the ability to override the title of the referenced object. |
Google Chrome Developers says:
The new WOFF 2.0 Web Font compression format offers a 30% average gain over WOFF 1.0 (up to 50%+ in some cases). WOFF 2.0 is available since Chrome 36 and Opera 23.
Some examples of file size differences: WOFF vs. WOFF2
#Good practices for project management in Django
#Setting up the environment
Each Django project should be encapsulated in its own virtual environment, allowing us to manage the requirements and dependencies independently.
If you don't have Virtualenv installed, please visit this page and download the virtualenv package. For a simple installation:
This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.
The script is here:
#!/bin/bash
convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"