Rick Hurst Web Developer in Bristol, UK

Menu

Category: django

Brain dump January 2013

I haven’t posted to this blog much recently, so I thought i’d set myself a new routine of blogging at least at the end of each month to record some thoughts and links.

Firstly, as of Jan 1st i’ve been Freelance again – towards the end of last year while working full time at Potato, I got a bad case of freelancers itch, and felt that I wanted to make more time for working on other business ventures. When a three-month contract as a mobile web application developer at ISM games came up, I jumped at it. This time round i’m going to try my hardest to not end up juggling client and contract work, and to make sure that I free up time to pursue other things, either between contracts or by landing part-time contract work down the line. The important thing is that i’ve thoroughly learnt from the mistakes I made during my last stint as a freelancer!

Technology-wise i’ve been really enjoying cutting my teeth in proper “single-page” web app development using JavaScript, Backbone.js, Marionette and jQuery mobile. As an advocate of Progressive Enhancement, it’s a bit of a departure for me to be building JavaScript-only apps, but with the application logic mostly on the client side, to make it function without JavaScript really would mean building the application twice. The only compromise approach that i’m aware of is this approach used by airbnb, where JavaScript is used both server and client side, so HTML can be pre-rendered using the same templates on both sides, and application logic can also be shared (to an extent). It is also becoming increasingly clear that JavaScript-only apps needn’t be inaccessible, with screen readers apparently supporting javascript. I haven’t tried any of these, so i’m sure there’s plenty to learn in that area.

I’m also now “getting” the whole mobile-first approach for building web apps, in part due to having to go back to my old Nokia N95 for a while when I had to give back my company Android phone when I left my day job. No, I didn’t use any web apps on the Nokia – it was just too painful to even try to get logged into gmail, but not having access to a smartphone, and not being able to use mobile-only apps such Instagram, reminded me that web apps are primarily being used on smartphones and tablets, and this trend will only increase. Getting these mobile web apps working well, and then adding in additional stuff (only where needed) for people using them on desktop is the right approach, rather than the whole “squash and hide” approach used in responsive websites to scale down from desktop to mobile.

Apart from that, i’m all about Python and Django still – The back end of the web app i’m building uses Django rest framework and I have some personal/ business projects in the pipeline using those.

Lastly, i’ve really been enjoying blogging on my on the road blog, particularly writing about non-web related stuff, such as VW T25 campervans 🙂

A few notes on image uploading and configuration in Django

I recently added image uploading to Too Old To Skate, and not having set up a “normal” django site for a while, hit about every stumbling block possible, so here are a few notes. Please bear in mind there may be other, better ways to achieve this – i’d love to hear them.

Adding an Image field

This is achieved simply by adding an ImageField to your model, e.g.:-


photo = models.ImageField(upload_to='image_uploads', blank=True)


Separate static and media directories

The static folder is where your local site assets go e.g. CSS and Javascript. Locally these are served up from /static/ by the django dev server, and on a live site this should be set up as aliases to serve by your web server (in my case Apache).

The media folder is where user-uploaded files go, in subdirectories specified in ‘upload_to’ in your image field in the model. The root is configured in settings.py, but unlike the static folder you will need to do some configuration to get the local dev server serving files up from this directory (and its sub-directories). The location of the media root needs to be different to static root, which threw me slightly, though I guess it makes sense to keep your own static assets and uploaded media entirely separate.

To get the local dev server serving up files from /media and its subdirectories, add this to urls.py:-


# you'll need to add this if you aren't already importing settings
from django.conf import settings

if settings.DEBUG:
urlpatterns += patterns('',
(r'^media/(?P.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT}))


Permissions

Permissions need to be set on your media folder to allow uploaded files to be saved. This depends on your set-up, but for me adding write permissions for group allowed apache + wsgi + python (whichever one of those it appears as?) to save files and create directories.

PIL and libjpeg

As usual this caused me massive headaches to get running both locally and on my web server, and as usual I tried so many things i’m not 100% sure which steps actually made a difference in the end!

DBBUG lightning talks June 2012

Rick Hurst giving a talk on django snippets

On tuesday Potato Bristol hosted the Django Bristol and Bath User Group (DBBUG) lightning talks. It went really well and it was nice to have some technical content as well as the usual beer and chat. The turnout was great and so were the talks.

First up was Chris Hall – “Django from the outside in (and back again)” talking about his experience as a PHP/Drupal developer using Django on a project for the first time.

Second up was me, talking about my simple Django content management tool “Snippets” (shortly to be renamed as soon as I can think of something suitable, as googling around there are too many other similar projects under the same name). I was pleased by the response and interest in Snippets considering it is such a simple tool – mainly the result of an evenings experimentation. This gives me an incentive to develop it further, as it shows there is a demand for simple tools like these, especially if you just want to add a small amount of editable copy into a web app, but don’t want the overhead of a full CMS.

Ed Crewe then talked about “using eggs for managed release and deployment”.

Jamil Appa fron ZenoTech talked about “Using Django to front an application that makes
use of GPUs in the Cloud”.

Lastly Russ Ferriday from SponsorCraft, talked about the spray project.

Ed has kindly created a lanyrd page for the event.

Running Google App Engine SDK on OSX lion

OSX Lion comes with python 2.7 as default. Although App Engine will run on 2.7, it is safer to develop on the version of python that your live app engine instances are running on, which in my case is python 2.5 currently.

From a fresh install of Lion, I did the following:-

Installed xcode via app store

Installed Google App Engine SDK for Python, by installing google app engine launcher (This contains the SDK and a launcher app).

Installed mac ports

In a terminal:-


sudo port -v selfupdate
sudo port install python25
sudo port install py25-pil


This means I can start my django server on python 2.5 using:-


python2.5 manage.py runserver


However if you want to run dev_appserver.py it will still try to use python 2.7 (which, unless you’ve installed it into your default python, will be without PIL)

you can use macports to set the default version of python:-


sudo port select python python25


Finally, you might want to set Python Path to /opt/local/bin/python2.5 in your Google App Engine Launcher preferences

refs:-

http://stackoverflow.com/questions/4868185/how-to-install-pil-on-mac-osx-10-5-8-for-google-app-engine

http://stackoverflow.com/questions/6152765/macports-didnt-place-python-select-in-opt-local-bin

Update: after upgrading google app engine SDK to version 1.6, I was getting an import error “No module named _ctypes”. I have now upgraded to python2.6 and this fixed the issue.

Left the circus, going to work in the Potato field

Potato sign

I’ve mused a few times on this blog about the relative merits of full-time and freelance and what would convince me to go back into a full-time job, but it’s happened. I’m delighted to say that as of December 1st I am a full-time Django Developer, working for Potato, as part of the small (but growing) Bristol team. I’ve been freelancing full-time for Potato since October and have really been enjoying being part of a specialist team, working on interesting projects for interesting clients, using interesting technologies. I’ve learned so much in a short space of time working with talented and supportive colleagues, it’s been extremely enjoyable and satisfying. So when I was offered a permanent contract I was happy to accept – yesterday I went to London to meet my London-based colleagues and founders, and while I was there I signed a contract.

So other than a few existing freelance odds and ends that need handing over, I’m no longer a freelancer and not taking on any new clients or freelance work with immediate effect. My five years of freelance have been one hell of a ride, with lots of ups and downs, but i’m glad I did it, and proud that I made a success of it. Right now i’m looking forward to seeing what lies ahead in the world of potato!

Swoop Patagonia re-skin 3

screengrab of swoop reskin version 3

Last night Dan Fairs pushed the latest version of the django powered Swoop Patagonia site live. The site has several new content management features created by Dan with the help of Ben Mason allowing swoop staff to create and manage content in a more flexible manner and has been re-skinned (by yours truly) to use a new design created by the talented designer Ming Cheung. Another successful team effort!

plone conference 2010 day 2

Plone conf day 2

Some notes and thoughts from day of plone conference 2010. These are mostly in note form, but wanted to get these online anyway, while they are fresh in my mind.

fixing the ungoogleable by Elizabeth Leddy

What happens when something breaks, and a simple google search doesn’t offer any results?

First, warn people (so they don’t bother you while you fix it, and they don’t panic).

Work out how quickly can you access your backups? I think this is very important – personally for smaller sites i’m doing individual site backups as packages mainly to make it convenient to restore them in a local dev environment, but I know some people are relying on whole server backups on tape. This would be laborious to restore in an emergency.

Isolation by elimination -> network, hardware, software, data
map out your system!

Eliminate things by switching them off – write your code so that it can handle dependencies being switched off.

Set up a system so that you have an isolated instance (so you can look at logs of only your own activity, rather than mixed with everyone elses)

Create a dashboard (maintenance page)

Monitoring

Write Test case’s to diagnose faults

Start writing a “help” email, but don’t send it. This is apparently known as “rubber ducking”. I do this all the time, I often spot my mistake when I past in a traceback to an email message to send to someone!

“horizon of intervention” – At what point do you need external help?

Get to know people with specialisms and buy them a beer! Participate in the plone community (I really need to do more of that).

Create tickets and close them as you go

Document your processes.

The state of plone caching by Ricardo Newbery

cachefu – useful tool, but as far as “internet time” goes, this is a little long in the tooth now (started 2006). End of life – critical bugfixes only

plone.app.caching – will be in future plone releases, but available now

load testing with funkload (not accurate regarding CSS/ image discovery)

load testing with multi-mechanize

BrowserMob – not free

Building a custom app with plone with minimal development by Eric BREHAULT

This was extremely interesting – Eric is the project manage for Plomino – a plone add-on that provides application development toolkit for creating database applications within plone – i.e. the types of database applications that non-technical people might create on there own machines with Lotus Domino, Filemaker or Access. The data is still stored in the ZODB, but models and forms can views can be created through the web. Formulas are done in python.

I can see this being really useful – all too often I end up building custom applications based on complex access database or excel spreadsheets i’ve been provided, but if I can persuade clients to use Plomino, then not only will it help get that data in a format suiteble for building a web application, but data can be collaborated on across teams, rather then emailing around (and inevitably forking spreadsheets and databases). There were some nice examples of data visualisation – a great quote “almost useless, but very nice”” – you need these to impress your boss.

Themeing with XDV (Diazo) Laurence Rowe

I wrote some notes on this yesterday, connected to Nates Deliverance talk, so won’t go into this here, other than to quote Laurence: “we write XSLT, so you don’t have to”

collective.amberjack: chapter one. The interactive age. Massimo Azzolini

Amberjack is a Javascript library for creating a site tour/ tutorial. Collective amberjack wraps this up as an add-on for plone. Interactive tutrials can be created.

An example was given using the windmill testing framework (windmill in itself looks nice alternative to selenium).

The Art of Integrating Plone with Webservices with David Glick

Most of this was over my head, but one important note I made from this is about urlib (which I use in a django screen scraper app i’m developing) can have two possible error responses – URLError and HTTPError – two possible error responses.

external ecommerce and plone playing along with Sasha Vincic

There seems to be a bit of a theme going here – an acknowledgement that Plone works out best long term if you use it as a “black box” CMS, and don’t try to do everything with it. The upgrade path is easier if you don’t add on your own customisations – “clean plone”. The current plone ecommerce offerings are not as good as external systems, so it is better to integrate with an external system, which is also then kept clean to allow easier upgrades.

In the python world there are some Django Ecommerce stores LFS and Satchmo, but the store doesn’t have to be Python – other proven systems such as magento can also be integrated with Plone.

To integrate with plone you need to integrate search, linking, thumbnailing. Valentine achieved search compatibility by creating objects in plone via an RSS import – see valentine.rssobjects. A latecomer to the talk asked “but which plone ecommerce product would you use if you had to?”. Answer “we wouldn’t”.

collective.transcode.star (lightning talk)

manage online transcoding
http://plone.org/products/collective.transcode.star – looks interesting, and may bring plone back into the picture for a project i’m doing.

BlueDynamics bda.plone.finder

osx style finder widget for navigating/ organising content in plone – looks great!

Swoop Travel site launched – first real Django project and first output from Foundry

swoop travel homepage

A couple of months ago, freelancers Dan Fairs, Dan Hilton and myself discussed the idea of teaming up to offer services beyond those that we could offer individually. We came up with the identity Foundry, and decided that we wanted to work on interesting projects, mainly using the Django framework.

No sooner had we come up with the idea, I was approached to build a website for new adventure travel company swoop travel, and I decided it would be an ideal project to work on as a collaboration. It has worked out really well and “phase one” of the site went live yesterday, providing information and filtered searches about trekking in patagonia, specifically trekking in the Torres del Paine national park.

This was my first Django project, and although all the heavy lifting was done by the two Dan’s while I concentrated on the front end, it was a great introduction to working with the framework. One of the big wins was having the admin site in place very early on in the project allowing all the trip and operator information to be input as we built the site. It was also my first proper introduction to GIT source control, which worked out well for distributed collaborative working.

Looking forward to the next phase of this project and more collaborative projects!