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 | |
| /** | |
| * @file | |
| * An example of how to pass your custom variable to the first item in a multi-value | |
| * entityreference field. | |
| */ | |
| /** | |
| * Implements hook_preprocess_field(). |
$ brew install pv-OR-
$ apt-get install pv| from django.core.exceptions import ValidationError | |
| from django.forms.utils import ErrorList | |
| from wagtail.wagtailcore import blocks | |
| class MyLinkBlock(blocks.StructBlock): | |
| """ | |
| Example validating StructBlock. | |
| """ |
| [core] | |
| excludesfile = ~/.gitignore | |
| autocrlf = input | |
| editor = vim | |
| quotepath = false | |
| safecrlf = false | |
| [color] | |
| ui = auto | |
| status = auto | |
| branch = auto |
| <?php | |
| function _load_header_image($variables) { | |
| if ($node = $variables['node']) { | |
| // Load main_image | |
| $file = $node->field_main_image->entity; | |
| if ($file) { | |
| $variables = array( | |
| 'responsive_image_style_id' => 'header_image', | |
| 'uri' => $file->getFileUri(), |
| Given /^(?:|I )am on "(?P<page>[^"]+)"$/ | |
| Given /^(?:|I )am on (?:|the )homepage$/ | |
| Given :type content: | |
| Given :vocabulary terms: | |
| Given I am an anonymous user | |
| Given I am at :path | |
| Given I am logged in as :name | |
| Given I am logged in as a user with the :permissions permission(s) | |
| Given I am logged in as a user with the :role role(s) | |
| Given I am logged in as a user with the :role role(s) and I have the following fields: |
Magic words:
psql -U postgresSome interesting flags (to see all, use -h or --help depending on your psql version):
-E: will describe the underlaying queries of the \ commands (cool for learning!)-l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)| <?php | |
| /** | |
| * This is the content type which should have the EntityReference field in the new site. | |
| */ | |
| class MainContentTypeMigration extends DrupalNode6Migration { | |
| public function __construct(array $arguments) { | |
| parent::__contstruct($arguments); | |
| $this->addFieldMapping('my_new_field', 'my_old_field'); |
| """ | |
| Attempting to set session variables directly from TestCases can | |
| be error prone. Use this super-class to enable session modifications | |
| from within your tests. | |
| Usage | |
| ----- | |
| class MyTest(SessionEnabledTestCase): |