Oct 14

I just downloaded the recently release Open Office 3.0 productivity suite. On first launch of the software, I was prompted to register the software in order to help Sun determine the global market share. I didn’t mind doing this so I clicked the Register button. What transpired was a very long process requiring me to fill out a form for the Sun Developer Network, receiving a registration email which I then had to validate. After this registration process was complete, I still had to go back to the original Open Office registration page which, in the end, didn’t actually work. Sun in one stroke ticked me off before I had a chance to even see the software. I’ve given up my time and my email address and our mutual goal (registering the software) wasn’t achieved. Not a great first impression and very poor customer service. However, it is valuable to reflect on this experience when designing your own software.

The point is, determine what the most significant thing that you want your users to do and give them the shortest path to achieving this goal. Goal driven design is nothing new and agile developers tend to already think this way. If Sun’s goal is to determine market share, here is one alternative to the process.

  1. “Do you want to register now and help Sun get a snapshot of the global market share of Open Office.org”, Yes / No
  2. Clicking Yes takes you to a simple form that asks for email address and password and a submit button.
  3. Customer fills in email address and password, clicks register.
  4. Sun could then send a single email to me explaining the benefits of the more full fledged program. If I do not choose to opt-in to the full program then Sun still has what they want, a registered user of Open Office, with minimal hassle on my part.

On further thought, Sun could make this simpler:

  1. On first launch, ask the user if they would like to provide feedback to Sun.
  2. If the customer agrees then on each launch, send a ping to Sun’s database with information on who is using the software.

This is a gross example but represents some real world UI lunacy we are often faced with. Make sure you give your customers the easiest path to achieving their goals.

Apr 05

I haven’t posted any django information in a while because I haven’t had any time to mess with it. Today, I dove back in.

I wanted to get a fresh start with the project I’m working on so I thought I’d clear out the database. Why for the life of me I couldn’t find the proper incantation to make this happen I’ll never know.

After searching for about 10 minutes I found it. I’m posting it here so I can reference it the next time I have a brain lapse.

Are you ready? Here it is…
manage.py flush

This will reset the database to the state immediately after it was created.

Dec 17

Fans of the excellent Python based web application framework Django will be happy to find out that Christmas has come early this year. Apress has just published The Django Book. Every good framework needs excellent documentation in order to break through. It’s a sign that the software has come into it’s own. Django is no exception.

The Django Book was published by Apress in December 2007. It covers the most current version of Django (as of this writing). It is available in hard copy from your favorite book seller on you can read it free online at the Django Book website. I’ve used this book in BETA form for the last four months. The final version exceeds the beta in quality and depth.

Technorati Tags: , , ,

Powered by ScribeFire.

Dec 12

Interested in cutting down on your driving time? It’s easy. Avoid left turns. At least that’s what UPS is doing.
23303950

according to Heather Robinson, a U.P.S. spokeswoman, the software helped the company shave 28.5 million miles off its delivery routes, which has resulted in savings of roughly three million gallons of gas and has reduced CO2 emissions by 31,000 metric tons. So what can Brown do for you? We can’t speak to how good or bad they are in the parcel-delivery world, but they won’t be clogging up the left-hand lane while they do their business.

Technorati Tags: , ,

Dec 11

Django, the hot Python web application framework, provides an excellent administration user interface out of the box. Django originated in the newsroom and it’s reflected throughout the code. The idea behind including an admin interface is that reporters can work on easily submitting their content while the code jockeys work on the fun stuff – namely presenting that content to their readers.

The admin interface provides a great experience out of the box but is also extensible so you can add features not present in the original interface.

I was working on a Model that was meant to be manipulated inside the admin interface. I wanted to provide constraints on some Integers Fields in that that model in order to limit the range of possible entered values.

The first way I tried to solve this was to add a choices parameter for my IntegerFields. While this technique worked, it caused my admin interface to add a drop down box displaying my choices. This was not what I was looking for.

The final way I solved it came from a suggestion on the Django IRC channel. Use validators. It took some digging through the documentation but I figured out how to do what I want. I will explain by way of an example.

from django.core import validators
from django.db import models

range_validator = validators.NumberIsInRange(0,4)

class Test (models.Model):
    valid_int = models.IntegerField(null=True, blank=True, validator_list=[range_validator])

The validation framework is defined in the validators module. Import that if you need to perform any validation on your data.

Django includes a number of built-in validators. I lucked out and they had a validator that suited my purposes. The first step creates a validator instance of NumberIsInRange with the appropriate range. This returns a callable that I use later.

Model fields take a parameter of type validator_list which is a “list of extra validators to apply to the field. Each should be a callable that takes the parameters field_data, all_data and raises django.core.validators.ValidationError for errors. (See the validator docs.)”

A quick test in the admin interface and the code works.

The Django documentation contains everything you need to get the job done. Some careful searching and a great support community has helped make Django one of the best web frameworks available.

Technorati Tags: , ,

Oct 08

Django, the Python based web framework has a template system which allows you to separate business logic from presentation. It provides a method of substituting variables inside the template using the {% var %} syntax.

One of the things you will often need to do is provide links to various views inside your application. However, the worst possible way to do this is to hard code pages inside your template. Developers of the Django framework are proponents of the DRY philosophy. This is evident in the URL mapping mechanism.

When you need to link to other views in your application, open your urls.py file. Copy the full package.app.view.view_name to your view. Then, inside your template in an anchor tag insert the following.

<a href="{% url package.app.view.view_name %}">
Link location
</a>

Django will then substitute the view name with the proper link relative to where your application lives.

The obvious advantage to doing this is if you ever publish your Django application to a different location you don’t have to update your links.

Technorati Tags: ,

Sep 27

Django, the Python based web application framework, is an excellent Model/View/Controller application framework for rich website design.

A Django application runs under a web server. However, often it is necessary to develop external scripts that need to interact with you web application data models. This brief tutorial will walk through an example. This may not necessarily be the _best_ way to do this, but merely a way. I struggled for a few hours on this last night and thought it would be useful to others to document my results.

Let’s look at an example. Feel free to take this and modify it as needed. It’s a bit contrived but will suit our purposes.

Suppose you have written a blog application and you want to periodically purge old entries. In your Model, you have written code to to all of the heavy lifting. Now, you want to make sure that these updates happen at a scheduled interval.

Assume your project lives in c:\project\blogprj

import sys,os
from datetime import *
sys.path.append('c:\\project')
os.environ['DJANGO_SETTINGS_MODULE'] ='blogprj.settings'

from django.core.management import setup_environ
from blogprj import settings

from blogprj.blog.models import Entry

setup_environ(settings)

blogs = BlogEntry.objects.all()

for entry in blogs:
     entry.purge_oldentries(date.today())

Let’s take a closer look at this.

sys.path.append('c:\\project')

This line appends your project directory to the python module search search path so that it can find the your packages. Remember, when django creates your template, it creates an __init__.py file in each directory of your project and apps. These __init__.py files tell python to treat the entire directory as a python package. If you set your module path to c:\\project\\blog then python will not be able to find the root of your packages (blog)

os.environ['DJANGO_SETTINGS_MODULE'] ='blogprj.settings'
The DJANGO_SETTINGS_MODULE variable tells your django application the name of the settings module. It uses the Python path syntax.

from django.core.management import setup_environ
from blogprj import settings

Since you are using Django libraries, you must tell it where to find your settings.py file. This is done through the function setup_environ and your project settings, imported here.

from blogprj.blog.models import Entry

We are going to be working with the Entry model, so we need to import it.

setup_environ(settings)

As stated previously, we must tell Django to use our project settings. This is necessary so Django can know what database we use, our installed apps, etc. This is handled by the setup_environ() method which takes a Settings object as a parameter.

Once this is done, the rest of the application merely performs the work against the model.

Save this script and you can run it inside your favorite scheduler, on Windows, we use Task Scheduler.

I hope this small tutorial has given you a little insight in how to call Django from external scripts. I welcome your comments.

Technorati Tags: , , ,

Sep 23

“Programming  languages are like girlfriends: the new one is better because *you* are better” – Derek Silvers

Found that one in a blog post, from the owner of CD Baby, on why he dumped the Ruby Rails framework and went back to plain old PHP.

Aug 06

“We’ve heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.”

Aug 06

Where a new system concept or new technology is used, one has to build a system to throw away, for even the best planning is not so omniscient as to get it right the first time. Hence plan to throw one away; you will, anyhow.

Tiger Airways
preload preload preload