Fixing Firefox form caching in Django

I noticed recently that Firefox seems to cache form fields very aggressively, particularly tickbox values. This can result in the cached values being displayed instead of the updated content from the server. It usually happens when the submitted form returns to the same URL – e.g. an Update Profile page – giving the impression that changes haven’t been saved.  Bad Firefox!  A re-direct after POST doesn’t seem to resolve the issue.

The only way to force Firefox to display the updated content is to set the ‘no-cache’ HTTP header. Fortunately Django has a cache framework that can be used out-of-the-box to do this individually for each view. The key piece is the @cache_control decorator.

The solution very simple, just import the decorator and add it to the view that handles the form processing. The full docs are on the Django site. I’ve included a short example below.


from django.views.decorators.cache import cache_control

@cache_control(no_cache=True)
def my_form_view(request):
...rest of view

The result can be confirmed by viewing the http response headers, the Firefox Web Developer extension is a handy tool for this. If everything is working you’ll see:

Cache-Control: no-cache

Job Done.  Thanks Django!

Geany: The Linux text editor for ex-Windows users

Ok, this is going to be controversial . . .

Today I found Geany . . . and my search for the perfect Linux text-editor finally ended. If you’re already a VIM or Emacs ninja then you may want to stop reading now, if however you come from a Windows background (like me) or you like the niceties a true GUI tool can offer, then Geany may be everything you’ve been looking for.

I use Python, so whitespace management is *very* important to me, for this I need some key functionality:

  • Whitespace display
  • Correct tab/space handling

On Windows my editor of choice was Notepad++, it did all of above superbly. When I moved to Linux most of my development-related tasks became much easier, however I sorely missed some of the key editing  features that I had become used to (as a side note – I also miss the GUI repo browsing offered by the TortoiseHG).

Why I love Geany

It’s fast, lightweight and has some killer features . . .

1. Whitespace

Geany shows whitespace clearly.  It handles tabs and spaces properly without interchanging the two. These features make all Python indentation issues just drift away.
Geany Whitespace

2. Folding

It’s great to be able to collapse all the classes and functions that you’re not working on to save some screen real-estate (not to mention the scrolling up/down).
Geany Folding

3. Class/Function browser

This sealed the deal. The browser on the left pane lists all the classes, functions, variables and imports found in the open file. This makes navigation very quick, and is a boon for working your way around an unfamiliar piece of code.
Geany Symbols

3. Other great stuff

And there’s more: Built-in file browser, shell, scratchpad, and support for 3rd-party plugins are just some of the other great features that Geany has to offer. As a bonus, Geany can also run on Windows too.

So Geany it is, and I’m finally happy. Here are some of the other editors I tried (and why they didn’t quite fit the bill for me).

Gedit
The default editor in Ubuntu is actually a really nice little tool and does 99% of what I need, but something I cannot live without is whitespace display. None of the available Gedit plugins seem to offer this..

VIM
Immensely powerful, but has a learning curve that right now I’m just to busy for.

Emacs
See VIM.

Wing IDE
I had high hope for Wing, but it let me down massively when it started to mix up tabs and spaces within the same indented sections.

Eclipse
I really don’t want to wait 10mins for Eclipse to load every day. It’s far too big for my needs.

Crowdsourcing Prague for EuroDjangoCon 2009


Attending EuroDjangoCon

I’m off to Prague tomorrow ahead of next week’s EuroDjangoCon.

In a great demonstration of crowdsourcing, jacobian has created a Google Map for Prague which is now being populated by conference goers.


View EuroDjangoCon in a larger map

So far it includes the conference hotel, tram stops and a bunch of bars, restaurants and sites. Who needs a guidebook!

EuroDjangoCon has been organized by Robert Lofthouse and takes place in Prague on 4th-6th of May 2009 (with development sprints on the 7th and 8th).

I’m looking forward to meeting up with fellow Django folks so please stop me and say Hi if you see me wandering around.