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:
When using vagrant, vscode won't be able to map to the vm, well not yet anyway. A way around this is to checkout a branch called pipenv, run pipenv --python 3
to create a virtual environment. Then run pipenv install -r requirements.txt
to install everything in the project.
After doing this, in vscode ctrl+p
then search for >python: select interpreter
. Select the virtual env python, it will look something like this: /home/yourname/.local/share/virtualenvs/project-foo-JbRjzqlX/bin/python
.
Just don't commit the pipenv stuff.
Place the following in .git/hooks/pre-commit
#!/bin/sh | |
#http://www.thegeekstuff.com/2011/01/advanced-regular-expressions-in-grep-command-with-10-examples-%E2%80%93-part-ii/ | |
# GENERAL | |
# print lines begining with range of letters | |
grep ^[A-D] table.txt | |
# REGEX |
sudo apt-get update | |
sudo apt-get install python3-pip python3-dev libpq-dev postgresql postgresql-contrib nginx | |
sudo -u postgres psql | |
- paste this code in postgres console: | |
CREATE DATABASE django_project; | |
CREATE USER username WITH PASSWORD 'pass1234'; | |
ALTER ROLE username SET client_encoding TO 'utf8'; | |
ALTER ROLE username SET default_transaction_isolation TO 'read committed'; |
import sys | |
import traceback | |
from django.utils import timezone | |
from django.db import transaction | |
from django.core.management.base import BaseCommand, CommandError | |
# django will strip new lines split helptext in 80 char lines | |
HELP_TEXT = """ |
from io import BytesIO | |
import requests | |
from django.core.files.images import ImageFile | |
from wagtail.wagtailimages.models import Image | |
# event is a model object, substitute your model | |
# filename and title are up to you | |
# in my model, event.event_image is a ForeignKey to wagtailimages.Image | |
response = requests.get(url) |
"""Crop a polygonal selection from an image.""" | |
import numpy as np | |
from PIL import Image | |
from shapely.geometry import Point | |
from shapely.geometry import Polygon | |
im = Image.open('bird.jpg').convert('RGBA') | |
pixels = np.array(im) | |
im_copy = np.array(im) |
# Ask for the user password | |
# Script only works if sudo caches the password for a few minutes | |
sudo true | |
# Install kernel extra's to enable docker aufs support | |
# sudo apt-get -y install linux-image-extra-$(uname -r) | |
# Add Docker PPA and install latest version | |
# sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9 | |
# sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list" |