Writing thread-safe django - get_or_create

By : Javed Khan

In this blog post, we'll discuss thread-safety, why it's important and how to write thread-safe django code, especially for bulk operations like management commands. We'll take a simple example - get or create.

Thread-safety:

Thread-safety means that our code can be run in multiple threads and behave as expected. The reason that code can be unsafe with regard to threads is because we'll be manipulating shared memory (e.g. database) from the threads and there's a chance of a race-condition which will produce unexpected results.

To avoid this, we have the option of using read-write locks ...

more info..
Topics : django python threads

Accept bitcoins using python

By : Javed Khan

In this blog post we'll talk about bitcoins and look at an overview of how to accept them from your python app.

Bitcoin:

Bitcoin is crypto-currency whose protocol allows fast, anonymous and secure digital transactions.

To know more about bitcoin and to install it, go to the "Developer Guide" guide.

Getting started:

To get started, install bitcoin (assuming Ubuntu):

$ sudo apt-get install bitcoind

Now edit ~/.bitcoin/bitcoin.conf and add:

testnet=1

This will allow us to run bitcoin in test mode.

Now start the bitcoind daemon using:

$ bitcoind -daemon

To check that it's working, do:

$ bitcoind ...

more info..
Topics : python bitcoin

Self-testing fabfile using docker

By : Javed Khan

In my last blog post, I discussed deploying django on docker. This is a blog post on a related note and we'll be looking at using docker to test a fabfile. Note that docker is still under development and not ready for use in production.

Fabfile and testing:

Fabric is a great tool for automating deployments. Unfortunately, the docs on testing fabfiles are a bit scarce.

With good tests, you can be sure that your fabfile works out of the box and be prepared for server migrations or upgrades.

One apporach to testing complex fabfiles is using vagrant or ...

more info..
Topics : deploy docker fabfile

Deploying django using docker

By : Javed Khan

In this blog post we'll take a look at Docker and discuss ways to deploy django using docker.

About Docker:

Docker is a tool that helps you manage lxc containers and images. You can create an image, launch container from the existing image, attach to a running container, and generally play around with the containers.

The most important benefit of using docker and containers in general is that you have a clean, hygeinic and portable runtime enivorment for your app. This means you don't have to worry about missing dependecies, packages and other pain points during subsequent deployments ...

more info..
Topics : django deploy docker

Not exactly, not exactly tim the enchanter

By : Javed Khan

I've been putting off writing about my experience with django form wizard for some time now. I came across this blog post by Kenneth Love which finally compelled me to write this down.

About Django Form Wizard:

Form Wizard can be handy when you have a huge form, and you want to make it less intimidating to the user by splitting it into multiple steps.

If you have glued multiple forms together with sessions or whatnot and it turned out to be a mess, you now what I'm talking about :)

Think surveys, checkouts, lengthy registrations etc.

The class ...

more info..
Topics : django forms wizard
Javed
Comments
Reactions

Django: csrf error on non-existent urls

By : Javed Khan

While testing out a API from another django site, I came across a seemingly common error.

403 Forbidden

CSRF verification failed. Request aborted.

Help

Reason given for failure:

    No CSRF or session cookie.

Posting the data to the api endpoint returned 403 Forbidden with the standard csrf failure error page. I cross checked that the view was csrf_exempted and that CsrfViewMiddleware was not enabled. The view had some other unrelated decorators which I guessed could be the cause of the problem. According to this bug, not all decorators play nice with the csrf_exempt decorator. Even with that fixed, there was ...

more info..
Javed
Comments
Reactions

Real time applications with Django, XMPP and StropheJS

By : Javed Khan

TL;DR:

Introduction:

PubSub is a XMPP extension which allows publishing and subscribing to events. This is useful when you instantly want to notify many clients about something interesting happening on your server.

Quoting the authors of PubSub specs:

The protocol enables XMPP entities to create nodes (topics) at a
pubsub service and publish information at those nodes; an event
notification (with or without payload) is then broadcasted to all ...

more info..
Javed
Comments
Reactions

Link Roundup for week ending 19/11/2010

By : Javed Khan

more info..
Topics : linkroundup
Javed
Comments
Reactions

Seven reasons why you should switch to Vim

By : Javed Khan

So you want a better IDE for developing django, huh? Why not give good old vim a try?

Use pathogen to maintain your vim plugins (and sanity). Using this, you can clone the repositories listed here to .vim/bundle/ and start using them right away.

Also, consider adding your .vimrc and .vim to a repository. Include .vimrc inside .vim and symlink .vim/.vimrc to ~/.vimrc to version control your .vimrc.

My vim files can be found here. Also, here's an imgur album demonstrating these plugins in action.

1. Syntax highlighting for django templates

Starting from vim 7.1, syntax ...

more info..
Topics : django vim
Javed
Comments
Reactions

Testing webhooks in development platforms

By : Javed Khan

Webhooks were popularized by PayPal and have become commonplace now a days. A typical webhook service fires a POST to a URL of your choice whenever something interesting happens. You handle this request and respond accordingly.

But you need to test webhooks regularly during development and it is a bit of a problem if your development server is inaccessible from the rest of the Internet. I have tried to solve this using ssh and nginx.

For this method to work you need:

  • Development server (which can hopefully process the webhook at /webhook) lets call it (D)
  • SSH accessible server (S ...

more info..
Javed
Comments
Reactions

Ubuntu as a django development platform

By : Javed Khan

Introduction:

Hi, I am Javed Khan, also known as tuxcanfly elsewhere on the internets. I have recently joined agiliq and am thrilled to be a part of the team.

This blog post covers the steps I took to convert a fresh ubuntu install to a full fledged django development platform.

Databases:

Mysql sudo apt-get install mysql-server mysql-client python-mysqldb Postgresql sudo apt-get install postgresql Sqlite sudo apt-get install sqlite python-sqlite

Version Control:

Git
need help setting up git with github? sudo apt-get install git-core git-gui git-svn Svn sudo apt-get install subversion rapidsvn meld meld is a diff/merge tool that can ...

more info..
© Agiliq, 2009-2012