background preloader

Django Price Engine

Facebook Twitter

Index — Django Design Patterns. Mechanical Girl : Scheduling Periodic Tasks with Celery 2.3.3 and Django 1.4. There are going to be times in the life of your application when you'll need to perform tasks - making requests to APIs, sending emails, or storing large amounts of data, for example.

Mechanical Girl : Scheduling Periodic Tasks with Celery 2.3.3 and Django 1.4

To do that, you'll most likely want to implement some sort of job queue - that is, a system that lines these tasks up and executes them. Celery is a task queue commonly used with Django - it's open source, easy to integrate with many other languages and frameworks, and it can execute tasks either asynchronously (in the background) or synchronously (wait until ready). This article is going to talk about a very basic Celery implementation for Django - you'll need to have Django installed already, and we'll discuss installing and configuring celery, django-celery (Celery integration for Django), and RabbitMQ (the recommended message broker for celery). If you're using an older version of Celery, it may be a little challenging finding the right docs - for 2.3.3, start with this link: Installing and configuring.

Getting Started — neo4django 0.1.8-dev documentation. Using Tastypie With Non-ORM Data Sources — Tastypie 0.10.0 documentation. Much of this documentation demonstrates the use of Tastypie with Django’s ORM.

Using Tastypie With Non-ORM Data Sources — Tastypie 0.10.0 documentation

You might think that Tastypie depended on the ORM, when in fact, it was purpose-built to handle non-ORM data. This documentation should help you get started providing APIs using other data sources. Virtually all of the code that makes Tastypie actually process requests & return data is within the Resource class. ModelResource is actually a light wrapper around Resource that provides ORM-specific access. The methods that ModelResource overrides are the same ones you’ll need to override when hooking up your data source. Approach¶ When working with Resource, many things are handled for you. What you don’t get out of the box are the fields you’re choosing to expose & the lowest level data access methods. Detail_uri_kwargsget_object_listobj_get_listobj_getobj_createobj_updateobj_delete_listobj_deleterollback If read-only is all you’re exposing, you can cut that down to four methods to override. Presentations/unbreaking-django.pdf. Matt Woodward's Blog: Generating CSV Files in Django.

This is a very quick tip since it's so simple but I did run into one little wrinkle with string encoding while doing this so I thought I'd share.

Matt Woodward's Blog: Generating CSV Files in Django

I had a request to generate a CSV of all the Old Dog Haven "Walk for Old Dogs" registrants so the fine folks managing the event can do email blasts, print registration sheets, and the like. Since Python has CSV functionality as part of the standard library the generation of the CSV data was very easy, and since the Django HTTP Response object was quite wisely designed to behave as a file-like object, writing the CSV data to the HTTP response was dead simple as well.

The only thing I ran into while writing the data to the response object was there were some non-ASCII characters in the database which threw this error:'ascii' codec can't encode character u'\xe9' in position 4: ordinal not in range(128) To get around this it was just a matter of tacking .encode('utf-8') to the end of the string objects when writing out the CSV data.