17 de febrero de 2011

Un parrafito de Montaigne


"Yo soy de la partida. Aquellos que siguen el camino opuesto, el de complacerse en ellos mismos, el de estimar lo que tienen por encima del resto y no reconocer ninguna forma más hermosa que la que tienen ante sus ojos, si no son más avisados que nosotros, con seguridad son más felices. No envidio en absoluto su sabiduría, pero sí su buena suerte."

- Montaigne

15 de febrero de 2011

Dale Carnegie quotes

I read some books written by Dale Carnegie and found lots of interesting stuff on them, so, here goes my post dedicated to him, including a link to a page of some of his quotes.

Quotes here: http://bit.ly/Dale_Carnegie

3 de febrero de 2011

Backup/Restore a MySQL dump from the console

Given that tools like MySQL Administrator or MySQL Query Browser most usually won't behave very good when it comes to recovering large db backups, moreover if there is UTF-8 stuff in the dump, I decided to go for the mysql shell, which does much better.

Here some useful commands to have handy:

Dump ALL MySQL Databases

mysqldump --user=XXXXXXXX --password=XXXXXXX -A > PATH_TO_SQL_DUMP_FILE.SQL

Dump Individual or Multiple MySQL Databases

mysqldump --user=XXXXXXXX --password=XXXXXXX --databases DB_NAME1 DB_NAME2 DB_NAME3 > PATH_TO_SQL_DUMP_FILE.SQL

Dump some particular tables from a MySQL Database

mysqldump --user=XXXXXXXX --password=XXXXXXXX --databases DB_NAME --tables TABLE_NAME > PATH_TO_SQL_DUMP_FILE.SQL


If you want to make sure of not having backwards compatibility issues from the MySQL Server versions between your development and production environments, you may want to add this to the commands:

 --compatible=mysql323

Reloading the full contents of a database:
  1. Unzip the backup file you wish to use.
  2. Open it up and pull out only the information that you will need.
  3. Save this text file.
  4. Use the following command to feed back in the contents of a text file: 
mysql --verbose --user=XXXXXXXX --password=XXXXXXXX DB_NAME < PATH_TO_SQL_DUMP_FILE.SQL

Django: Dump your database contents to(SQL data) into an xml file

To dump all the data in your Django project's db into a nice xml fixture, just run the following command:
python manage.py dumpdata --format=xml APP_NAME > SOME_FIXTURES_FOLDER/APP_NAME/initial_data.xml
Update:

As Fabi[1] correctly (and violently jeje :-P) pointed out, json is much cooler:

python manage.py dumpdata --indent=4 data.json

[1] @caffeineGalli at Twitter and his site: http://from-the-cloud.com/

1 de febrero de 2011

Upgrading Django 0.96 to 1.2.4: tuning up model fields

Continuing with the last post, here goes a script I made to upgrade the fields of the models.

The script is here. The upgrade reference is here: "Porting your apps from Django 0.96 to 1.0".

Add CSRF token to all your Django templates in a glimpse.

Recently, in my work(at Machinalis: www.machinalis.com) I had the tough experience of having to upgrade a Django app built with Django 0.96 to Django 1.2.4.

I had to deal with things like oldforms, newforms, ObjectPaginator, changing 'maxlength' to 'max_length' in models fieleds and a long list of etc's.

But it came the time for me to deal with integrating csrf to all the giant bunch of forms there around... And that's not meant to be done by a human being :-P

So, I created a Python script for that. You can get it from my GiHub here.

Appart from that, you'll need to add this 'django.middleware.csrf.CsrfViewMiddleware' to MIDDLEWARE_CLASSES in settings.py and, depending on the nature of your project, making several changes more. I'd suggest taking a look(as I did) at the Django Project Reference on CSRF here.

More scripts I made to help upgrading Django 0.96 to 1.2.4 coming soon!