Entries tagged with django
Using ipython's debugger as pdb replacement.
Do you know how to debug your python code? I usually do the following in my code to set something like a hardcoded breakpoint:
import pdb; pdb.set_trace();
This will bring up a pdb prompt when the code execution reaches this line.
But pdb is a bit limited since it doesn't support code completion,
syntax highlighting and so on.
So here is how you make your debug prompt more fancy by using ipython's debugger.
Websocket support for django!
You know what WebSockets are? It's a new web protocol for bidirectional connections between the browser and your application server. This is a huge win over AJAX and plain HTTP since you don't need to establish a new connection for every tiny message.
Like TCP socket but for the web.
It's an exciting new technology - so I started experimenting with WebSockets and with my favourite webframework Django. Here is what I came up with, bundled into a reusable app called django-websocket.
Enable setup.py test in your Django apps
Erich Holscher has posted a blog entry with the same title about a year ago. This helped me out quite a lot to get python setup.py test working with a reusable app.
Unfortunatelly the code in his blog post is not working anymore exactly like this. Django has changed its internal structure of its default test runner. So here is how you can get setup.py test working today.
Django admin with read-only permission
I work as a freelancer and do many django related projects. My clients care in most cases very much about django's admin site and want to have it customized in many different ways.
One client even has a django project that uses the admin site as only frontend. It's an intranet CRM system - but they need to assigned every employee change permissions because every user must be able to view every entry.
Since django doesn't support read permissions in the admin this was the only way to do it. Here is a quick-and-dirty fix without creating extra views for readonly pages, extra templates etc.
Test Driven Development - The Django Way
http://od-eon.com/blogs/tudor/test-driven-development-django-way/
Nice little write up about test driven development with django. Nothing special or excitingly new but I wanted to post it because I followed nearly the same principles in my last big project.
It worked very nice and I will do it the same way with the next project.
Integrate your python test runner into vim
I've lately browsed the dotfiles repository
of Gary Bernhardt and found a wonderful gem in
his .vimrc. He has implemented some clever functions that run your testsuite
and shows you a pretty, colorful bar below your statusline to indicate if all
tests have passed or if some of them have failed.
If your tests are passing, it shows you a bright green bar to visualize that everything went well. If some test are failing your quickfix list is populated with all failing assertions and your cursor jumps to the first one.
I adapted his implementation and changed some points to make it fit for my work with django. The code can find out to which app the file you are editing belongs to and only runs tests for this particular application.
Testing your first django app
http://dougalmatthews.com/articles/2010/jan/20/testing-your-first-django-app/
Dougal Matthews wrote, as he said, the unofficial fifth part of the django tutorial. It'a about testing and seem to be a very clear and easy to start with. So … if you don't test your django code yet: Start doing it!
After you get a bit routine in writing tests you will notice that it's not too time consuming writing them but will save you a lot of stressfull hours afterwards.
Benchmark of django deployment techniques
http://basicverbs.com/benchmark-of-django-deployment-techniques/
Vasil Vangelovski benchmarked a few combinations for deploying django on a webserver. Among others he tested apache only (serving static files and django via mod_wsgi), nginx (for static files) + mod_wsgi, nginx + fcgi and nginx with cherrypy as wsgi server.
nginx + cherrypy seem to use less memory than the other setups, but all in all any combination is usable.
Introducing django-publicmanager
I use nearly in all projects something like an is_public and a pub_date field
in my models. But using this introduces many possibilities to forget to check
this values in all places you use the model which would open up everything for information leaks.
django-publicmanager tries to fix this issue with two custom managers.
Modelvalidation will be in django 1.2
http://code.djangoproject.com/changeset/12098
Form- and modelvalidation landed in trunk and will be in django 1.2. This is really cool news. Especially the form validators look quite useful and will make standard fields even more flexible.
Congratulations to everyone who contributed to this feature.
Released django-feedburner
I stumbled upon a stackoverflow question that asks about feedburner integration into a django app. django-feedburner is my attempt to bundle this into a reusable app.
Hello world!
I already thought about creating my own blog about two years ago. But I always wanted too much and never finished any approach I started with. So I tried something different this time - I have mainly used ready to use django components and finished this site in about three days.
Read what I want to publish on this blog in the next few months.
Subscribe to this tag's feed.
about
Gregor Müllegger's Weblog on django, python, vim and anything else.
Feel free to contact me if you have question about my life, my work or my projects.
