Mostrando entradas con la etiqueta django. Mostrar todas las entradas
Mostrando entradas con la etiqueta django. Mostrar todas las entradas

19 de mayo de 2015

REST with Python: awesome API development tools and docs


Here goes a collection of links I find very useful to keep handy regarding RESTful APIs and Python:



Frameworks/libraries


Videos/blog posts/Tutorials


Others


Dealing with speed

  • json, from the Python standard library, is slow and performance can be improved using ujson
  • SQLAlchemy has an option to cache connections: connection pool.


Special thanks to Juan Norris for creating and letting me share the original document here.

3 de junio de 2013

Santex Tech Meetup: Python en el mundo real




Python en en mundo real



Se expondrán brevemente proyectos y empresas que han encarado proyectos exitosos a nivel mundial con Python, comparando ventajas, ecosistema, comunidad y desventajas del lenguaje.
La charla apuntará a ser bien de alto nivel (en el sentido de que no requiere más que nociones básicas de programación) y se mostrarán ejemplos prácticos de programas y librerías de computación científica, motores para hacer juegos, aplicaciones web, frameworks, etc.

UPDATE:

Material de la charla! https://github.com/matiasherranz/talks/tree/master/Real_world_Python

Fotos del evento! link.

1 de octubre de 2012

Working on django-notification (django 1.4 support, internationalization, etc.).

What's this all about?


Working on a Django project, I happened to come across with the need of a notifications app for Django. The first one to take a look at and perhaps the most popular the last years is django-notification. So, let's take a look at it, my friend.

What was the problem?


Well, to begin with, it does not work with Django  1.4 or above. That's the starting point for me to branch out from the original repo of the project. I tuned it up to work with Django 1.4.

Later down the road, we decided to use internationalized dates. And then again, django-notification did not handle them properly (does not suppor internationalization at all). And therefore a zillion of our tests started to throw warning.

Once again, I had some time to spare, and got myself hands on that.

Summarizing

Which changes did I make to django-notification? Let's take a look:

  • Made it work with django 1.4
  • [this is a big one] Made django-notification timezone aware and compliant.
  • Made every single file PEP8 compliant
  • Fixed a bunch of issues I found while going through the codebase (like missing imports)
  • Quite a few code improvements (like the usage of "zip" or "file" as variable names)

Where's this code? How I install it for my project?


The code is available here, at my github account: https://github.com/matiasherranz/django-notification

You can install it with pip this way:

pip install  -e git+https://github.com/matiasherranz/django-notification.git#egg=django-notification

I'm open to suggestions, comments or pull requests to improve the app.

Hope it helps!

15 de septiembre de 2012

Material de mi charla sobre Django en el PyDay Córdoba 2012

Acá dejo el contenido de mi charla de Django del PyDay 2012:

Filminas y la aplicación que mostré, creada paso a paso:

Muchas gracias a todos/as los/as que vinieron!


Cualquier consulta, no duden en mandarme un email.


Salud!

7 de febrero de 2012

Repairing PostgreSQL after upgrading to Mac OSX Lion

I upgraded to Mac OSX to 10.7.3 (Lion) yesterday and had some issues with PostgreSQL.

For instance, when I tried to run the South migrations for the Django project I'm working at, I got this:

psycopg2.OperationalError: could not connect to server: Permission denied
    Is the server running locally and accepting
    connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
How I fixed this?

  1.  Edit PostgreSQL's config to define the unix_socket_directory setting:

    $ sudo nano /Library/PostgreSQL/9.0/data/postgresql.conf

    In my case I changed the setting to unix_socket_directory = '/var/pgsql_socket/'.
  2. Exceute the following commands:

    $ sudo dscl . append /Groups/_postgres GroupMembership postgres
    $ sudo chmod g+w,o+rx /var/pgsql_socket/

  3.  Restart the server:

    $ sudo -u postgres /Library/PostgreSQL/9.0/bin/pg_ctl -D /Library/PostgreSQL/9.0/data/ restart
Note: You may want to add an alias for this command in your ~/.profile file. If so, it is just a matter of adding a line like this:

alias restart_postgres='sudo -u postgres /Library/PostgreSQL/9.0/bin/pg_ctl -D /Library/PostgreSQL/9.0/data/ restart'

15 de septiembre de 2011

Después de haber laburado más de 10 horas hoy....

.... llegar al final del día logrando esto, es.... en un modo muy particular, maravilloso! jeje

Acá la cosa en cuestión que me hizo feliz ver:


----------------------------------------------------------------------
Ran 414 tests in 232.764s

OK
Destroying test database for alias 'default' ('test_cpi_mrp3')...


Sí señor! Sí señor! Ahora sí puedo hacer un push a origin e irme a dormir :)

5 de julio de 2011

How to install MySQL Server and Python connector in Mac OS X Snow Leopard


================================================================
-> MySQL Server and Python connector(Mac OS X Snow Leopard):
================================================================

Here goes some tricky stuff. You may want to consider getting yourself a cup of
linden infusion :-P

--> If you have a previous MySQL version:

If you have a previous MySQL version, perhaps a 32 bit one, you may encounter several
problems to perform the upgrade to a newer, 64-bit version. But don't worry, the
following steps should get you going in no time.

Hands on!
To uninstall the previous version, do this *in order*:

- First you need to go to: /Library/Receipts and look for a file named
  'InstallHistory.plist' (It's just a regular property list)
- Open it and look for the entries regarding MySQL, and delete them.

    MacBookPro:~ matias$ cd /Library/Receipts/
    MacBookPro:Receipts matias$ sudo nano InstallHistory.plist
    ctrl+shift+w, look for the entries regarding MySQL and delete them.
    ctrl+o (save) ctrl+x (exit)

- As the installer receipts are actually located in a different place on Snow Leopard:

    MacBookPro:Receipts matias$ cd /private/var/db/receipts/
    MacBookPro:receipts matias$ ls *mysql*
    com.mysql.mysql.bom          com.mysql.mysqlstartup.bom
    com.mysql.mysql.plist        com.mysql.mysqlstartup.plist
    MacBookPro:receipts matias$ sudo rm  *mysql*


- Now we are ready to do the uninstall work per se, by doing these *in order*:

    * Use mysqldump or MySQL Admin to backup your databases to text files!
    * Stop the database server
    * sudo rm /usr/local/mysql
    * sudo rm -rf /usr/local/mysql*
    * sudo rm -rf /Library/StartupItems/MySQLCOM
    * sudo rm -rf /Library/PreferencePanes/My*
    * edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
    * rm -rf ~/Library/PreferencePanes/My*
    * sudo rm -rf /Library/Receipts/mysql*
    * sudo rm -rf /Library/Receipts/MySQL*
    * sudo rm /etc/my.cnf


--> Install MySQL (server, startup item, pref pane):

- Install mysql's x86_64  version from the .dmg file. Download the .dmg from
  here: http://dev.mysql.com/downloads/mysql/5.1.html#downloads
  (I also put the installers under '3rdparty/MacOSX_Installers' folder).

--> Install MySQLdb in the virtualenv

- Turn the virtualenv on. This command does the trick:

    MacBookPro:~ matias$ laexpo_start
    (Env)MacBookPro:~ matias$

- Fetch MySQL-python-1.2.3 from here: http://sourceforge.net/projects/mysql-python/.
  I'll assume you downloaded the .tar.gz file to the Desktop.

- Unpack the tarball, enter the folder:

    (Env)MacBookPro:~ matias$ tar xzf MySQL-python-1.2.3.tar.gz
    (Env)MacBookPro:~ matias$ cd MySQL-python-1.2.3

- Open the 'site.cfg' file and edit the 'mysql_config' to poin to the path where
  you mysql_config resides. For me it is '/usr/local/mysql-5.1.50-osx10.6-x86_64/bin/mysql_config'

- Open the 'setup_posix.py' file and set the 'mysql_config.path' to the same path
  you did in the previous step(line 26). Should end up looking like this:

  mysql_config.path = "/usr/local/mysql-5.1.50-osx10.6-x86_64/bin/mysql_config"

- Compile the thing:

    (Env)MacBookPro:~ matias$ cd ~/Desktop/MySQL-python-1.2.3
    (Env)MacBookPro:MySQL-python-1.2.3 matias$ python setup.py clean
    (Env)MacBookPro:~ matias$ ARCHFLAGS='-arch x86_64' /usr/bin/python setup.py build
    (Env)MacBookPro:~ matias$ ARCHFLAGS='-arch x86_64' python setup.py install

* NOTE 1: It is critical to have the virtualenv activated before running the above
          listed command. If it is not, the installation of MySQLdb will be done in
          the system and no in the virtualenv and therefore MySQLdb will not be
          available when you turn the virtualenv on.

* NOTE 2: It is also critical to set the compilation flags correctly. If not set
          correctly, the compilation will default to 32-bit architecture and will
          not work afterwards with MySQL.

* NOTE 3: DON'T USE 'sudo' FOR THE COMPILLATION/INSTALL COMMANDS. If you do so, you'll
          be installing MySQLdb to the system and not to the virtualenv.


- Confirm the process worked ok:

    (Env)MacBookPro:MySQL-python-1.2.3 matias$ python
    Python 2.6.1 (r261:67515, Dec 17 2009, 00:59:15)
    [GCC 4.2.1 (Apple Inc. build 5646)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import MySQLdb
    >>> MySQLdb.version_info
    (1, 2, 3, 'final', 0)

14 de junio de 2011

Installing psycopg2 inside a virtualenv in Mac OS X

If you tried to install psycopg2 inside a virtualenv in Mac OS X and got something like this:

(Env)MacBookPro:proj matias$ ARCHFLAGS="-arch i386 -arch x86_64" pip install --upgrade psycopg2
Downloading/unpacking psycopg2
  Downloading psycopg2-2.4.2.tar.gz (666Kb): 666Kb downloaded
  Running setup.py egg_info for package psycopg2
    Error: pg_config executable not found.
 
    Please add the directory containing pg_config to the PATH
    or specify the full executable path with the option:
 
        python setup.py build_ext --pg-config /path/to/pg_config build ...
 
    or with the pg_config option in 'setup.cfg'.
    Complete output from command python setup.py egg_info:
    running egg_info
creating pip-egg-info/psycopg2.egg-info
writing pip-egg-info/psycopg2.egg-info/PKG-INFO
writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'
warning: manifest_maker: standard file '-c' not found
Error: pg_config executable not found.


Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:


    python setup.py build_ext --pg-config /path/to/pg_config build ...


or with the pg_config option in 'setup.cfg'.
----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /Users/matias/.pip/pip.log

The issue is that psycopg depends on pg_config command, and if you don't have it, you can't install psycopg.


That got it fixed for me:
export PATH=/Library/PostgreSQL/8.4/bin/:"$PATH"
Now, let's go again:



(Env)MacBookPro:proj matias$ ARCHFLAGS="-arch i386 -arch x86_64" pip install psycopg2
Downloading/unpacking psycopg2
  Running setup.py egg_info for package psycopg2
    no previously-included directories found matching 'doc/src/_build'
Installing collected packages: psycopg2
 (....lot's of lines of output here....)
Successfully installed psycopg2
Cleaning up...
Done!

9 de mayo de 2011

ipdb sometimes goes crazy too

Debugging a post request from a Django dev server with ipdb, I got that:


ipdb> print request.FILES.get('data_dict.pickle')
None
ipdb> request.python(3743,0x1019c1000) malloc: *** error for object 0x101cf5950: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
Just wanted to share that :)

6 de mayo de 2011

Django mode for TextMate

Developing with Django using TextMate?

Take a look at this!

http://code.djangoproject.com/wiki/TextMate

Installation:
mkdir -p /Library/Application\ Support/TextMate/Bundles
cd /Library/Application\ Support/TextMate/Bundles
svn co http://svn.textmate.org/trunk/Bundles/Python%20Django.tmbundle/
git clone https://github.com/textmate/python-django-templates.tmbundle.git
Usage:

Just set the language of your files to "Python Django" and that's it!

PEP8 check in TextMate

I think any serious programmer that codes with Python should try to get his/her code as close as possible to PEP8.

Many IDEs have their own way to perform static PEP8 code checks. If you use TextMate, here is a way to go:


https://github.com/astrofrog/python-pep8-tmbundle

Installation:

cd ~/Library/Application\ Support/TextMate/Bundles/
git clone git://github.com/astrofrog/python-pep8-tmbundle.git "Python PEP8.tmbundle"
cd Python\ PEP8.tmbundle/
git submodule init
git submodule update
osascript -e 'tell app "TextMate" to reload bundles'

Usage:
shift + crtl + command + v

And that's it!
 

1 de mayo de 2011

De cero a Django en 30 minutos: videos de la charla





PyDay Córdoba - Mi charla sobre Django

Después de la choripaneada, el ping pong con la gente de PyAr, los comentarios super apasionados respecto de las bases de datos no relacionales de Emiliano Marcozzi y las infaltables y fabulantásticas charlas geek, termina el PyDay Córdoba 2011.

Estuvo muy bueno, la verdad. Excelente la organización de Juan BC.

De paso, aprovecho este post y dejo el material de mi charla sobre Django:
https://github.com/matiasherranz/scoobygalletas/tree/master/PyDay_Cba2011

Están las filminas(pasadas a PDF) y el código completo del ejemplo que mostré. Cualquier cosa, ya saben, me tiran un mail a scoobygalletas@gmail.com.

Saludos!

27 de abril de 2011

How to install PIL on Snow Leopard

For all the unfortunate like me that came across the pain it involves to correctly install PIL to use Django ImageFields in Mac (Snow Leopard) here goes what worked for me:

MacBookPro:~ matias$ sudo -s
bash-3.2# ARCHFLAGS="-arch i386 -arch x86_64" pip install PIL
"sudo -s" is needed because ARCHFLAGS doesn't seem to get passed into sudo.

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".

24 de septiembre de 2009

Iterating over a dictionary in Django templates

Just a quick one: To iterate over a list you do something along the lines of:

{% for item in list%}{{ item }}{% endfor %}

But this fails (silently, of course) for dictionaries and the magic you are looking for is to call .items on the dictionary then iterate key,value across that:
{% for key,value in dictionary.items %}{{ value }}{% endfor %}

Edit: This is now covered in the django documentation itself.

Artículo original: acá.