Thursday, July 31, 2008

Django 0.96 and 1.0 alpha

The web framework for perfectionists with deadlines.
Django makes it easier to build better Web apps more quickly and with less code.

These notes refer to Django version 0.96 and 1.0 alpha:

2008-08-26:
GREAT so far:
* model-db-tables creation
* template inheritance
* great documentation
* fixtures

PROBLEMS so far:
* creating CRUD forms
* upgrading models sometimes requires going to the rdbms admin software to alter or drop the table
* console commands to administer, validate, reset, etc

2008-08-25:
* generic views:
* edit urls.py
* (r'^incomes/list/$', 'imbr.incomes.views.income_list'),
* edit views.py:
* return an object_list()
* edit models.py:
* create a ModelForm for your models

* django generic wrapper howto: http://www.b-list.org/weblog/2006/nov/16/django-tips-get-most-out-generic-views/
* django.views.generic.list_detail.object_list has "object_list" as the name of the variable for use on your templates. This is overridable.
* django.views.generic.list_detail.object_detail has "object" as the name of the variable for use on your templates. This is overridable.

2008-08-13:
* use babel, http://babel.edgewall.org, a Python library for I18N and L10N - use BabelDjango for your django projects
* to round-off decimals at django templates use the floatformat filter (ie 34.23234 --> {{ value|floatformat:3 }} --> 34.232)

2008-06-16:
* to use alternating rows, use CYCLE, make sure not to put spaces between the values, only commas.

2008-06-11:
* iif() equivalent == (c and (a,) or (b,))[0] from http://mail.python.org/pipermail/python-list/2001-June/090770.html

2008-06-04:
* in postgresql, an error in adding data will occur if database is prepopulated by data from fixtures. Use "python manage.py sqlsequencereset catalog | psql -U postgres -d lms" after loading your fixtures. Issue Ticket is http://groups.google.com/group/django-users/msg/7df2011a3700c3d0

2008-06-02:
* fixtures as json are much easier to maintain: add, edit, and remove records
* to save data as fixtures: python manage.py dumpdata --format=json --indent=4 catalog > catalog/initial_data.json
* to load data as fixtures: python manage.py loaddata catalog/initial_data.json
* use fixtures to add initial data to your database
* use unittest as unit tests for your models

2008-05-30:
* http://www.stonemind.net/blog/2007/01/12/small-django-tips-from-one-newbie-to-another/

2008-05-28 (chapter 7):
* redirect after POST to prevent saving duplicate record

2008-05-26 (chapter 7):
* escape variables in your templates to prevent XSS

2008-05-26 (chapter 5):
* for "python manage.py dbshell" to work under sqlite3 db, download the sqlite3.exe executable from www.sqlite.org and put it somewhere in your path
* put __str__() method to all model classes for a string representation of the class
* use PIL (python imaging library) for ImageFields in your model at http://www.pythonware.com/products/pil/
* django requires single column primary key
* django uses the MTV (model-template-view) framework. In MVC framework, Model = django.model, View = django.views and django.templates, Controller = django.URLconfs

2008-05-25: (chapter 4)
* Template inheritance can be nested to whatever level
* Templates are the Views in MVC model
* Templates have their own language but just enough for "presentation" level, if you want to add logic, use a View
*

Labels: , ,

Thursday, May 15, 2008

TurboGears 1.0.4.4

The rapid web development megaframework you've been looking for.

These notes refer to TurboGears 1.0.4.4

2008-04-16:
* storm as orm

2008-04-10:
* easy_install tgcrud == for basic crud forms
* tgcrud steps:
* Use the tg-admin crud command to generate the crud package.
* Customize the form field in /controllers folder.
* Import the package to your controllers.py
* Add a sub-controller to your Root controller class.

2008-04-09:
* if you create initial data when declaring your SQLObject classes, at the bottom of your model.py, create a temporary SQLObject class and issue dropTable() and createTable() to unlock the database
* to create unicode strings (for internationalization) prepend the string with the letter u (ie u'Name')
* use datetime.date(yyyy, mm, dd) to encode date values in SQLObject DateCol
* use lower case for all SQLObject class properties
* use underscore not uppercase for all SQLObject class properties
* use single noun when naming your SQLObject classes
* [tg-admin toolbox] automatically creates the database based on your model.py

Problems I have encountered so far:

2008-05-15:
* always changing modules, TG1 uses SQLObject while the not-yet-released TG2 now uses SQLAlchemy
* crud forms without coding, authentication without coding

2008-04-14:
* creating master-detail forms

2008-04-10:
* creating master templates

2008-04-09:
* create database schema from classes
* modify existing database with new classes

Useful Widgets:

2008-04-15:
* http://pythonisito.blogspot.com/2006/02/django-like-automated-admin-interface.html - todo

2008-04-14:
* FancyFlash - todo
* TGFastData == iconized crud forms
* DataGrid

2008-04-10:
* tgcrud == for basic crud forms

Overall, TurboGears is a very promising web development framework using Python.

Labels: , ,