<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Giv Parvaneh &#187; Tutorials</title>
	<atom:link href="http://www.givp.org/blog/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.givp.org/blog</link>
	<description>::::..::..:::::::...:::::....::......:::::::::....::::......::::::::::::::::</description>
	<lastBuildDate>Thu, 22 Jul 2010 21:42:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<meta xmlns="http://www.w3.org/1999/xhtml" name="robots" content="noindex,follow" />
		<item>
		<title>Test-Driven Development &#8211; How Do I Start?</title>
		<link>http://www.givp.org/blog/2010/07/22/test-driven-development-how-do-i-start/</link>
		<comments>http://www.givp.org/blog/2010/07/22/test-driven-development-how-do-i-start/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 21:42:12 +0000</pubDate>
		<dc:creator>Giv</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[p]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.givp.org/blog/?p=188</guid>
		<description><![CDATA[There seem to be a lot of developers who like the idea of Test-Driven Development (TDD) and can clearly see the benefit of having tests written for their code but can&#8217;t seem to get their head around the process. How do you start writing unit tests before writing the actual code? Let&#8217;s start with an [...]]]></description>
			<content:encoded><![CDATA[<p>There seem to be a lot of developers who like the idea of <a href="http://en.wikipedia.org/wiki/Test-driven_development" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Test-driven_development?referer=');">Test-Driven Development</a> (TDD) and can clearly see the benefit of having tests written for their code but can&#8217;t seem to get their head around the process. How do you start writing unit tests <em>before</em> writing the actual code?</p>
<p>Let&#8217;s start with an example. You want to write a method that takes a URL as an argument and have it tell you through a boolean return if it&#8217;s the correct domain or not. It seems simple enough. Just write your method, pass the URL through some regular expression and you&#8217;re done.</p>
<p>But you yourself already know which domains are allowed and which are not so before writing the actual code you can run some tests in your head. E.g. I only want www.bbc.co.uk and its sub-domains on http and https. Nothing else should be allowed. So https://beta.bbc.co.uk/iplayer should return TRUE and http://www.bbcbb.com should return FALSE etc.</p>
<blockquote><p>The process behind TDD is that you first write a failing test. Then you write the actual code and adjust until the test passes.</p></blockquote>
<p>So let&#8217;s write some tests for our domain checker. I&#8217;m using Python and Unittest here:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">unittest</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># this is what we're going to be testing</span>
<span style="color: #ff7700;font-weight:bold;">class</span> Utils<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> is_bbc<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, val<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">pass</span> <span style="color: #808080; font-style: italic;">#placeholder</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># this is the actual test</span>
<span style="color: #ff7700;font-weight:bold;">class</span> TestUtils<span style="color: black;">&#40;</span><span style="color: #dc143c;">unittest</span>.<span style="color: black;">TestCase</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> setUp<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">u</span> = Utils<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> test_is_bbc<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">assertTrue</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">u</span>.<span style="color: black;">is_bbc</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'http://www.bbc.co.uk/iplayer'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">assertTrue</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">u</span>.<span style="color: black;">is_bbc</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'http://www.bbc.co.uk/food'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">assertTrue</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">u</span>.<span style="color: black;">is_bbc</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'http://www.bbc.co.uk'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">assertTrue</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">u</span>.<span style="color: black;">is_bbc</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'https://www.bbc.co.uk'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">assertTrue</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">u</span>.<span style="color: black;">is_bbc</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'http://beta.bbc.co.uk'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">assertFalse</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">u</span>.<span style="color: black;">is_bbc</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'http://www.bbc.com'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">assertFalse</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">u</span>.<span style="color: black;">is_bbc</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'http://www.bbbc.co.uk'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">assertFalse</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">u</span>.<span style="color: black;">is_bbc</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'http://.bbc.co.uk'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
suite = <span style="color: #dc143c;">unittest</span>.<span style="color: black;">TestLoader</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">loadTestsFromTestCase</span><span style="color: black;">&#40;</span>TestUtils<span style="color: black;">&#41;</span>
<span style="color: #dc143c;">unittest</span>.<span style="color: black;">TextTestRunner</span><span style="color: black;">&#40;</span>verbosity=<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>.<span style="color: black;">run</span><span style="color: black;">&#40;</span>suite<span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>I&#8217;ve created a an empty method where our domain checker is going to live but as you can see it doesn&#8217;t do anything. The tests should immediately make sense. We pass a bunch of domain variations and we know which ones should pass or fail. Naturally, running the test right now will fail:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ python sample.py
test_is_bbc <span style="color: #7a0874; font-weight: bold;">&#40;</span>__main__.TestUtils<span style="color: #7a0874; font-weight: bold;">&#41;</span> ... FAIL
&nbsp;
======================================================================
FAIL: test_is_bbc <span style="color: #7a0874; font-weight: bold;">&#40;</span>__main__.TestUtils<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #660033;">----------------------------------------------------------------------</span>
Traceback <span style="color: #7a0874; font-weight: bold;">&#40;</span>most recent call <span style="color: #c20cb9; font-weight: bold;">last</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>:
  File <span style="color: #ff0000;">&quot;sample.py&quot;</span>, line <span style="color: #000000;">14</span>, <span style="color: #000000; font-weight: bold;">in</span> test_is_bbc
    self.assertTrue<span style="color: #7a0874; font-weight: bold;">&#40;</span>self.u.is_bbc<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'http://www.bbc.co.uk/iplayer'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
AssertionError
&nbsp;
<span style="color: #660033;">----------------------------------------------------------------------</span>
Ran <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #000000; font-weight: bold;">in</span> 0.000s
&nbsp;
FAILED <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">failures</span>=<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Now you can start writing the actual code and keep running the same tests until it passes:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">unittest</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># this is what we're going to be testing</span>
<span style="color: #ff7700;font-weight:bold;">class</span> Utils<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> is_bbc<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, val<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">match</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'^https?://([^/]+)?<span style="color: #000099; font-weight: bold;">\.</span>bbc<span style="color: #000099; font-weight: bold;">\.</span>co<span style="color: #000099; font-weight: bold;">\.</span>uk'</span>, val<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># this is the actual test</span>
<span style="color: #ff7700;font-weight:bold;">class</span> TestUtils<span style="color: black;">&#40;</span><span style="color: #dc143c;">unittest</span>.<span style="color: black;">TestCase</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> setUp<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">u</span> = Utils<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> test_is_bbc<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">assertTrue</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">u</span>.<span style="color: black;">is_bbc</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'http://www.bbc.co.uk/iplayer'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">assertTrue</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">u</span>.<span style="color: black;">is_bbc</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'http://www.bbc.co.uk/food'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">assertTrue</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">u</span>.<span style="color: black;">is_bbc</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'http://www.bbc.co.uk'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">assertTrue</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">u</span>.<span style="color: black;">is_bbc</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'https://www.bbc.co.uk'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">assertTrue</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">u</span>.<span style="color: black;">is_bbc</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'http://beta.bbc.co.uk'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">assertFalse</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">u</span>.<span style="color: black;">is_bbc</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'http://www.bbc.com'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">assertFalse</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">u</span>.<span style="color: black;">is_bbc</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'http://www.bbbc.co.uk'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">assertFalse</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">u</span>.<span style="color: black;">is_bbc</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'http://.bbc.co.uk'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#this should fail</span>
&nbsp;
suite = <span style="color: #dc143c;">unittest</span>.<span style="color: black;">TestLoader</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">loadTestsFromTestCase</span><span style="color: black;">&#40;</span>TestUtils<span style="color: black;">&#41;</span>
<span style="color: #dc143c;">unittest</span>.<span style="color: black;">TextTestRunner</span><span style="color: black;">&#40;</span>verbosity=<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>.<span style="color: black;">run</span><span style="color: black;">&#40;</span>suite<span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>The regex may look like it&#8217;s correct but running the test will fail again:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ python sample.py
test_is_bbc <span style="color: #7a0874; font-weight: bold;">&#40;</span>__main__.TestUtils<span style="color: #7a0874; font-weight: bold;">&#41;</span> ... FAIL
&nbsp;
======================================================================
FAIL: test_is_bbc <span style="color: #7a0874; font-weight: bold;">&#40;</span>__main__.TestUtils<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #660033;">----------------------------------------------------------------------</span>
Traceback <span style="color: #7a0874; font-weight: bold;">&#40;</span>most recent call <span style="color: #c20cb9; font-weight: bold;">last</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>:
  File <span style="color: #ff0000;">&quot;sample.py&quot;</span>, line <span style="color: #000000;">22</span>, <span style="color: #000000; font-weight: bold;">in</span> test_is_bbc
    self.assertFalse<span style="color: #7a0874; font-weight: bold;">&#40;</span>self.u.is_bbc<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'http://.bbc.co.uk'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
AssertionError
&nbsp;
<span style="color: #660033;">----------------------------------------------------------------------</span>
Ran <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #000000; font-weight: bold;">in</span> 0.001s
&nbsp;
FAILED <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">failures</span>=<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>It has failed on the final assert because our code will also allow http://.bbc.co.uk and we obviously don&#8217;t want that. But as you can see we&#8217;ve caught this edge case before deploying our app so we can promptly fix our code.</p>
<p>Hopefully this example demonstrates why it&#8217;s a good idea to start with tests. This is obviously a simple example but on bigger projects predicting the outcome of your system can save you a lot of debugging time in the future.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  href="http://twitter.com/home?status=Test-Driven%20Development%20-%20How%20Do%20I%20Start%3F%20-%20http%3A%2F%2Fwww.givp.org%2Fblog%2F2010%2F07%2F22%2Ftest-driven-development-how-do-i-start%2F" title="Twitter" onclick="pageTracker._trackPageview('/outgoing/twitter.com/home?status=Test-Driven_20Development_20-_20How_20Do_20I_20Start_3F_20-_20http_3A_2F_2Fwww.givp.org_2Fblog_2F2010_2F07_2F22_2Ftest-driven-development-how-do-i-start_2F&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.givp.org%2Fblog%2F2010%2F07%2F22%2Ftest-driven-development-how-do-i-start%2F&amp;t=Test-Driven%20Development%20-%20How%20Do%20I%20Start%3F" title="Facebook" onclick="pageTracker._trackPageview('/outgoing/www.facebook.com/share.php?u=http_3A_2F_2Fwww.givp.org_2Fblog_2F2010_2F07_2F22_2Ftest-driven-development-how-do-i-start_2F_amp_t=Test-Driven_20Development_20-_20How_20Do_20I_20Start_3F&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.givp.org%2Fblog%2F2010%2F07%2F22%2Ftest-driven-development-how-do-i-start%2F&amp;title=Test-Driven%20Development%20-%20How%20Do%20I%20Start%3F&amp;bodytext=There%20seem%20to%20be%20a%20lot%20of%20developers%20who%20like%20the%20idea%20of%20Test-Driven%20Development%20%28TDD%29%20and%20can%20clearly%20see%20the%20benefit%20of%20having%20tests%20written%20for%20their%20code%20but%20can%27t%20seem%20to%20get%20their%20head%20around%20the%20process.%20How%20do%20you%20start%20writing%20unit%20tests%20be" title="Digg" onclick="pageTracker._trackPageview('/outgoing/digg.com/submit?phase=2_amp_url=http_3A_2F_2Fwww.givp.org_2Fblog_2F2010_2F07_2F22_2Ftest-driven-development-how-do-i-start_2F_amp_title=Test-Driven_20Development_20-_20How_20Do_20I_20Start_3F_amp_bodytext=There_20seem_20to_20be_20a_20lot_20of_20developers_20who_20like_20the_20idea_20of_20Test-Driven_20Development_20_28TDD_29_20and_20can_20clearly_20see_20the_20benefit_20of_20having_20tests_20written_20for_20their_20code_20but_20can_27t_20seem_20to_20get_20their_20head_20around_20the_20process._20How_20do_20you_20start_20writing_20unit_20tests_20be&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fwww.givp.org%2Fblog%2F2010%2F07%2F22%2Ftest-driven-development-how-do-i-start%2F&amp;title=Test-Driven%20Development%20-%20How%20Do%20I%20Start%3F&amp;notes=There%20seem%20to%20be%20a%20lot%20of%20developers%20who%20like%20the%20idea%20of%20Test-Driven%20Development%20%28TDD%29%20and%20can%20clearly%20see%20the%20benefit%20of%20having%20tests%20written%20for%20their%20code%20but%20can%27t%20seem%20to%20get%20their%20head%20around%20the%20process.%20How%20do%20you%20start%20writing%20unit%20tests%20be" title="del.icio.us" onclick="pageTracker._trackPageview('/outgoing/delicious.com/post?url=http_3A_2F_2Fwww.givp.org_2Fblog_2F2010_2F07_2F22_2Ftest-driven-development-how-do-i-start_2F_amp_title=Test-Driven_20Development_20-_20How_20Do_20I_20Start_3F_amp_notes=There_20seem_20to_20be_20a_20lot_20of_20developers_20who_20like_20the_20idea_20of_20Test-Driven_20Development_20_28TDD_29_20and_20can_20clearly_20see_20the_20benefit_20of_20having_20tests_20written_20for_20their_20code_20but_20can_27t_20seem_20to_20get_20their_20head_20around_20the_20process._20How_20do_20you_20start_20writing_20unit_20tests_20be&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.givp.org%2Fblog%2F2010%2F07%2F22%2Ftest-driven-development-how-do-i-start%2F&amp;title=Test-Driven%20Development%20-%20How%20Do%20I%20Start%3F&amp;annotation=There%20seem%20to%20be%20a%20lot%20of%20developers%20who%20like%20the%20idea%20of%20Test-Driven%20Development%20%28TDD%29%20and%20can%20clearly%20see%20the%20benefit%20of%20having%20tests%20written%20for%20their%20code%20but%20can%27t%20seem%20to%20get%20their%20head%20around%20the%20process.%20How%20do%20you%20start%20writing%20unit%20tests%20be" title="Google Bookmarks" onclick="pageTracker._trackPageview('/outgoing/www.google.com/bookmarks/mark?op=edit_amp_bkmk=http_3A_2F_2Fwww.givp.org_2Fblog_2F2010_2F07_2F22_2Ftest-driven-development-how-do-i-start_2F_amp_title=Test-Driven_20Development_20-_20How_20Do_20I_20Start_3F_amp_annotation=There_20seem_20to_20be_20a_20lot_20of_20developers_20who_20like_20the_20idea_20of_20Test-Driven_20Development_20_28TDD_29_20and_20can_20clearly_20see_20the_20benefit_20of_20having_20tests_20written_20for_20their_20code_20but_20can_27t_20seem_20to_20get_20their_20head_20around_20the_20process._20How_20do_20you_20start_20writing_20unit_20tests_20be&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.givp.org/blog/2010/07/22/test-driven-development-how-do-i-start/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Saving data with Titanium mobile</title>
		<link>http://www.givp.org/blog/2010/07/15/saving-data-with-titanium-mobile/</link>
		<comments>http://www.givp.org/blog/2010/07/15/saving-data-with-titanium-mobile/#comments</comments>
		<pubDate>Thu, 15 Jul 2010 20:15:29 +0000</pubDate>
		<dc:creator>Giv</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[appcelerator]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[titanium]]></category>

		<guid isPermaLink="false">http://www.givp.org/blog/?p=181</guid>
		<description><![CDATA[In my previous post I talked about getting a simple table view up and running quickly using Titanium. A few people have asked me to continue the tutorial and explain how to save individual items and then display saved items in a separate window. Saving data is quite simple. You first need to create the [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.givp.org/blog/2010/07/13/building-mobile-app-with-titanium/">my previous post</a> I talked about getting a simple table view up and running quickly using Titanium. A few people have asked me to continue the tutorial and explain how to save individual items and then display saved items in a separate window.</p>
<p>Saving data is quite simple. You first need to create the database and schema. You obviously only need to do this the first time the user opens your app. So in your app.js file you can do something like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> db <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">Database</span>.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mydb'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
db.<span style="color: #660066;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'CREATE TABLE IF NOT EXISTS SAVEDITEMS  (NAME TEXT)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This should look very familiar to you if you&#8217;re used to SQL. It first instantiates a database object then checks to see if the &#8220;SAVEDITEMS&#8221; table exists. If not, it will simply create it. If it does exist, it will just ignore that command. This will create a table with a single text field for storing the name of a selected item.</p>
<p>Now that we have our table set up, we can read and write to it whenever we like. If you wanted to save an item, you would do this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">db.<span style="color: #660066;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;INSERT INTO SAVEDITEMS ( NAME ) VALUES ('my cool item')&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>To get a list of all items in the database:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> rows <span style="color: #339933;">=</span> db.<span style="color: #660066;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;SELECT * FROM SAVEDITEMS&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
rows.<span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The last line is very important. You must close your query results to avoid memory leakage.</p>
<p>You can now loop through the saved items and stick them in a table view:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// create blank table view</span>
<span style="color: #003366; font-weight: bold;">var</span> tableview <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createTableView</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">currentWindow</span>.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>tableview<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// create an empty array</span>
<span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// get a list of all saved items</span>
<span style="color: #003366; font-weight: bold;">var</span> rows <span style="color: #339933;">=</span> db.<span style="color: #660066;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'SELECT * FROM SAVEDITEMS'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// loop through all items</span>
<span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>rows.<span style="color: #660066;">isValidRow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #006600; font-style: italic;">// add each item to the data array and set the table row title</span>
   data.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>title<span style="color: #339933;">:</span>rows.<span style="color: #660066;">field</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>hasChild<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   rows.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// load db data into the table view</span>
tableview.<span style="color: #660066;">setData</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
rows.<span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>That should help you get started. You can look at how to use events to save items and also check to see which items have already been saved so you don&#8217;t show the save button etc. Take a look at the <a href="http://github.com/givp/Titanium-Mobile-Reference-Directory-App" onclick="pageTracker._trackPageview('/outgoing/github.com/givp/Titanium-Mobile-Reference-Directory-App?referer=');">demo app</a> I&#8217;ve created to see how I handled the saving logic. Specifically the <a href="http://github.com/givp/Titanium-Mobile-Reference-Directory-App/blob/master/details.js" onclick="pageTracker._trackPageview('/outgoing/github.com/givp/Titanium-Mobile-Reference-Directory-App/blob/master/details.js?referer=');">details.js</a> file.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  href="http://twitter.com/home?status=Saving%20data%20with%20Titanium%20mobile%20-%20http%3A%2F%2Fwww.givp.org%2Fblog%2F2010%2F07%2F15%2Fsaving-data-with-titanium-mobile%2F" title="Twitter" onclick="pageTracker._trackPageview('/outgoing/twitter.com/home?status=Saving_20data_20with_20Titanium_20mobile_20-_20http_3A_2F_2Fwww.givp.org_2Fblog_2F2010_2F07_2F15_2Fsaving-data-with-titanium-mobile_2F&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.givp.org%2Fblog%2F2010%2F07%2F15%2Fsaving-data-with-titanium-mobile%2F&amp;t=Saving%20data%20with%20Titanium%20mobile" title="Facebook" onclick="pageTracker._trackPageview('/outgoing/www.facebook.com/share.php?u=http_3A_2F_2Fwww.givp.org_2Fblog_2F2010_2F07_2F15_2Fsaving-data-with-titanium-mobile_2F_amp_t=Saving_20data_20with_20Titanium_20mobile&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.givp.org%2Fblog%2F2010%2F07%2F15%2Fsaving-data-with-titanium-mobile%2F&amp;title=Saving%20data%20with%20Titanium%20mobile&amp;bodytext=In%20my%20previous%20post%20I%20talked%20about%20getting%20a%20simple%20table%20view%20up%20and%20running%20quickly%20using%20Titanium.%20A%20few%20people%20have%20asked%20me%20to%20continue%20the%20tutorial%20and%20explain%20how%20to%20save%20individual%20items%20and%20then%20display%20saved%20items%20in%20a%20separate%20window.%0A%0ASav" title="Digg" onclick="pageTracker._trackPageview('/outgoing/digg.com/submit?phase=2_amp_url=http_3A_2F_2Fwww.givp.org_2Fblog_2F2010_2F07_2F15_2Fsaving-data-with-titanium-mobile_2F_amp_title=Saving_20data_20with_20Titanium_20mobile_amp_bodytext=In_20my_20previous_20post_20I_20talked_20about_20getting_20a_20simple_20table_20view_20up_20and_20running_20quickly_20using_20Titanium._20A_20few_20people_20have_20asked_20me_20to_20continue_20the_20tutorial_20and_20explain_20how_20to_20save_20individual_20items_20and_20then_20display_20saved_20items_20in_20a_20separate_20window._0A_0ASav&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fwww.givp.org%2Fblog%2F2010%2F07%2F15%2Fsaving-data-with-titanium-mobile%2F&amp;title=Saving%20data%20with%20Titanium%20mobile&amp;notes=In%20my%20previous%20post%20I%20talked%20about%20getting%20a%20simple%20table%20view%20up%20and%20running%20quickly%20using%20Titanium.%20A%20few%20people%20have%20asked%20me%20to%20continue%20the%20tutorial%20and%20explain%20how%20to%20save%20individual%20items%20and%20then%20display%20saved%20items%20in%20a%20separate%20window.%0A%0ASav" title="del.icio.us" onclick="pageTracker._trackPageview('/outgoing/delicious.com/post?url=http_3A_2F_2Fwww.givp.org_2Fblog_2F2010_2F07_2F15_2Fsaving-data-with-titanium-mobile_2F_amp_title=Saving_20data_20with_20Titanium_20mobile_amp_notes=In_20my_20previous_20post_20I_20talked_20about_20getting_20a_20simple_20table_20view_20up_20and_20running_20quickly_20using_20Titanium._20A_20few_20people_20have_20asked_20me_20to_20continue_20the_20tutorial_20and_20explain_20how_20to_20save_20individual_20items_20and_20then_20display_20saved_20items_20in_20a_20separate_20window._0A_0ASav&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.givp.org%2Fblog%2F2010%2F07%2F15%2Fsaving-data-with-titanium-mobile%2F&amp;title=Saving%20data%20with%20Titanium%20mobile&amp;annotation=In%20my%20previous%20post%20I%20talked%20about%20getting%20a%20simple%20table%20view%20up%20and%20running%20quickly%20using%20Titanium.%20A%20few%20people%20have%20asked%20me%20to%20continue%20the%20tutorial%20and%20explain%20how%20to%20save%20individual%20items%20and%20then%20display%20saved%20items%20in%20a%20separate%20window.%0A%0ASav" title="Google Bookmarks" onclick="pageTracker._trackPageview('/outgoing/www.google.com/bookmarks/mark?op=edit_amp_bkmk=http_3A_2F_2Fwww.givp.org_2Fblog_2F2010_2F07_2F15_2Fsaving-data-with-titanium-mobile_2F_amp_title=Saving_20data_20with_20Titanium_20mobile_amp_annotation=In_20my_20previous_20post_20I_20talked_20about_20getting_20a_20simple_20table_20view_20up_20and_20running_20quickly_20using_20Titanium._20A_20few_20people_20have_20asked_20me_20to_20continue_20the_20tutorial_20and_20explain_20how_20to_20save_20individual_20items_20and_20then_20display_20saved_20items_20in_20a_20separate_20window._0A_0ASav&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.givp.org/blog/2010/07/15/saving-data-with-titanium-mobile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a native mobile app with Titanium in less than an hour</title>
		<link>http://www.givp.org/blog/2010/07/13/building-mobile-app-with-titanium/</link>
		<comments>http://www.givp.org/blog/2010/07/13/building-mobile-app-with-titanium/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 12:03:46 +0000</pubDate>
		<dc:creator>Giv</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[appcelerator]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[Objective-c]]></category>
		<category><![CDATA[titanium]]></category>

		<guid isPermaLink="false">http://www.givp.org/blog/?p=164</guid>
		<description><![CDATA[When I wrote my last blog entry, I favoured objective-c over Appcelerator&#8217;s Titanium framework thinking it just wasn&#8217;t good enough. Almost 6 months later and I would like to take back that comment. Titanium is no longer an embedded web browser inside an app. It uses Javascript to compile an entire iPhone/Xcode project with objective-c, [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://givp.mugal.org/blog/wp-content/uploads/2010/07/animalApp.jpg" alt="" title="animalApp" width="595" height="376" class="alignleft size-full wp-image-166" /><br />
<br />
When I wrote my last blog entry, I favoured objective-c over <a href="http://www.appcelerator.com/" onclick="pageTracker._trackPageview('/outgoing/www.appcelerator.com/?referer=');">Appcelerator&#8217;s Titanium framework</a> thinking it just wasn&#8217;t good enough. Almost 6 months later and I would like to take back that comment. Titanium is no longer an embedded web browser inside an app. It uses Javascript to compile an entire iPhone/Xcode project with objective-c, so it uses native UI elements using clever APIs. This is also true for Android apps, iPad and now Blackberry.</p>
<p>This is not to say there&#8217;s no need to use Xcode ever again. But if you&#8217;re planning to build a general navigation-based app with loads of menus, windows and the ability to pull/push data from the web, it can be done much faster with Titanium. Plus you&#8217;ll be able to create the same app for multiple platforms without re-writing the code.</p>
<p>So I wanted to put together a relatively simple app that lets me browse and search through a list of items, in this example, animals; and be able to group them alphabetically like the iPhone&#8217;s contacts directory. Then I want to click on an item to see more details and be able to save my favourite items for easy access later.</p>
<p>I&#8217;ve created a sample app that you can <a href="http://github.com/givp/Titanium-Mobile-Reference-Directory-App" onclick="pageTracker._trackPageview('/outgoing/github.com/givp/Titanium-Mobile-Reference-Directory-App?referer=');">download</a> and use right now. All you have to do is add your own data and you&#8217;re done.</p>
<p>I&#8217;m going to quickly run you through how to set up the tabs, the list, alphabetical grouping, search and detail view for each item. I won&#8217;t explain the saving feature here but once you do the main part below you should be able to easily follow the rest by looking at <a href="http://github.com/givp/Titanium-Mobile-Reference-Directory-App" onclick="pageTracker._trackPageview('/outgoing/github.com/givp/Titanium-Mobile-Reference-Directory-App?referer=');">the code</a>.</p>
<p>Here&#8217;s how it works. See the sample app to work out where to place individual files.</p>
<p>1. Create a tab group. One for the main list and one tab for saved items:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// create tab group</span>
<span style="color: #003366; font-weight: bold;">var</span> tabGroup <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createTabGroup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// create base UI tab and root window</span>
<span style="color: #003366; font-weight: bold;">var</span> mainList <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createWindow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    title<span style="color: #339933;">:</span><span style="color: #3366CC;">'Animals'</span><span style="color: #339933;">,</span>
    backgroundColor<span style="color: #339933;">:</span><span style="color: #3366CC;">'#ffffff'</span><span style="color: #339933;">,</span>
    barColor<span style="color: #339933;">:</span><span style="color: #3366CC;">'#333'</span><span style="color: #339933;">,</span>
    url<span style="color: #339933;">:</span><span style="color: #3366CC;">'mainList.js'</span><span style="color: #339933;">,</span>
    tabBarHidden<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> tabMainList <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createTab</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    icon<span style="color: #339933;">:</span><span style="color: #3366CC;">'book.png'</span><span style="color: #339933;">,</span>
    title<span style="color: #339933;">:</span><span style="color: #3366CC;">'Animals'</span><span style="color: #339933;">,</span>
    window<span style="color: #339933;">:</span>mainList
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// create saved items tab</span>
<span style="color: #003366; font-weight: bold;">var</span> faves <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createWindow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    title<span style="color: #339933;">:</span><span style="color: #3366CC;">'Saved Items'</span><span style="color: #339933;">,</span>
    backgroundColor<span style="color: #339933;">:</span><span style="color: #3366CC;">'#ffffff'</span><span style="color: #339933;">,</span>
    barColor<span style="color: #339933;">:</span><span style="color: #3366CC;">'#333'</span><span style="color: #339933;">,</span>
    url<span style="color: #339933;">:</span><span style="color: #3366CC;">'faves.js'</span><span style="color: #339933;">,</span>
    tabBarHidden<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> tabFaves <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createTab</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    icon<span style="color: #339933;">:</span><span style="color: #3366CC;">'star.png'</span><span style="color: #339933;">,</span>
    title<span style="color: #339933;">:</span><span style="color: #3366CC;">'Saved Items'</span><span style="color: #339933;">,</span>
    window<span style="color: #339933;">:</span>faves
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//  add tabs</span>
tabGroup.<span style="color: #660066;">addTab</span><span style="color: #009900;">&#40;</span>tabMainList<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
tabGroup.<span style="color: #660066;">addTab</span><span style="color: #009900;">&#40;</span>tabFaves<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
tabGroup.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span>tabMainList<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">currentWindow</span>.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>tabGroup<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>That&#8217;s it. We have now created two tabs. mainList.js will take care of the content for the first tab and faves.js for the saved items tab.</p>
<p>2. Create a JSON doc (data.js) containing your data for the list:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myData <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>
    <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;title&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Armadillo&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;description&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Armadillos eat ants but they are not Anteaters&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;title&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Bear&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;description&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Bears are awesome and they like honey&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;title&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Dog&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;description&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Dogs are the best and they woof&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;title&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Deer&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;description&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;D'oh! a deer...&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;title&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Zebra&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;description&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Zebras are stripey and cool&quot;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>3. Set up your directory list in the first tab (mainList.js)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// include the data</span>
Titanium.<span style="color: #660066;">include</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'data.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> firstLetter<span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> oldFirstLetter<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// loop through data and add to list</span>
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> myData.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">// get first letter of each item for grouping</span>
	firstLetter <span style="color: #339933;">=</span> myData<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">title</span>.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>i <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	    oldFirstLetter <span style="color: #339933;">=</span> firstLetter<span style="color: #339933;">;</span>
	    Ti.<span style="color: #660066;">API</span>.<span style="color: #660066;">info</span><span style="color: #009900;">&#40;</span>oldFirstLetter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
	    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>firstLetter <span style="color: #339933;">==</span> oldFirstLetter<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    	        oldFirstLetter <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    	    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    	        oldFirstLetter <span style="color: #339933;">=</span> firstLetter<span style="color: #339933;">;</span>
    	    <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        data.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>title<span style="color: #339933;">:</span>myData<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">title</span><span style="color: #339933;">,</span>hasChild<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>header<span style="color: #339933;">:</span>oldFirstLetter<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        oldFirstLetter <span style="color: #339933;">=</span> firstLetter<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// add search bar</span>
<span style="color: #003366; font-weight: bold;">var</span> search <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createSearchBar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	showCancel<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">false</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// create table view</span>
<span style="color: #003366; font-weight: bold;">var</span> tableview <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createTableView</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    data<span style="color: #339933;">:</span>data<span style="color: #339933;">,</span>
    search<span style="color: #339933;">:</span>search<span style="color: #339933;">,</span>
    filterAttribute<span style="color: #339933;">:</span><span style="color: #3366CC;">'title'</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">currentWindow</span>.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>tableview<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// create table view event listener</span>
tableview.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> win <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createWindow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		url<span style="color: #339933;">:</span><span style="color: #3366CC;">'details.js'</span><span style="color: #339933;">,</span>
		backgroundColor<span style="color: #339933;">:</span><span style="color: #3366CC;">'#ffffff'</span><span style="color: #339933;">,</span>
                barColor<span style="color: #339933;">:</span><span style="color: #3366CC;">'#333333'</span><span style="color: #339933;">,</span>
		title<span style="color: #339933;">:</span>e.<span style="color: #660066;">rowData</span>.<span style="color: #660066;">title</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// send selected item's title to detail page</span>
	win.<span style="color: #660066;">currentItem</span> <span style="color: #339933;">=</span> e.<span style="color: #660066;">rowData</span>.<span style="color: #660066;">title</span><span style="color: #339933;">;</span>
&nbsp;
	Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">currentTab</span>.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span>win<span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>animated<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Notice in the tableview event listener we are telling it to just open a new window on click and pass the item&#8217;s title.</p>
<p>4. Display the selected item&#8217;s data in details.js</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// include the data</span>
Titanium.<span style="color: #660066;">include</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'data.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
win <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">currentWindow</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> desc <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// create scroll view for the content</span>
<span style="color: #003366; font-weight: bold;">var</span> scrollView <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createScrollView</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	contentWidth<span style="color: #339933;">:</span><span style="color: #3366CC;">'auto'</span><span style="color: #339933;">,</span>
	contentHeight<span style="color: #339933;">:</span><span style="color: #3366CC;">'auto'</span><span style="color: #339933;">,</span>
	top<span style="color: #339933;">:</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
	showVerticalScrollIndicator<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
	showHorizontalScrollIndicator<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">false</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #006600; font-style: italic;">// loop through data and get correct item by title (this is easier than using Id's incase you add new items later)</span>
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> myData.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>myData<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">title</span> <span style="color: #339933;">==</span> win.<span style="color: #660066;">currentItem</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        desc <span style="color: #339933;">=</span> myData<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">description</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// create description label</span>
<span style="color: #003366; font-weight: bold;">var</span> label <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createLabel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	text<span style="color: #339933;">:</span>desc<span style="color: #339933;">,</span>
	height<span style="color: #339933;">:</span><span style="color: #3366CC;">'auto'</span><span style="color: #339933;">,</span>
	width<span style="color: #339933;">:</span><span style="color: #CC0000;">300</span><span style="color: #339933;">,</span>
	top<span style="color: #339933;">:</span><span style="color: #CC0000;">10</span><span style="color: #339933;">,</span>
	font<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>fontSize<span style="color: #339933;">:</span><span style="color: #CC0000;">16</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	color<span style="color: #339933;">:</span><span style="color: #3366CC;">'#333333'</span><span style="color: #339933;">,</span>
	textAlign<span style="color: #339933;">:</span><span style="color: #3366CC;">'left'</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>That&#8217;s it. I said an hour to develop this but in reality it will probably take you much less once you get used to the APIs. Of course for the data source you can use XHR to get data from the web but if you want your app to be usable without an internet connection, you would have to store the data locally like this.</p>
<p>I hope this was helpful. Let me know if you have any questions.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  href="http://twitter.com/home?status=Building%20a%20native%20mobile%20app%20with%20Titanium%20in%20less%20than%20an%20hour%20-%20http%3A%2F%2Fwww.givp.org%2Fblog%2F2010%2F07%2F13%2Fbuilding-mobile-app-with-titanium%2F" title="Twitter" onclick="pageTracker._trackPageview('/outgoing/twitter.com/home?status=Building_20a_20native_20mobile_20app_20with_20Titanium_20in_20less_20than_20an_20hour_20-_20http_3A_2F_2Fwww.givp.org_2Fblog_2F2010_2F07_2F13_2Fbuilding-mobile-app-with-titanium_2F&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.givp.org%2Fblog%2F2010%2F07%2F13%2Fbuilding-mobile-app-with-titanium%2F&amp;t=Building%20a%20native%20mobile%20app%20with%20Titanium%20in%20less%20than%20an%20hour" title="Facebook" onclick="pageTracker._trackPageview('/outgoing/www.facebook.com/share.php?u=http_3A_2F_2Fwww.givp.org_2Fblog_2F2010_2F07_2F13_2Fbuilding-mobile-app-with-titanium_2F_amp_t=Building_20a_20native_20mobile_20app_20with_20Titanium_20in_20less_20than_20an_20hour&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.givp.org%2Fblog%2F2010%2F07%2F13%2Fbuilding-mobile-app-with-titanium%2F&amp;title=Building%20a%20native%20mobile%20app%20with%20Titanium%20in%20less%20than%20an%20hour&amp;bodytext=%0A%0AWhen%20I%20wrote%20my%20last%20blog%20entry%2C%20I%20favoured%20objective-c%20over%20Appcelerator%27s%20Titanium%20framework%20thinking%20it%20just%20wasn%27t%20good%20enough.%20Almost%206%20months%20later%20and%20I%20would%20like%20to%20take%20back%20that%20comment.%20Titanium%20is%20no%20longer%20an%20embedded%20web%20browser%20insi" title="Digg" onclick="pageTracker._trackPageview('/outgoing/digg.com/submit?phase=2_amp_url=http_3A_2F_2Fwww.givp.org_2Fblog_2F2010_2F07_2F13_2Fbuilding-mobile-app-with-titanium_2F_amp_title=Building_20a_20native_20mobile_20app_20with_20Titanium_20in_20less_20than_20an_20hour_amp_bodytext=_0A_0AWhen_20I_20wrote_20my_20last_20blog_20entry_2C_20I_20favoured_20objective-c_20over_20Appcelerator_27s_20Titanium_20framework_20thinking_20it_20just_20wasn_27t_20good_20enough._20Almost_206_20months_20later_20and_20I_20would_20like_20to_20take_20back_20that_20comment._20Titanium_20is_20no_20longer_20an_20embedded_20web_20browser_20insi&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fwww.givp.org%2Fblog%2F2010%2F07%2F13%2Fbuilding-mobile-app-with-titanium%2F&amp;title=Building%20a%20native%20mobile%20app%20with%20Titanium%20in%20less%20than%20an%20hour&amp;notes=%0A%0AWhen%20I%20wrote%20my%20last%20blog%20entry%2C%20I%20favoured%20objective-c%20over%20Appcelerator%27s%20Titanium%20framework%20thinking%20it%20just%20wasn%27t%20good%20enough.%20Almost%206%20months%20later%20and%20I%20would%20like%20to%20take%20back%20that%20comment.%20Titanium%20is%20no%20longer%20an%20embedded%20web%20browser%20insi" title="del.icio.us" onclick="pageTracker._trackPageview('/outgoing/delicious.com/post?url=http_3A_2F_2Fwww.givp.org_2Fblog_2F2010_2F07_2F13_2Fbuilding-mobile-app-with-titanium_2F_amp_title=Building_20a_20native_20mobile_20app_20with_20Titanium_20in_20less_20than_20an_20hour_amp_notes=_0A_0AWhen_20I_20wrote_20my_20last_20blog_20entry_2C_20I_20favoured_20objective-c_20over_20Appcelerator_27s_20Titanium_20framework_20thinking_20it_20just_20wasn_27t_20good_20enough._20Almost_206_20months_20later_20and_20I_20would_20like_20to_20take_20back_20that_20comment._20Titanium_20is_20no_20longer_20an_20embedded_20web_20browser_20insi&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.givp.org%2Fblog%2F2010%2F07%2F13%2Fbuilding-mobile-app-with-titanium%2F&amp;title=Building%20a%20native%20mobile%20app%20with%20Titanium%20in%20less%20than%20an%20hour&amp;annotation=%0A%0AWhen%20I%20wrote%20my%20last%20blog%20entry%2C%20I%20favoured%20objective-c%20over%20Appcelerator%27s%20Titanium%20framework%20thinking%20it%20just%20wasn%27t%20good%20enough.%20Almost%206%20months%20later%20and%20I%20would%20like%20to%20take%20back%20that%20comment.%20Titanium%20is%20no%20longer%20an%20embedded%20web%20browser%20insi" title="Google Bookmarks" onclick="pageTracker._trackPageview('/outgoing/www.google.com/bookmarks/mark?op=edit_amp_bkmk=http_3A_2F_2Fwww.givp.org_2Fblog_2F2010_2F07_2F13_2Fbuilding-mobile-app-with-titanium_2F_amp_title=Building_20a_20native_20mobile_20app_20with_20Titanium_20in_20less_20than_20an_20hour_amp_annotation=_0A_0AWhen_20I_20wrote_20my_20last_20blog_20entry_2C_20I_20favoured_20objective-c_20over_20Appcelerator_27s_20Titanium_20framework_20thinking_20it_20just_20wasn_27t_20good_20enough._20Almost_206_20months_20later_20and_20I_20would_20like_20to_20take_20back_20that_20comment._20Titanium_20is_20no_20longer_20an_20embedded_20web_20browser_20insi&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.givp.org/blog/2010/07/13/building-mobile-app-with-titanium/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Django Gravatar filter</title>
		<link>http://www.givp.org/blog/2009/12/13/django-gravatar-filter/</link>
		<comments>http://www.givp.org/blog/2009/12/13/django-gravatar-filter/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 22:04:37 +0000</pubDate>
		<dc:creator>Giv</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://www.givp.org/blog/?p=120</guid>
		<description><![CDATA[If you want to add user avatars to your Django app, you can certainly use the excellent django-avatar app. This will let your users upload/edit their own avatars or use Gravatar. But for my app I only wanted to use Gravatar so I was looking for a simpler solution that let me just pass the [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to add user avatars to your Django app, you can certainly use the excellent <a href="http://github.com/ericflo/django-avatar" onclick="pageTracker._trackPageview('/outgoing/github.com/ericflo/django-avatar?referer=');">django-avatar</a> app. This will let your users upload/edit their own avatars or use <a href="http://www.gravatar.com/" onclick="pageTracker._trackPageview('/outgoing/www.gravatar.com/?referer=');">Gravatar</a>.</p>
<p>But for my app I <u>only</u> wanted to use Gravatar so I was looking for a simpler solution that let me just pass the user object and an optional size in a template filter and have Gravatar take care of the rest.</p>
<p>The solution is <a href="http://docs.djangoproject.com/en/dev/howto/custom-template-tags/" onclick="pageTracker._trackPageview('/outgoing/docs.djangoproject.com/en/dev/howto/custom-template-tags/?referer=');">custom template tags</a>. If you&#8217;re already used to using the built-in template filters, you&#8217;ll know how useful and easy they are. I wanted my Gravatar filter to be as simple as possible. Something like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: black;">&#123;</span><span style="color: black;">&#123;</span> <span style="color: #dc143c;">user</span>|gravatar:<span style="color: #ff4500;">20</span> <span style="color: black;">&#125;</span><span style="color: black;">&#125;</span></pre></td></tr></table></div>

<p>Where 20 is the optional width/height of the avatar. This would then create an img tag with the full Gravatar URL.</p>
<p>First create your &#8216;templatetags&#8217; directory and associated files as instructed in the <a href="http://docs.djangoproject.com/en/dev/howto/custom-template-tags/" onclick="pageTracker._trackPageview('/outgoing/docs.djangoproject.com/en/dev/howto/custom-template-tags/?referer=');">docs</a>. Then create a function that takes in the user object and uses the email address to construct the Gravatar URL:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> django <span style="color: #ff7700;font-weight:bold;">import</span> template
<span style="color: #ff7700;font-weight:bold;">import</span> hashlib
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">utils</span>.<span style="color: black;">safestring</span> <span style="color: #ff7700;font-weight:bold;">import</span> mark_safe
register = template.<span style="color: black;">Library</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
@register.<span style="color: #008000;">filter</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> gravatar<span style="color: black;">&#40;</span><span style="color: #dc143c;">user</span>, size=<span style="color: #ff4500;">50</span><span style="color: black;">&#41;</span>:
    gravatar_url = <span style="color: #483d8b;">&quot;http://www.gravatar.com/avatar&quot;</span>
    emailHash = hashlib.<span style="color: #dc143c;">md5</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">user</span>.<span style="color: #dc143c;">email</span>.<span style="color: black;">lower</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>.<span style="color: black;">hexdigest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> mark_safe<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;img src='%s/%s.jpg?d=identicon&amp;s=%s' alt='' /&gt;&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>gravatar_url, emailHash, size<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>


<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  href="http://twitter.com/home?status=Django%20Gravatar%20filter%20-%20http%3A%2F%2Fwww.givp.org%2Fblog%2F2009%2F12%2F13%2Fdjango-gravatar-filter%2F" title="Twitter" onclick="pageTracker._trackPageview('/outgoing/twitter.com/home?status=Django_20Gravatar_20filter_20-_20http_3A_2F_2Fwww.givp.org_2Fblog_2F2009_2F12_2F13_2Fdjango-gravatar-filter_2F&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.givp.org%2Fblog%2F2009%2F12%2F13%2Fdjango-gravatar-filter%2F&amp;t=Django%20Gravatar%20filter" title="Facebook" onclick="pageTracker._trackPageview('/outgoing/www.facebook.com/share.php?u=http_3A_2F_2Fwww.givp.org_2Fblog_2F2009_2F12_2F13_2Fdjango-gravatar-filter_2F_amp_t=Django_20Gravatar_20filter&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.givp.org%2Fblog%2F2009%2F12%2F13%2Fdjango-gravatar-filter%2F&amp;title=Django%20Gravatar%20filter&amp;bodytext=If%20you%20want%20to%20add%20user%20avatars%20to%20your%20Django%20app%2C%20you%20can%20certainly%20use%20the%20excellent%20django-avatar%20app.%20This%20will%20let%20your%20users%20upload%2Fedit%20their%20own%20avatars%20or%20use%20Gravatar.%0A%0ABut%20for%20my%20app%20I%20only%20wanted%20to%20use%20Gravatar%20so%20I%20was%20looking%20for%20a%20si" title="Digg" onclick="pageTracker._trackPageview('/outgoing/digg.com/submit?phase=2_amp_url=http_3A_2F_2Fwww.givp.org_2Fblog_2F2009_2F12_2F13_2Fdjango-gravatar-filter_2F_amp_title=Django_20Gravatar_20filter_amp_bodytext=If_20you_20want_20to_20add_20user_20avatars_20to_20your_20Django_20app_2C_20you_20can_20certainly_20use_20the_20excellent_20django-avatar_20app._20This_20will_20let_20your_20users_20upload_2Fedit_20their_20own_20avatars_20or_20use_20Gravatar._0A_0ABut_20for_20my_20app_20I_20only_20wanted_20to_20use_20Gravatar_20so_20I_20was_20looking_20for_20a_20si&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fwww.givp.org%2Fblog%2F2009%2F12%2F13%2Fdjango-gravatar-filter%2F&amp;title=Django%20Gravatar%20filter&amp;notes=If%20you%20want%20to%20add%20user%20avatars%20to%20your%20Django%20app%2C%20you%20can%20certainly%20use%20the%20excellent%20django-avatar%20app.%20This%20will%20let%20your%20users%20upload%2Fedit%20their%20own%20avatars%20or%20use%20Gravatar.%0A%0ABut%20for%20my%20app%20I%20only%20wanted%20to%20use%20Gravatar%20so%20I%20was%20looking%20for%20a%20si" title="del.icio.us" onclick="pageTracker._trackPageview('/outgoing/delicious.com/post?url=http_3A_2F_2Fwww.givp.org_2Fblog_2F2009_2F12_2F13_2Fdjango-gravatar-filter_2F_amp_title=Django_20Gravatar_20filter_amp_notes=If_20you_20want_20to_20add_20user_20avatars_20to_20your_20Django_20app_2C_20you_20can_20certainly_20use_20the_20excellent_20django-avatar_20app._20This_20will_20let_20your_20users_20upload_2Fedit_20their_20own_20avatars_20or_20use_20Gravatar._0A_0ABut_20for_20my_20app_20I_20only_20wanted_20to_20use_20Gravatar_20so_20I_20was_20looking_20for_20a_20si&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.givp.org%2Fblog%2F2009%2F12%2F13%2Fdjango-gravatar-filter%2F&amp;title=Django%20Gravatar%20filter&amp;annotation=If%20you%20want%20to%20add%20user%20avatars%20to%20your%20Django%20app%2C%20you%20can%20certainly%20use%20the%20excellent%20django-avatar%20app.%20This%20will%20let%20your%20users%20upload%2Fedit%20their%20own%20avatars%20or%20use%20Gravatar.%0A%0ABut%20for%20my%20app%20I%20only%20wanted%20to%20use%20Gravatar%20so%20I%20was%20looking%20for%20a%20si" title="Google Bookmarks" onclick="pageTracker._trackPageview('/outgoing/www.google.com/bookmarks/mark?op=edit_amp_bkmk=http_3A_2F_2Fwww.givp.org_2Fblog_2F2009_2F12_2F13_2Fdjango-gravatar-filter_2F_amp_title=Django_20Gravatar_20filter_amp_annotation=If_20you_20want_20to_20add_20user_20avatars_20to_20your_20Django_20app_2C_20you_20can_20certainly_20use_20the_20excellent_20django-avatar_20app._20This_20will_20let_20your_20users_20upload_2Fedit_20their_20own_20avatars_20or_20use_20Gravatar._0A_0ABut_20for_20my_20app_20I_20only_20wanted_20to_20use_20Gravatar_20so_20I_20was_20looking_20for_20a_20si&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.givp.org/blog/2009/12/13/django-gravatar-filter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Django Geolocation</title>
		<link>http://www.givp.org/blog/2009/10/31/django-geolocation/</link>
		<comments>http://www.givp.org/blog/2009/10/31/django-geolocation/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 16:35:37 +0000</pubDate>
		<dc:creator>Giv</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[model]]></category>

		<guid isPermaLink="false">http://www.givp.org/blog/?p=87</guid>
		<description><![CDATA[One thing I love about Django models is the ability to subclass its methods to add extra functionality without having to write any extra code in admin or view layers. I have an application where a user can enter an address in the admin section. I want to plot this location on Google Maps later [...]]]></description>
			<content:encoded><![CDATA[<p>One thing I love about Django models is the ability to subclass its methods to add extra functionality without having to write any extra code in admin or view layers.</p>
<p>I have an application where a user can enter an address in the admin section. I want to plot this location on Google Maps later but I don&#8217;t want to have to parse the address and do a reverse geolocation lookup in the view layer every time that page is viewed. The best thing to do is to store the lat/long values in the database.</p>
<p>I could do this by messing around with the Django admin templates but I&#8217;d rather not even let the user know the geolocation lookup is happening. Besides, what if I want to interact with the DB from the interpreter? The geolocation bit should happen no matter where the database is being used.</p>
<p>This is my model</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> Entry<span style="color: black;">&#40;</span>models.<span style="color: black;">Model</span><span style="color: black;">&#41;</span>:
    title = models.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span>max_length=<span style="color: #ff4500;">200</span><span style="color: black;">&#41;</span>
    description = models.<span style="color: black;">TextField</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'description'</span>, blank=<span style="color: #008000;">True</span>, null=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
    address = models.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span>max_length=<span style="color: #ff4500;">200</span>, blank=<span style="color: #008000;">True</span>, null=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
    postcode = models.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span>max_length=<span style="color: #ff4500;">200</span>, blank=<span style="color: #008000;">True</span>, null=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
    city = models.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span>max_length=<span style="color: #ff4500;">200</span>, blank=<span style="color: #008000;">True</span>, null=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
    country = models.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span>max_length=<span style="color: #ff4500;">100</span><span style="color: black;">&#41;</span>
    geo_lat = models.<span style="color: black;">DecimalField</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'latitude'</span>, max_digits=<span style="color: #ff4500;">13</span>, decimal_places=<span style="color: #ff4500;">10</span>, blank=<span style="color: #008000;">True</span>, null=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
    geo_long = models.<span style="color: black;">DecimalField</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'longitude'</span>, max_digits=<span style="color: #ff4500;">13</span>, decimal_places=<span style="color: #ff4500;">10</span>, blank=<span style="color: #008000;">True</span>, null=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>In Django admin I don&#8217;t show &#8216;geo_lat&#8217; and &#8216;geo_lat&#8217;. We just ask the user to enter the address, then before saving, we do the lookup, set the lat/long values and then save the model.</p>
<p>Creating a new entry would still be done the same way from either admin, view or interpreter:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">e = Entry<span style="color: black;">&#40;</span>title=<span style="color: #483d8b;">'a new entry'</span>, address=<span style="color: #483d8b;">'123 Smith Road'</span>, city=<span style="color: #483d8b;">'London'</span>, country=<span style="color: #483d8b;">'UK'</span><span style="color: black;">&#41;</span>
e.<span style="color: black;">save</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>But we are going to hijack the save() method to do some extra work before saving to the database. Let&#8217;s create a method that does the geolocation lookup first:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib2</span>
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">utils</span> <span style="color: #ff7700;font-weight:bold;">import</span> simplejson <span style="color: #ff7700;font-weight:bold;">as</span> json
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> get_geo<span style="color: black;">&#40;</span>address<span style="color: black;">&#41;</span>:
    address = <span style="color: #dc143c;">urllib</span>.<span style="color: black;">quote</span><span style="color: black;">&#40;</span>address<span style="color: black;">&#41;</span>
    url = <span style="color: #483d8b;">&quot;http://maps.google.com/maps/geo?q=%s&amp;output=json&amp;oe=utf8&amp;sensor=true_or_false&amp;key=12345&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>address<span style="color: black;">&#41;</span>
    data = <span style="color: #dc143c;">urllib2</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span>url<span style="color: black;">&#41;</span>
    obj = json.<span style="color: black;">loads</span><span style="color: black;">&#40;</span> data.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> obj<span style="color: black;">&#91;</span><span style="color: #483d8b;">'Status'</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'code'</span><span style="color: black;">&#93;</span> == <span style="color: #ff4500;">200</span>:
        data = obj<span style="color: black;">&#91;</span><span style="color: #483d8b;">'Placemark'</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'Point'</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'coordinates'</span><span style="color: black;">&#93;</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #ff7700;font-weight:bold;">raise</span> <span style="color: #008000;">Exception</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Invalid address'</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> data</pre></td></tr></table></div>

<p>We pass the address to Google and if we get a 200 status code, we grab the lat/long values and return them.</p>
<p>Now let&#8217;s call this method in our save() subclass (inside the Entry model):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> save<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
    add = <span style="color: #483d8b;">&quot;%s, %s, %s, %s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">address</span>, <span style="color: #008000;">self</span>.<span style="color: black;">postcode</span>, <span style="color: #008000;">self</span>.<span style="color: black;">city</span>, <span style="color: #008000;">self</span>.<span style="color: black;">country</span><span style="color: black;">&#41;</span>
    geo_data = utils.<span style="color: black;">get_geo</span><span style="color: black;">&#40;</span>add<span style="color: black;">&#41;</span>
    <span style="color: #008000;">self</span>.<span style="color: black;">geo_long</span> = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>geo_data<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
    <span style="color: #008000;">self</span>.<span style="color: black;">geo_lat</span> = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>geo_data<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
    <span style="color: #008000;">super</span><span style="color: black;">&#40;</span>Listing, <span style="color: #008000;">self</span><span style="color: black;">&#41;</span>.<span style="color: black;">save</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># Call the &quot;real&quot; save() method</span></pre></td></tr></table></div>

<p>This could be improved so instead of throwing and exception for bad addresses we handle it more gracefully by informing the user or at least save the address and ignore the geolocation lookup. But either way, the model is now responsible for doing the extra work before saving the new/updated data.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  href="http://twitter.com/home?status=Django%20Geolocation%20-%20http%3A%2F%2Fwww.givp.org%2Fblog%2F2009%2F10%2F31%2Fdjango-geolocation%2F" title="Twitter" onclick="pageTracker._trackPageview('/outgoing/twitter.com/home?status=Django_20Geolocation_20-_20http_3A_2F_2Fwww.givp.org_2Fblog_2F2009_2F10_2F31_2Fdjango-geolocation_2F&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.givp.org%2Fblog%2F2009%2F10%2F31%2Fdjango-geolocation%2F&amp;t=Django%20Geolocation" title="Facebook" onclick="pageTracker._trackPageview('/outgoing/www.facebook.com/share.php?u=http_3A_2F_2Fwww.givp.org_2Fblog_2F2009_2F10_2F31_2Fdjango-geolocation_2F_amp_t=Django_20Geolocation&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.givp.org%2Fblog%2F2009%2F10%2F31%2Fdjango-geolocation%2F&amp;title=Django%20Geolocation&amp;bodytext=One%20thing%20I%20love%20about%20Django%20models%20is%20the%20ability%20to%20subclass%20its%20methods%20to%20add%20extra%20functionality%20without%20having%20to%20write%20any%20extra%20code%20in%20admin%20or%20view%20layers.%0A%0AI%20have%20an%20application%20where%20a%20user%20can%20enter%20an%20address%20in%20the%20admin%20section.%20I%20wa" title="Digg" onclick="pageTracker._trackPageview('/outgoing/digg.com/submit?phase=2_amp_url=http_3A_2F_2Fwww.givp.org_2Fblog_2F2009_2F10_2F31_2Fdjango-geolocation_2F_amp_title=Django_20Geolocation_amp_bodytext=One_20thing_20I_20love_20about_20Django_20models_20is_20the_20ability_20to_20subclass_20its_20methods_20to_20add_20extra_20functionality_20without_20having_20to_20write_20any_20extra_20code_20in_20admin_20or_20view_20layers._0A_0AI_20have_20an_20application_20where_20a_20user_20can_20enter_20an_20address_20in_20the_20admin_20section._20I_20wa&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fwww.givp.org%2Fblog%2F2009%2F10%2F31%2Fdjango-geolocation%2F&amp;title=Django%20Geolocation&amp;notes=One%20thing%20I%20love%20about%20Django%20models%20is%20the%20ability%20to%20subclass%20its%20methods%20to%20add%20extra%20functionality%20without%20having%20to%20write%20any%20extra%20code%20in%20admin%20or%20view%20layers.%0A%0AI%20have%20an%20application%20where%20a%20user%20can%20enter%20an%20address%20in%20the%20admin%20section.%20I%20wa" title="del.icio.us" onclick="pageTracker._trackPageview('/outgoing/delicious.com/post?url=http_3A_2F_2Fwww.givp.org_2Fblog_2F2009_2F10_2F31_2Fdjango-geolocation_2F_amp_title=Django_20Geolocation_amp_notes=One_20thing_20I_20love_20about_20Django_20models_20is_20the_20ability_20to_20subclass_20its_20methods_20to_20add_20extra_20functionality_20without_20having_20to_20write_20any_20extra_20code_20in_20admin_20or_20view_20layers._0A_0AI_20have_20an_20application_20where_20a_20user_20can_20enter_20an_20address_20in_20the_20admin_20section._20I_20wa&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.givp.org%2Fblog%2F2009%2F10%2F31%2Fdjango-geolocation%2F&amp;title=Django%20Geolocation&amp;annotation=One%20thing%20I%20love%20about%20Django%20models%20is%20the%20ability%20to%20subclass%20its%20methods%20to%20add%20extra%20functionality%20without%20having%20to%20write%20any%20extra%20code%20in%20admin%20or%20view%20layers.%0A%0AI%20have%20an%20application%20where%20a%20user%20can%20enter%20an%20address%20in%20the%20admin%20section.%20I%20wa" title="Google Bookmarks" onclick="pageTracker._trackPageview('/outgoing/www.google.com/bookmarks/mark?op=edit_amp_bkmk=http_3A_2F_2Fwww.givp.org_2Fblog_2F2009_2F10_2F31_2Fdjango-geolocation_2F_amp_title=Django_20Geolocation_amp_annotation=One_20thing_20I_20love_20about_20Django_20models_20is_20the_20ability_20to_20subclass_20its_20methods_20to_20add_20extra_20functionality_20without_20having_20to_20write_20any_20extra_20code_20in_20admin_20or_20view_20layers._0A_0AI_20have_20an_20application_20where_20a_20user_20can_20enter_20an_20address_20in_20the_20admin_20section._20I_20wa&amp;referer=');"><img src="http://www.givp.org/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.givp.org/blog/2009/10/31/django-geolocation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
