<?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; Python</title>
	<atom:link href="http://www.givp.org/blog/category/python/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>iPhone App Development with Google App Engine</title>
		<link>http://www.givp.org/blog/2010/02/14/iphone-app-dev-google-app-engine/</link>
		<comments>http://www.givp.org/blog/2010/02/14/iphone-app-dev-google-app-engine/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 12:11:04 +0000</pubDate>
		<dc:creator>Giv</dc:creator>
				<category><![CDATA[Google App Engine]]></category>
		<category><![CDATA[Objective-c]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[appengine]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[memcached]]></category>

		<guid isPermaLink="false">http://www.givp.org/blog/?p=138</guid>
		<description><![CDATA[After almost a year of messing around with various iPhone development alternatives such as Phonegap and Titanium, I finally decided to learn Objective-C and do it all properly. I actually think those other frameworks are brilliant as they allow you to use familiar languages like Javascript to quickly create nice apps for both iPhone and [...]]]></description>
			<content:encoded><![CDATA[<p>After almost a year of messing around with various iPhone development alternatives such as <a href="http://phonegap.com/" onclick="pageTracker._trackPageview('/outgoing/phonegap.com/?referer=');">Phonegap</a> and <a href="http://www.appcelerator.com/" onclick="pageTracker._trackPageview('/outgoing/www.appcelerator.com/?referer=');">Titanium</a>, I finally decided to learn Objective-C and do it all properly. I actually think those other frameworks are brilliant as they allow you to use familiar languages like Javascript to quickly create nice apps for both iPhone and Android. But since they rely heavily on the web view element for loading HTML, creating sophisticated apps like Skype would be impossible.</p>
<p>So I set out to create an app for the iPhone with Objective-C. My app is pretty simple. It basically pulls in RSS news, audio podcast and video podcast feeds into a <a href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html" onclick="pageTracker._trackPageview('/outgoing/developer.apple.com/iphone/library/documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html?referer=');">UITableView</a> list, allowing the user to read, listen and watch news stories from the <a href="http://www.democracynow.org/" onclick="pageTracker._trackPageview('/outgoing/www.democracynow.org/?referer=');">Democracy Now!</a> website.</p>
<p><img class="alignright" title="Democracy Now! app" src="http://www.givp.org/democracyapp/img/democphone.png" alt="" width="164" height="305" /><br />
I managed to put together the app pretty quickly but I ran into a lot of issues when I tried to parse and massage the XML data. For starters, cocoa does not have native support for regular expressions (but there are several external libraries). I wanted to clean up the content I was getting back before displaying it to the user but I soon realised something that would normally take me a few minutes in Python/PHP/Javascript would take a lot longer in Objective-C. Parsing XML using <a href="http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html" onclick="pageTracker._trackPageview('/outgoing/developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html?referer=');">NSXMLParser</a> was an absolute nightmare and extremely slow. I rarely work with XML these days and find JSON a much easier protocol to deal with. I even tested the app with some sample JSON data using the excellent <a href="http://code.google.com/p/json-framework/" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/json-framework/?referer=');">json-framework</a> libarary and it was much easier and faster. Alas, I only had RSS feeds to work with.</p>
<p>The other problem I ran into was slow HTTP requests. It would sometimes take up to 20 seconds just to load the first screen. This was due to a combination of slow connection speeds, long response times from the data provider and a slow XML parser.</p>
<p>The solution I came up with was to do as little as possible in the phone app as far as the data was concerned. I decided to use Google App Engine to fetch the data from the source, parse, rejig, massage and beautify in Python, then serialise and return the results in JSON to the phone app to use.</p>
<p>It may sound like this would increase response times even more since the phone would have to first call GAE, then GAE would need to call the data source and then all the way back to the phone. This is true, however, once the data is with GAE we have the luxury of using <a href="http://code.google.com/appengine/docs/python/memcache/usingmemcache.html" onclick="pageTracker._trackPageview('/outgoing/code.google.com/appengine/docs/python/memcache/usingmemcache.html?referer=');">memcache</a> and <a href="http://code.google.com/appengine/docs/python/datastore/" onclick="pageTracker._trackPageview('/outgoing/code.google.com/appengine/docs/python/datastore/?referer=');">datastore</a>. The RSS and podcast feeds are updated once a day so there&#8217;s no reason to request the data from the source every time the user loads the app. Because each time we have to make the HTTP call, parse the data and load it up. This is extremely slow and unnecessary. We can just make one request a day, then parse, cleanup and cache the results for the next user that requests it.</p>
<p>So the app only talks to GAE. GAE first checks memcache to see if we have a cached version. If we don&#8217;t, it will make the HTTP call, fetch the data, parse, serialise, cache and return results. If we do have a cached version, there&#8217;s nothing else to do but to return the data. A cron job will also run every 24 hours to make sure memcache is up to date.</p>
<p><img src="http://givp.mugal.org/blog/wp-content/uploads/2010/02/bloggae.gif" alt="" /></p>
<p>If you really want a solid and reliable app, you need to think about all the edge cases also. What happens if the cache expires and the data provider&#8217;s website is down? At that exact moment a user loads the app only to get an error message saying there&#8217;s nothing to show. An unlikely scenario but not impossible. So the way I got around this issue was to store the serialised JSON output in GAE&#8217;s datastore as well. We always use the data from memcache but should memcache be empty and the data source down, we can switch over to the datastore and load yesterday&#8217;s content instead. Not ideal but better than having a broken app.</p>
<p>This is a bit of an overkill for such a simple app but it&#8217;s super fast and efficient and will work well for almost any app that relies on 3rd-party APIs. To be fair, it was my lack of experience with Objective-C that led me to using GAE. I feel much more comfortable in Python than Objective-C and I&#8217;m sure an experienced cocoa developer would have no problems parsing and massaging data in the app itself.</p>
<p>Of course there is one other edge case &#8211; Google App Engine could go down or worst, the interwebz could break. In which case, a simple error message will suffice.</p>
<p>You can download <a href="http://itunes.apple.com/app/democracy-now-war-peace-report/id353540657" onclick="pageTracker._trackPageview('/outgoing/itunes.apple.com/app/democracy-now-war-peace-report/id353540657?referer=');">Democracy Now! app on iTunes</a></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=iPhone%20App%20Development%20with%20Google%20App%20Engine%20-%20http%3A%2F%2Fwww.givp.org%2Fblog%2F2010%2F02%2F14%2Fiphone-app-dev-google-app-engine%2F" title="Twitter" onclick="pageTracker._trackPageview('/outgoing/twitter.com/home?status=iPhone_20App_20Development_20with_20Google_20App_20Engine_20-_20http_3A_2F_2Fwww.givp.org_2Fblog_2F2010_2F02_2F14_2Fiphone-app-dev-google-app-engine_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%2F02%2F14%2Fiphone-app-dev-google-app-engine%2F&amp;t=iPhone%20App%20Development%20with%20Google%20App%20Engine" title="Facebook" onclick="pageTracker._trackPageview('/outgoing/www.facebook.com/share.php?u=http_3A_2F_2Fwww.givp.org_2Fblog_2F2010_2F02_2F14_2Fiphone-app-dev-google-app-engine_2F_amp_t=iPhone_20App_20Development_20with_20Google_20App_20Engine&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%2F02%2F14%2Fiphone-app-dev-google-app-engine%2F&amp;title=iPhone%20App%20Development%20with%20Google%20App%20Engine&amp;bodytext=After%20almost%20a%20year%20of%20messing%20around%20with%20various%20iPhone%20development%20alternatives%20such%20as%20Phonegap%20and%20Titanium%2C%20I%20finally%20decided%20to%20learn%20Objective-C%20and%20do%20it%20all%20properly.%20I%20actually%20think%20those%20other%20frameworks%20are%20brilliant%20as%20they%20allow%20you%20t" title="Digg" onclick="pageTracker._trackPageview('/outgoing/digg.com/submit?phase=2_amp_url=http_3A_2F_2Fwww.givp.org_2Fblog_2F2010_2F02_2F14_2Fiphone-app-dev-google-app-engine_2F_amp_title=iPhone_20App_20Development_20with_20Google_20App_20Engine_amp_bodytext=After_20almost_20a_20year_20of_20messing_20around_20with_20various_20iPhone_20development_20alternatives_20such_20as_20Phonegap_20and_20Titanium_2C_20I_20finally_20decided_20to_20learn_20Objective-C_20and_20do_20it_20all_20properly._20I_20actually_20think_20those_20other_20frameworks_20are_20brilliant_20as_20they_20allow_20you_20t&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%2F02%2F14%2Fiphone-app-dev-google-app-engine%2F&amp;title=iPhone%20App%20Development%20with%20Google%20App%20Engine&amp;notes=After%20almost%20a%20year%20of%20messing%20around%20with%20various%20iPhone%20development%20alternatives%20such%20as%20Phonegap%20and%20Titanium%2C%20I%20finally%20decided%20to%20learn%20Objective-C%20and%20do%20it%20all%20properly.%20I%20actually%20think%20those%20other%20frameworks%20are%20brilliant%20as%20they%20allow%20you%20t" title="del.icio.us" onclick="pageTracker._trackPageview('/outgoing/delicious.com/post?url=http_3A_2F_2Fwww.givp.org_2Fblog_2F2010_2F02_2F14_2Fiphone-app-dev-google-app-engine_2F_amp_title=iPhone_20App_20Development_20with_20Google_20App_20Engine_amp_notes=After_20almost_20a_20year_20of_20messing_20around_20with_20various_20iPhone_20development_20alternatives_20such_20as_20Phonegap_20and_20Titanium_2C_20I_20finally_20decided_20to_20learn_20Objective-C_20and_20do_20it_20all_20properly._20I_20actually_20think_20those_20other_20frameworks_20are_20brilliant_20as_20they_20allow_20you_20t&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%2F02%2F14%2Fiphone-app-dev-google-app-engine%2F&amp;title=iPhone%20App%20Development%20with%20Google%20App%20Engine&amp;annotation=After%20almost%20a%20year%20of%20messing%20around%20with%20various%20iPhone%20development%20alternatives%20such%20as%20Phonegap%20and%20Titanium%2C%20I%20finally%20decided%20to%20learn%20Objective-C%20and%20do%20it%20all%20properly.%20I%20actually%20think%20those%20other%20frameworks%20are%20brilliant%20as%20they%20allow%20you%20t" title="Google Bookmarks" onclick="pageTracker._trackPageview('/outgoing/www.google.com/bookmarks/mark?op=edit_amp_bkmk=http_3A_2F_2Fwww.givp.org_2Fblog_2F2010_2F02_2F14_2Fiphone-app-dev-google-app-engine_2F_amp_title=iPhone_20App_20Development_20with_20Google_20App_20Engine_amp_annotation=After_20almost_20a_20year_20of_20messing_20around_20with_20various_20iPhone_20development_20alternatives_20such_20as_20Phonegap_20and_20Titanium_2C_20I_20finally_20decided_20to_20learn_20Objective-C_20and_20do_20it_20all_20properly._20I_20actually_20think_20those_20other_20frameworks_20are_20brilliant_20as_20they_20allow_20you_20t&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/02/14/iphone-app-dev-google-app-engine/feed/</wfw:commentRss>
		<slash:comments>4</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>Test-driven Development in Agile Projects</title>
		<link>http://www.givp.org/blog/2009/11/21/test-driven-development-in-agile/</link>
		<comments>http://www.givp.org/blog/2009/11/21/test-driven-development-in-agile/#comments</comments>
		<pubDate>Sat, 21 Nov 2009 14:29:06 +0000</pubDate>
		<dc:creator>Giv</dc:creator>
				<category><![CDATA[Experiments]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.givp.org/blog/?p=113</guid>
		<description><![CDATA[I recently posted this on the BBC Web Developer Blog: http://www.bbc.co.uk/blogs/webdeveloper/2009/11/testdriven-development-in-agil.shtml Developers at the BBC tend to use Agile methodologies as a way to quickly release iterations of products. But where does rigorous code testing fit in with the short development and release cycles? How can we maintain the quality of our code when things [...]]]></description>
			<content:encoded><![CDATA[<p>I recently posted this on the BBC Web Developer Blog:</p>
<p><a href="http://www.bbc.co.uk/blogs/webdeveloper/2009/11/testdriven-development-in-agil.shtml" onclick="pageTracker._trackPageview('/outgoing/www.bbc.co.uk/blogs/webdeveloper/2009/11/testdriven-development-in-agil.shtml?referer=');">http://www.bbc.co.uk/blogs/webdeveloper/2009/11/testdriven-development-in-agil.shtml</a></p>
<blockquote><p>
Developers at the BBC tend to use Agile methodologies as a way to quickly release iterations of products. But where does rigorous code testing fit in with the short development and release cycles? How can we maintain the quality of our code when things need to change so fast?
</p></blockquote>
<p><a href="http://www.bbc.co.uk/blogs/webdeveloper/2009/11/testdriven-development-in-agil.shtml" onclick="pageTracker._trackPageview('/outgoing/www.bbc.co.uk/blogs/webdeveloper/2009/11/testdriven-development-in-agil.shtml?referer=');">More</a></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%20in%20Agile%20Projects%20-%20http%3A%2F%2Fwww.givp.org%2Fblog%2F2009%2F11%2F21%2Ftest-driven-development-in-agile%2F" title="Twitter" onclick="pageTracker._trackPageview('/outgoing/twitter.com/home?status=Test-driven_20Development_20in_20Agile_20Projects_20-_20http_3A_2F_2Fwww.givp.org_2Fblog_2F2009_2F11_2F21_2Ftest-driven-development-in-agile_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%2F11%2F21%2Ftest-driven-development-in-agile%2F&amp;t=Test-driven%20Development%20in%20Agile%20Projects" title="Facebook" onclick="pageTracker._trackPageview('/outgoing/www.facebook.com/share.php?u=http_3A_2F_2Fwww.givp.org_2Fblog_2F2009_2F11_2F21_2Ftest-driven-development-in-agile_2F_amp_t=Test-driven_20Development_20in_20Agile_20Projects&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%2F11%2F21%2Ftest-driven-development-in-agile%2F&amp;title=Test-driven%20Development%20in%20Agile%20Projects&amp;bodytext=I%20recently%20posted%20this%20on%20the%20BBC%20Web%20Developer%20Blog%3A%0A%0Ahttp%3A%2F%2Fwww.bbc.co.uk%2Fblogs%2Fwebdeveloper%2F2009%2F11%2Ftestdriven-development-in-agil.shtml%0A%0A%0ADevelopers%20at%20the%20BBC%20tend%20to%20use%20Agile%20methodologies%20as%20a%20way%20to%20quickly%20release%20iterations%20of%20products.%20Bu" title="Digg" onclick="pageTracker._trackPageview('/outgoing/digg.com/submit?phase=2_amp_url=http_3A_2F_2Fwww.givp.org_2Fblog_2F2009_2F11_2F21_2Ftest-driven-development-in-agile_2F_amp_title=Test-driven_20Development_20in_20Agile_20Projects_amp_bodytext=I_20recently_20posted_20this_20on_20the_20BBC_20Web_20Developer_20Blog_3A_0A_0Ahttp_3A_2F_2Fwww.bbc.co.uk_2Fblogs_2Fwebdeveloper_2F2009_2F11_2Ftestdriven-development-in-agil.shtml_0A_0A_0ADevelopers_20at_20the_20BBC_20tend_20to_20use_20Agile_20methodologies_20as_20a_20way_20to_20quickly_20release_20iterations_20of_20products._20Bu&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%2F11%2F21%2Ftest-driven-development-in-agile%2F&amp;title=Test-driven%20Development%20in%20Agile%20Projects&amp;notes=I%20recently%20posted%20this%20on%20the%20BBC%20Web%20Developer%20Blog%3A%0A%0Ahttp%3A%2F%2Fwww.bbc.co.uk%2Fblogs%2Fwebdeveloper%2F2009%2F11%2Ftestdriven-development-in-agil.shtml%0A%0A%0ADevelopers%20at%20the%20BBC%20tend%20to%20use%20Agile%20methodologies%20as%20a%20way%20to%20quickly%20release%20iterations%20of%20products.%20Bu" title="del.icio.us" onclick="pageTracker._trackPageview('/outgoing/delicious.com/post?url=http_3A_2F_2Fwww.givp.org_2Fblog_2F2009_2F11_2F21_2Ftest-driven-development-in-agile_2F_amp_title=Test-driven_20Development_20in_20Agile_20Projects_amp_notes=I_20recently_20posted_20this_20on_20the_20BBC_20Web_20Developer_20Blog_3A_0A_0Ahttp_3A_2F_2Fwww.bbc.co.uk_2Fblogs_2Fwebdeveloper_2F2009_2F11_2Ftestdriven-development-in-agil.shtml_0A_0A_0ADevelopers_20at_20the_20BBC_20tend_20to_20use_20Agile_20methodologies_20as_20a_20way_20to_20quickly_20release_20iterations_20of_20products._20Bu&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%2F11%2F21%2Ftest-driven-development-in-agile%2F&amp;title=Test-driven%20Development%20in%20Agile%20Projects&amp;annotation=I%20recently%20posted%20this%20on%20the%20BBC%20Web%20Developer%20Blog%3A%0A%0Ahttp%3A%2F%2Fwww.bbc.co.uk%2Fblogs%2Fwebdeveloper%2F2009%2F11%2Ftestdriven-development-in-agil.shtml%0A%0A%0ADevelopers%20at%20the%20BBC%20tend%20to%20use%20Agile%20methodologies%20as%20a%20way%20to%20quickly%20release%20iterations%20of%20products.%20Bu" title="Google Bookmarks" onclick="pageTracker._trackPageview('/outgoing/www.google.com/bookmarks/mark?op=edit_amp_bkmk=http_3A_2F_2Fwww.givp.org_2Fblog_2F2009_2F11_2F21_2Ftest-driven-development-in-agile_2F_amp_title=Test-driven_20Development_20in_20Agile_20Projects_amp_annotation=I_20recently_20posted_20this_20on_20the_20BBC_20Web_20Developer_20Blog_3A_0A_0Ahttp_3A_2F_2Fwww.bbc.co.uk_2Fblogs_2Fwebdeveloper_2F2009_2F11_2Ftestdriven-development-in-agil.shtml_0A_0A_0ADevelopers_20at_20the_20BBC_20tend_20to_20use_20Agile_20methodologies_20as_20a_20way_20to_20quickly_20release_20iterations_20of_20products._20Bu&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/11/21/test-driven-development-in-agile/feed/</wfw:commentRss>
		<slash:comments>0</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>
