Lightning talks at the Dutch Django meeting (part one)

Tags: django, pun

Lightning talks at the April 2012 Dutch Django meeting

Code with style: PEP8 and Pylint - Johan Otten

Readability counts and PEP8 gives you a consistent code style. And it is BDFL-approved.

There’s a tool for it: http://pypi.python.org/pypi/pep8 .

Pylint gives you static program analysis. There’s a lot it checks.

Also look at PEP 257 about docstrings. Read it once or twice, just to get it a bit in the back of your head. It is not that important.

Note: there’s also a django lint.

Very useful: there’s a Jenkins “violations” plugin. This helps you see the number of pep8/pylint violations. Also there’s django-jenkins that helps a lot in setting up Jenkins for Django projects.

(Personal note: I really agree with PEP8, I even helped getting pep8 on pypi (it was a standalone .py file earlier). And I personally prefer pyflakes to pylint. Way easier to run than pylint and you get a lot of the benefits. And if you want to use pep8 and pyflakes in emacs, see http://reinout.vanrees.org/weblog/2010/05/11/pep8-pyflakes-emacs.html ).

Building apps using high-level models - Jeroen Vloothuis

Jeroen worked on a project with a questionaire with lots of pages and questions. Boring code to write, adding all those questions as Django model fields. Lots of model code, lots of view code.

The solution: let’s genereate one data structure to rule everything for me. So he defined some Questionaire and Question classes that he could define questionaires with in a simple syntax (one line per question).

He would then use that information to generate the Django models! The same for generationg the forms.

The good thing: it’s really DRY (Don’t Repeat Yourself) and it is nicely declarative. The bad thing is when you need to do debugging (the code is generated, so you cannot stick a pdb in there somewhere). And you need quite some Django skill to pull it off.

Jeroen has a blog post about this, you can see code examples there.

 
vanrees.org logo

Reinout van Rees

My name is Reinout van Rees and I program in Python, I live in the Netherlands, I cycle recumbent bikes and I have a model railway.

Weblog feeds

Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):