Category: Architecture

I have developed based on Drupal stack for more than 4 years. In my opinion:

  • The learning curve of Drupal is higher than other stacks, since It’s flexibility. 
  • Server environment in China is very poor. Drupal can works well at least installed in VPS.
  • The requirement is very simple in China, you can just install something like DZ forum or DEDE cms to accomplish the goal. Since the feature requirement is not comes from business requirement, they just want a simple web page to display there company profile etc.
  • Lots of teams want to build there own framework. (I disagree with this idea, it is wasting resource and time.)
  • The traffic of the website in China almost 100x larger than EU or US, but the value of the traffic is very low. So you need do more performance optimization for the Drupal site in China.
  • Most developers in China works on a Windows PC. So no drush, varnish, memcache, cron, etc.
  • Lots of developers installed Drupal and thought that Drupal is a blog :)

Django

Introduction:

Django is the modern base stack for web development. Compared with Ruby on Rails, I think I like Django better:

  • Build-in ready to use admin interface
  • Written in Python, with better performance
  • Simpler and reasonable project struct
  • Smaller base stack, but you can add what you want (ajax, south, REST, oauth …)

Essential tools for Django development:

virtualenv

We use this to manage the library for the project. You can have different environments (different python modules, different python versions) for every projects.

Create new clean environment foobar

virtualenv –no-site-packages foobar

Active the environment foobar

source foobar/bin/activate

Then install library in the environment foobar

pip …

At the end leave the environment foobar

deactivate

pip or easy_install

To install python libraries.

Django south

Database migration tool. Alertanative tool for syncdb

Create migration for your app

./manage.py schemamigration myapp –initial

Apply the migration

./manage.py migrate myapp

Then change the model myapp, and make a new migratation

./manage.py schemamigration myapp –auto

And apply it

./manage.py migrate myapp django-annoying

Useful decorators:

rederto ajaxrequest JSONField getobjectorNone

django-compressor

Compresses linked and inline javascript or CSS into a single cached file. And support coffeescript and less css framework.

django-pagination

pagination tools

django-piston

A mini-framework for Django for creating RESTful APIs.

django-celery

Celery integration for Django.

Celery is a task queue/job queue based on distributed message passing.

django-mongodb

MongoDB backend

django-admin-tools

Custom user interface, customizable dashboard

django-socialauth

oauth for social sites, login with twitter account, facebook account or gmail account

django-storages

Amazon S3, MogileFS file storage

django-grappelli

A jazzy skin for the Django Admin-Interface

django-profiles

A simple application which provides basic features for working with custom user profiles in Django projects.

django-registration

User registration and login

simplejson

JSON encoding and decoding

django-imagekit

Image process, support S3.

Beautiful Soup

Web Scrapping tool

django-workflows

django-workflows provides a generic workflow engine for Django.

The Django development environment steps:

How to install the virtualenv & django:

sudo apt-get install python-virtualenv

virtualenv –no-site-packages env_nm

source env_nm/bin/activate

pip install django

… ( install other modules )

deactivate

Export the libraries of the environment to a configuration file

pip freeze > requirements.txt

Install the environment in a clean environment

pip install -r requirements.txt

The missing part of Django settings.py

import os

ROOT_PATH = os.path.dirname(file)

MEDIAROOT = os.path.join(ROOTPATH, ‘static’)

TEMPLATE_DIRS = (

os.path.join(ROOT_PATH, ‘templates’)

)

Django Signals – You should pay attentation to this

This is the ECA (Aka: Event Condition Action) part of Django. 

ECA is the essentail part of modern web appliactions.

Other useful modules:

SQLAlchemy – use this when the django ORM is not enough.

Haystack – Modular search for Django.

Django-mptt – Preorder tree management

What is new in Drupal 7

User experience

The design process can see at http://www.d7ux.org/

Drupal 7 UX design principles:

1. Make the most frequent tasks easy and less frequent tasks achievable.

2. Design for the 80%

3. Privilege the Content Creator

4. Make the default settings smart

Learned from D7 AI:

Less clicks is not nessarlly better.

Few options show = more decision made.

Order by frequency use

Dashboard module provide the simple way to organizing administrative tasks and tracking information within your site.

Database layer

New database API

1. New in D7 is the placeholder and placeholder array

$node = db_query(“SELECT * FROM {node} WHERE nid = :nid“, array(‘:nid’ => $nid))->fetchObject();

$title = db_query(“SELECT title FROM {node} WHERE nid = :nid“, array(‘:nid’ => $nid))->fetchField();

2. New result set loop functions

$result = db_query(“SELECT nid, title FROM {node}”);

foreach ($result as $record) {
$record = $result->fetch();            // Use the default fetch mode.
//$record = $result->fetchObject();  // Fetch as a stdClass object.
//$record = $result->fetchAssoc();   // Fetch as an associative array.
}

see more: http://drupal.org/node/310072

3. Dynamic queries

This is the big change in D7, see from http://drupal.org/node/310075

Support for master/slave replication

$result = db_query(“SELECT nid, title FROM {node}”, array(), array(
‘target’ => ‘slave’,
‘fetch’ => PDO::FETCH_ASSOC,
));

Support for Transactions

A function simply calls “$txn = db_transaction();” as its first (or nearly first) operation to make itself transactional.

Nosql (Mongodb) support

D7 has a mongodb module provide the mongodb API.

Other

Default to InnoDB engine

Semantic Web support

Support RDF

More

More secure password system, MD5 is no longer used.

More can see from http://drupal.org/about/new-in-drupal-7