sábado, 19 de fevereiro de 2011

Django Better Form - on Server

System - Sistema: Server - Servidor
Python version unknown
Django version unknown

Installing and configuring django-form-utils on Server
Without easy_install command

Extras: Multi-edit
Ubuntu Gedit (very useful) plugin
Get Multi-edit!

Uninstalling previous django-form-utils easy_install installation:
 $ sudo easy_install -mxN django-form-utils  

Start a form-utils django app in your project:
 $ python manage.py startapp form_utils  
and then:
Download django-form-utils python source code
Download django-form-utils 0.2.0
django-form-utils project page
copy the content of file form_utils downloaded to your form_utils app.

Enjoy! Divirta-se!

domingo, 13 de fevereiro de 2011

Django Better Form

System - Sistema:
Ubuntu 10.04 LTS - the Lucid Lynx
Python 2.6.5
Django 1.2.4 final

Installing and configuring django-form-utils

 $ sudo apt-get install python-setuptools  
 $ sudo easy_install django-form-utils

Including form_utils:

Now change:

 #from django import forms  
 from form_utils import forms  

 class fooModelForm(forms.BetterModelForm):  
   class Meta:  
     model = fooModel  
     exclude = ('foo_field',)  
     fieldsets = [('Personal data', {'fields': ['name', 'email', 'phone'],  
                      #'description': 'Information',  
                      'classes': ['Personal data']  
     row_attrs = {'name': {'class': 'style_names'},  
            'email': {'class': 'style_email'},  
            'phone': {'class': 'style_phone'},}  
 <form action="." method="POST">{% csrf_token %}  
   {% if form.non_field_errors %}{{ form.non_field_errors }}{% endif %}  
   {% for fieldset in form.fieldsets %}  
     <fieldset class="{{ fieldset.classes }}">  
       {% if fieldset.legend %}  
         <legend>{{ fieldset.legend }}</legend>  
       {% endif %}  
       {% if fieldset.description %}  
         <p class="description">{{ fieldset.description }}</p>  
       {% endif %}  
         {% for field in fieldset %}  
           {% if field.is_hidden %}  
             {{ field }}  
           {% else %}  
             <li{{ field.row_attrs }}>  
               {{ field.errors }}  
               {{ field.label_tag }}  
               {{ field }}  
           {% endif %}  
         {% endfor %}  
   {% endfor %}  
   <input type="submit" value="Enviar!" class="button">  

More information: https://bitbucket.org/carljm/django-form-utils/src/
Also: http://djangosnippets.org/snippets/1314/

sábado, 5 de fevereiro de 2011

Django on Mac OS X 10.6.6 cookbook

System - Sistema:
  • Mac OS X Version 10.6.6 - Snow Leopard
  • Python 2.6.1 - default
Tiker Tool
To show the hidden mac files at finder and others functionalities

Install MySQL:
 $ curl -O http://mirror.services.wisc.edu/mysql/Downloads/MySQL-5.5/mysql-5.5.8-osx10.6-x86_64.dmg  
 $ sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /usr/local/mysql/support-files/mysql.server  

Locate the configuration defining the basedir and set the following :
Creating and configuring MySQL to Django:
 $ /usr/local/mysql/bin/mysql -u root  
 CREATE DATABASE django CHARACTER SET utf8 COLLATE utf8_general_ci;  
 GRANT ALL PRIVILEGES ON django.* TO 'django'@'localhost' IDENTIFIED BY '<password>';  

Download and install XConde for GCC and others

provides the Python bindings to interface with the database.

 $ curl -O http://internap.dl.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.3.tar.gz  
 $ tar -xvzf MySQL-python-1.2.3.tar.gz  
 $ cd MySQL-python-1.2.3  

Edit the site.cfg file:
Uncomment the line that begins #mysql_config =

Edit the path to point to /usr/local/mysql/bin/mysql_config:

mysql_config = /usr/local/mysql/bin/mysql_config
Complete the build and installation:
 $ python setup.py build  
 $ sudo python setup.py install  
 $ cd ..

IPython - optional
 $ curl -O http://ipython.scipy.org/dist/ipython-0.10.1.tar.gz  
 $ tar -xvzf ipython-0.10.1.tar.gz  
 $ cd ipython-0.10.1  
 $ python setup.py build  
 $ sudo python setup.py install  
 $ sudo python setup.py install_scripts --install-dir=/usr/local/bin  
 $ cd ..  

Install Django:
Exemplo where place django source code:

 $ cd ~  
 $ mkdir django  
 $ cd django  
 $ mkdir src  
 $ cd src  

Unpacking and installing:
 $ tar xzvf Django-1.2.4.tar.gz  
 $ cd Django-1.2.4  
 $ sudo python setup.py install  

Last MySQLdb fix:
 $ export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/  

Last Python Path fix:
 $ export PYTHONPATH=<pasta onde baixou o django>  
 $ export PYTHONPATH=/Users/dev/django/src