I’ve been working on something(s) recently involving fetching data from an API and using it in a Wagtail site. I came to the point when I was struggling to test the API request without actually requesting the live API. Why? Well, sites can go down, take to long to respond or generally misbehave and really, my API request should be able to handle this gracefully. More specifically, it should expect it.
I actually love testing. So much so, I would be happy just writing tests all day but I find it hard just to figure out how to test specific…
I was trying to figure out a way to call a JavaScript function using values from the request object. It turns out, Django has a built-in template filter for this…
As an example, I’m going to add some data by overriding the get_context()
method on a basic HomePage model (line 19, my_info):
In the home_page.html template, we would normally use this like {{ my_info }}
or loop over it depending on what we needed. But if we use the json_script
filter, we can safely output this value as JSON…
{{ my_info|json_script:"my-info" }}
Our data is now ready for use…
Let’s look at a basic example of migrating content from a Drupal site to a Wagtail site. This post explains how to prepare your Drupal data for exporting and how to write a content importer for Wagtail so moving won’t be the most stressful time of your life.
A Drupal migration is scary and usually, the type of task that’s reserved for Senior Developers. Just tinkering with the Drupal migrate module was enough to put me off learning more about it. Migrating content from one system to another presents a lot of problems to solve and pre-written solutions won’t catch…
If you’ve ever found yourself working in the Drupal front-end, you will have at some point searched for help on ‘Overriding templates’. It’s a legacy pattern that Drupal just can’t shake. With Drupal 8 we saw some big front-end improvements. Twig was inherited as a templating engine which was supposed to mean working with a more decoupled approach between the back end and front end… but, it’s not that decoupled…
There is an old infamous post about Drupal ‘divitis’, illustrating just how wild Drupal’s core markup can get. I’m amazed at how this old post on drupal was ended by…
Since writing my last post 6 things I learned whilst moving a Drupal 8 site to my first Wagtail site, I’ve got my feet wet, well soaked actually, with Wagtail and now is a good time to pause and expand on why I thought switching to Wagtail after 5 years as a Drupal developer was a good idea.
As a developer, I’m always trying out new frameworks and technology but I usually have a solid foundation to fall back on. For a long time, Drupal was my nucleus of development and I’ve been working with it for over 5 years…
Wagtail is an open source CMS written in Python and built on the Django framework. Built by developers for developers, it offers a fast attractive interface for editors where content can be created and structured intuitively.
Chances are you’ve heard of Drupal and Wordpress. In the past I’ve also used CodeIgnighter and Laravel, the common thread here being PHP. So I have to say I was somewhat intimidated at first when checking out Wagtail mainly because of Python. …
Vagrant has become a standard tool to use for web development, but one thing that’s annoyed me is having to navigate to directories on the command line just to run vagrant up or vagrant ssh.
Running the global-status command will show you the status of all your vms, but it also gives you an ‘id’
$: vagrant global-status
From anywhere in the command line you can run specific vagrant commands using the machines ID:
$: vagrant up ae0db97
Nice little timesaver!
What do words look like as colours? What would Shakespear’s sonnets look like as colours? This mini project renders text as colours using Python and saves them in a grid as an image.
It started as a bit of fun late one night on codepen, toying with ways to make images with code. In a really simple way, how can a colour represent a word? Easy… just convert a word to a colour code right?
As it turns out, it wasn’t so easy. Like most developers, I started looking for a JS library that already did this, wishful thinking as…
Back in the day, drupal 7 had quite a useful way of stashing (occasionally arbitrary) values in the database. Remember…
variable_set($name, $value)
variable_get($name, $value)
In Drupal 8, these functions have been replaced with ‘the new configuration system API/storage’. You can read about that here. But, there is more…
There is a nice way to set and get user data in drupal 8. We can make use of the users_data table. Take a look, it’s more than likely empty. Here is the set method:
$userData = \Drupal::service('user.data');
$userData->set('my_module', $uid, 'a_key', 'Here is a value');
Why? Well, I was sick of always having to install or go to adminer or use another program to view and edit databases. I didn’t know you can actually do this right from within Intellij IDEA.
Hit shift three times and search for database, or click the ‘database’ tab which is located on the right side as a vertical button:
In the popout window, click the green cross and add your database source. You will now need to add you database details in the modal: