<?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>Anand Nalya &#187; django</title>
	<atom:link href="http://anandnalya.com/tag/django/feed/" rel="self" type="application/rss+xml" />
	<link>http://anandnalya.com</link>
	<description>blog</description>
	<lastBuildDate>Tue, 01 May 2012 10:25:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Java Code Generators &#8211; A short rant</title>
		<link>http://anandnalya.com/2011/07/27/java-code-generators-a-short-rant/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=java-code-generators-a-short-rant</link>
		<comments>http://anandnalya.com/2011/07/27/java-code-generators-a-short-rant/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 06:02:51 +0000</pubDate>
		<dc:creator>anand</dc:creator>
				<category><![CDATA[Codeprix]]></category>
		<category><![CDATA[Thinking]]></category>
		<category><![CDATA[code generators]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[play]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ror]]></category>

		<guid isPermaLink="false">http://anandnalya.com/?p=124</guid>
		<description><![CDATA[Java is known to be a verbose language and the situation worsens when you step into bloated enterprise java world. You need to write tons of code and configure a lot of JXXX to make your simple webapp work. Though &#8230; <a href="http://anandnalya.com/2011/07/27/java-code-generators-a-short-rant/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Java is known to be a verbose language and the situation worsens when you step into bloated enterprise java world. You need to write tons of code and configure a lot of <em>JXXX</em> to make your simple webapp work. Though the situation is improving in the recent years with the introduction of convention over configuration approach and also of annotation based configurations but still, if you compare the amount of code required for a functional webapp in Java then it would be at least 2X to 4X more than that of similar webapps written in other frameworks like <a href="https://www.djangoproject.com/">Django</a> or <a href="http://rubyonrails.org/">RoR</a>.</p>
<p>A lot of java frameworks and IDEs tries to hide this complexity by generating code &#8211; from simple getters and setters to entire DAO layers and what not &#8211; that might give small productivity gains in the beginning but eventually every additional line of code in your project, either hand-written or generated by a state of art code generator, someone will need to maintain and evolve it, which according to <a href="http://users.jyu.fi/~koskinen/smcosts.htm">some</a> is almost 90% of the total software costs.</p>
<p>Thats why framework like <a href="http://www.playframework.org/">Play</a> feels like fresh air and it seems to be making inroads in the bloated enterprise java world.</p>
]]></content:encoded>
			<wfw:commentRss>http://anandnalya.com/2011/07/27/java-code-generators-a-short-rant/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Humanizing the time difference ( in django )</title>
		<link>http://anandnalya.com/2009/05/20/humanizing-the-time-difference-in-django/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=humanizing-the-time-difference-in-django</link>
		<comments>http://anandnalya.com/2009/05/20/humanizing-the-time-difference-in-django/#comments</comments>
		<pubDate>Wed, 20 May 2009 10:02:35 +0000</pubDate>
		<dc:creator>anand</dc:creator>
				<category><![CDATA[Codeprix]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[filters]]></category>
		<category><![CDATA[humanize]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://anandnalya.com/?p=70</guid>
		<description><![CDATA[django.contrib.humanize is a set of Django template filters that adds human touch to data. It provides naturalday filter that formats date to &#8216;yesterday&#8217;, &#8216;today&#8217; or &#8216;tomorrow&#8217; when applicable. A similar requirement which the humanize pacakge does not address is to &#8230; <a href="http://anandnalya.com/2009/05/20/humanizing-the-time-difference-in-django/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://docs.djangoproject.com/en/dev/ref/contrib/humanize/#module-django.contrib.humanize">django.contrib.humanize</a> is a set of Django template filters that adds human touch to data. It provides <a href="http://docs.djangoproject.com/en/dev/ref/contrib/humanize/#naturalday">naturalday</a> filter that formats date to &#8216;yesterday&#8217;, &#8216;today&#8217; or &#8216;tomorrow&#8217; when applicable.</p>
<p>A similar requirement which the humanize pacakge does not address is to display time difference with this human touch. so here is a snippet that does so.</p>
<div id="gist-1124424" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="kn">from</span> <span class="nn">django</span> <span class="kn">import</span> <span class="n">template</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'><span class="n">register</span> <span class="o">=</span> <span class="n">template</span><span class="o">.</span><span class="n">Library</span><span class="p">()</span></div><div class='line' id='LC4'><br/></div><div class='line' id='LC5'><span class="n">MOMENT</span> <span class="o">=</span> <span class="mi">120</span>    <span class="c"># duration in seconds within which the time difference </span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="c"># will be rendered as &#39;a moment ago&#39;</span></div><div class='line' id='LC7'><br/></div><div class='line' id='LC8'><span class="nd">@register.filter</span></div><div class='line' id='LC9'><span class="k">def</span> <span class="nf">naturalTimeDifference</span><span class="p">(</span><span class="n">value</span><span class="p">):</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="sd">&quot;&quot;&quot;</span></div><div class='line' id='LC11'><span class="sd">    Finds the difference between the datetime value given and now()</span></div><div class='line' id='LC12'><span class="sd">    and returns appropriate humanize form</span></div><div class='line' id='LC13'><span class="sd">    &quot;&quot;&quot;</span></div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span></div><div class='line' id='LC16'><br/></div><div class='line' id='LC17'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">datetime</span><span class="p">):</span></div><div class='line' id='LC18'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">delta</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()</span> <span class="o">-</span> <span class="n">value</span></div><div class='line' id='LC19'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="n">delta</span><span class="o">.</span><span class="n">days</span> <span class="o">&gt;</span> <span class="mi">6</span><span class="p">:</span></div><div class='line' id='LC20'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="n">value</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s">&quot;%b </span><span class="si">%d</span><span class="s">&quot;</span><span class="p">)</span>                    <span class="c"># May 15</span></div><div class='line' id='LC21'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="n">delta</span><span class="o">.</span><span class="n">days</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span></div><div class='line' id='LC22'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="n">value</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s">&quot;%A&quot;</span><span class="p">)</span>                       <span class="c"># Wednesday</span></div><div class='line' id='LC23'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">elif</span> <span class="n">delta</span><span class="o">.</span><span class="n">days</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span></div><div class='line' id='LC24'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="s">&#39;yesterday&#39;</span>                                <span class="c"># yesterday</span></div><div class='line' id='LC25'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">elif</span> <span class="n">delta</span><span class="o">.</span><span class="n">seconds</span> <span class="o">&gt;</span> <span class="mi">3600</span><span class="p">:</span></div><div class='line' id='LC26'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="nb">str</span><span class="p">(</span><span class="n">delta</span><span class="o">.</span><span class="n">seconds</span> <span class="o">/</span> <span class="mi">3600</span> <span class="p">)</span> <span class="o">+</span> <span class="s">&#39; hours ago&#39;</span>  <span class="c"># 3 hours ago</span></div><div class='line' id='LC27'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">elif</span> <span class="n">delta</span><span class="o">.</span><span class="n">seconds</span> <span class="o">&gt;</span>  <span class="n">MOMENT</span><span class="p">:</span></div><div class='line' id='LC28'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="nb">str</span><span class="p">(</span><span class="n">delta</span><span class="o">.</span><span class="n">seconds</span><span class="o">/</span><span class="mi">60</span><span class="p">)</span> <span class="o">+</span> <span class="s">&#39; minutes ago&#39;</span>     <span class="c"># 29 minutes ago</span></div><div class='line' id='LC29'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">else</span><span class="p">:</span></div><div class='line' id='LC30'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="s">&#39;a moment ago&#39;</span>                             <span class="c"># a moment ago</span></div><div class='line' id='LC31'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="n">defaultfilters</span><span class="o">.</span><span class="n">date</span><span class="p">(</span><span class="n">value</span><span class="p">)</span></div><div class='line' id='LC32'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">else</span><span class="p">:</span></div><div class='line' id='LC33'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="nb">str</span><span class="p">(</span><span class="n">value</span><span class="p">)</span></div><div class='line' id='LC34'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1124424/d65ec7510696ad289cb8f1d9fdde5491060fd32a/humanizeTimeDifference.py" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1124424#file_humanize_time_difference.py" style="float:right;margin-right:10px;color:#666">humanizeTimeDifference.py</a>
            <a href="https://gist.github.com/1124424">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://anandnalya.com/2009/05/20/humanizing-the-time-difference-in-django/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

