The Official Kountr Blog

Just another WordPress.com weblog

Where Should the Logic Go

leave a comment »

One of the features I added for someone was the days since last click, on a kount. Of course if the answer is 0, it reads “0 days ago” which, although true isn’t very smooth.

Someone suggested that if it is 0 it should just say “today”. This is an easy change to make, but I have an option. Currently I pass the number from the server to the template, where it is added to the string “ days ago” to produce the resultant phrase. Now I need to add logic to check for zero and change the string appropriately. I can do this logic in the template, or I can do it in the view and pass a string.

This isn’t a question of server vs. client because both of these will be executed on the server. It has to do whether this is presentation or not. I would argue that this is purely an issue of the presentation of the data, as such, it should be done in the template. I wasn’t sure when I started typing the post but I am sure now.

Use your views to serve up the raw data, as much as you can, and use the template for the presentation of that data. It is a soft rule because there are going to be cases where the power of python is necessary to solve the presentation of the information. I was working with date formats yesterday and I absolutely required the dateutil package to create the desired human readable date string. I couldn’t have done that presentation in the django template.

Written by Michael Artemiw

May 23, 2008 at 3:09 pm

Posted in Uncategorized

Leave a comment