Blog

The full list of my blog posts.

Handling csv uploads with django

Today I had to handle a csv file upload with django, parse it with a csv.DictReader and cycle on results.

I first thought this could be easily accomplished with the csv python module, but the task turned itself into a big pain in the a**, due to characters encoding and csv dialects Babylon.

After a bit of googling, I solved the issue thanks to a couple of very nice blog posts and the chardet python module. (http://pypi.python.org/pypi/chardet)

Here is what i did:

 
import chardet
def handle_upload(request)

     #assuming 'uploaded_file' is the file key in ...

Running Python in 32-bit mode on OSX

As i am working on a wxPython project, which must run with Python in 32 bit mode, as it relies on the Carbon API.

A way to run python in such mode is setting an environment variable before calling our interpreter:

export VERSIONER_PYTHON_PREFER_32_BIT=yes
python 

to save some typing, I created a bash script that i put on my path, with the following content

#!/bin/bash
export VERSIONER_PYTHON_PREFER_32_BIT=yes
python $*

Notice the last line that calls python passing all parameters you provide ad shell prompt.


django-cms-fragments

django-cms-fragments is django-cms plugin that allows injecting fragments of css, js or html in a django-cms page. 
The package is available via pypi and released under BSD license. You can get the full code or fork the project on github

You can see a live example on this page.


Openlayers css conflicts

While playing to build some django-cms-fragments examples, I noticed that OpenLayers conflicts with my theme derived fromTwitter Bootstrap.
If you end up with a strange OpenLayers map like this: 

It's a css issue caused by setting max-width on img tags. In my case, bootstrap was setting

img { max-width:100%; }

To get rid of it while not breaking the whole theme, override the setting just for your map div. For example, given a map div with class="map" the css could be:

.map { width:600px; height:400px;}
.map img { max-width:none; }

If you don't want to bother css classes ...


GeoDjango with spatialite on OSX

Yesterday I was playing around with GeoDjango and I wanted to use the spatialite backend (django.contrib.gis.db.backends.spatialite) , but the setup on OSX was not so trivial. This method, based on brew is not covered by the GeoDjango documentation about platform-specific instructions.

I will assume:

  • you have already brew installed
  • you are working with virtualenv. If not, I strongly suggest you to do this, when developing with Django and Python in general.

To make short: sqlite is built in a modular fashion and has the possibility to load up additional modules when it starts. The problem is ...


Urban Ecosystem Europe

Urban Ecosystem Europe

Urban Ecosystem Europe is an environmental data visualization platform I am developing for Ambiente Italia Srl.
The project is aimed at comparing different European cities on a common base of sustainability indicators.
The platform lets you explore the data in different ways, with thematic maps, charts and tabular data visualizations.

All the project is based on open source packages such as Openlayers, jQuery, jqplot, underscore.js and Twitter Bootstrap. 

The official web platform is still on a testing phase and will be publicly accessible by the end of April, 2012.


World Wide Temperature

World Wide Temperature

A website showing the temperature around the world, with data coming from METAR messages broadcast to planes in flight.
Data is shown on a map built with Openlayers
There is also an experimental representation of temperatures made with WebGL-Globe

This is still a draft and will hopefully be updated soon.

 

 

Go to World Wide Temperature


Mapparia

Mapparia

Mapparia is a website that displays updated data about air quality in Lombardia (Italy)

Go to www.mapparia.it


New website

This is my new homepage based on django, django-cms, twitter bootstrap, django-blog-zinnia, django-imagestore and other reusable django apps.

I switched to my old Drupal site to a Django one. Drupal is really awesome, but as a Python programmer i simply couldn't resist.
Moreover, lately I've been doing a lot of work with Django, so why spare my skills ? ;)

One more thing ... If you want to know more about my website you can even ...

check out the source or fork it on github!



Web RSA Calopicos

Web RSA Calopicos

Document on the state of the environment for Agenda 21 (Update for year 2009).
Developement of a web application http://www.a21calopicos.it/rsa/ for web publishing of RSA data, with webgis functionalities based on Openlayers (javascript) and Google Maps cartographical data.

Go to the webrsa