<?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>Ryan Kanno: The diary of an Enginerd in Hawaii&#187; Projects</title>
	<atom:link href="http://blog.localkinegrinds.com/category/projects/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.localkinegrinds.com</link>
	<description>Everything you&#039;ve ever thought, but never had the balls to say.</description>
	<lastBuildDate>Sat, 03 Sep 2011 13:19:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>For the Horde &#8211; DIY World of Warcraft Brownies</title>
		<link>http://blog.localkinegrinds.com/2010/08/05/for-the-horde-diy-world-of-warcraft-brownies/</link>
		<comments>http://blog.localkinegrinds.com/2010/08/05/for-the-horde-diy-world-of-warcraft-brownies/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 17:54:17 +0000</pubDate>
		<dc:creator>ryankanno</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Life]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://blog.localkinegrinds.com/?p=404</guid>
		<description><![CDATA[For the Horde &#8211; DIY World of Warcraft Brownies I noes I haven&#8217;t updated my blog in a few months more than a year, but I&#8217;ve been busy working at a small, local news startup. Since one of my New Year&#8217;s resolutions was to be a more diligent blogger, I thought I would start this [...]]]></description>
			<content:encoded><![CDATA[<h2>For the Horde &#8211; DIY World of Warcraft Brownies</h2>
<p>I noes I haven&#8217;t updated my blog in <del datetime="2010-01-15T02:55:15+00:00">a few months</del> more than a year, but I&#8217;ve been busy working at a small, <a href="http://www.civilbeat.com">local news startup</a>.  Since one of my New Year&#8217;s resolutions was to be a more diligent blogger, I thought I would start this year off with a *whiz-bang*, non-technical post!</p>
<p>(I guess it&#8217;s pretty ironic that I&#8217;m posting this in <del datetime="2010-07-01T02:24:02+00:00">January</del> August, huh? <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> )</p>
<p>Last December, I was invited to a Christmas Party.  Not your standard-fare holiday party, mind you, but a &#8220;World of Warcraft Guild&#8221; Christmas Party. Wanting to bring something unique to the potluck, I ended up making &#8220;For The Horde Brownies&#8221;&#8230; and this is a blog detailing the experience.</p>
<h3>&#8250;&#8250; Setup</h3>
<ul>
<li>Your favorite brownie mix/recipe</li>
<li>Powdered sugar</li>
<li>Print out of the <a href='http://blog.localkinegrinds.com/wp-content/uploads/2010/08/for_the_horde.pdf'>For the Horde pdf</a></li>
<li>X-Acto knife (or scissors)</li>
</ul>
<h3>&#8250;&#8250; Baking the brownies</h3>
<p>I&#8217;ll be the first to admit that I&#8217;m no baker.  While there are those that profess it as their passion, I see it purely as a means to an end.  With that said, you can use &lt;insert your favorite brownie mix here&gt; to make the brownies or if you&#8217;re feeling exceptionally adventurous, maybe use <a href="http://coffeetea.about.com/od/miscchocolate/r/chocbrownie.htm">one</a> of these <a href="http://www.recipegirl.com/2010/02/01/deep-dark-brownies-2/">recipes</a>.  Whatever your poison, just make sure it appears edible &#8211; enough to trick your guests with; kind of like this.</p>
<p><a href="http://farm5.static.flickr.com/4068/4277348635_3f1182e650.jpg" title="Your favorite brownie mix" rel="lightbox"><img alt="Your favorite brownie mix" src="http://farm5.static.flickr.com/4068/4277348635_3f1182e650_m.jpg" class="thumb" style="float: left; "></a></p>
<p><a href="http://farm5.static.flickr.com/4054/4278095010_be616f499f.jpg" title="The magical concoction!" rel="lightbox"><img alt="The magical concoction!" src="http://farm5.static.flickr.com/4054/4278095010_be616f499f_m.jpg" class="thumb" style="float: left; "></a></p>
<p><a href="http://farm5.static.flickr.com/4032/4277348763_b6dd064d42.jpg" title="Pulling the wool over sheep's eyes" rel="lightbox"><img alt="Pulling the wool over sheep's eyes" src="http://farm5.static.flickr.com/4032/4277348763_b6dd064d42_m.jpg" class="thumb" style="float: left;"></a></p>
<div style="clear:both;">&nbsp;</div>
<h3>&#8250;&#8250; Preparing the Horde symbol</h3>
<p>While baking your magical brownies, print out the <a href='http://blog.localkinegrinds.com/wp-content/uploads/2010/08/for_the_horde.pdf'>enclosed Horde pdf</a>.  You&#8217;ll want to make a few copies to practice your X-Acto skills on.  Of course, if your scissor-fu is amazing, feel free to wield those instead.  (It took me two tries with the X-Acto to get it just right).  After you&#8217;ve finished removing the Horde symbol, it should resemble the following:</p>
<p><a href="http://farm3.static.flickr.com/2756/4278095122_9035e6f154.jpg" title="Horde symbol" rel="lightbox"><img alt="Horde symbol" src="http://farm3.static.flickr.com/2756/4278095122_9035e6f154_m.jpg" style="float: left; " class="thumb"></a></p>
<p><a href="http://farm3.static.flickr.com/2771/4277348879_21c5c71c9e.jpg" title="Horde symbol cutout" rel="lightbox"><img alt="Horde symbol cutout" src="http://farm3.static.flickr.com/2771/4277348879_21c5c71c9e_m.jpg" style="float: left; " class="thumb"></a></p>
<div style="clear:both;">&nbsp;</div>
<h3>&#8250;&#8250; For the Horde!</h3>
<p>After you have a cut out of the Horde symbol, you can use the powdered sugar to apply the symbol to your brownies.  If you mess up, like I did, fret not.  </p>
<div class="bold info">Pro-tip: if the powdered sugar goes awol, use some water to dissolve the sugar and clean up the edges.</div>
<p><a href="http://farm5.static.flickr.com/4070/4278095224_9e72201d4d.jpg" title="Practice Run" rel="lightbox"><img alt="Practice Run" src="http://farm5.static.flickr.com/4070/4278095224_9e72201d4d_m.jpg" style="float: left;" class="thumb"></a></p>
<p><a href="http://farm3.static.flickr.com/2695/4278095290_0f9f603b82.jpg" title="Applying the symbol" rel="lightbox"><img alt="Applying the symbol" src="http://farm3.static.flickr.com/2695/4278095290_0f9f603b82_m.jpg" style="float: left;" class="thumb"></a></p>
<div style="clear:both;">&nbsp;</div>
<p><strong>Your final product should end up looking something like the following:</strong></p>
<p><a href="http://farm5.static.flickr.com/4011/4278095328_9525d6c343.jpg" title="For the Horde" rel="lightbox"><img alt="For the Horde" src="http://farm5.static.flickr.com/4011/4278095328_9525d6c343_m.jpg" style="float: left; " class="thumb"></a></p>
<div style="clear:both;">&nbsp;</div>
<h2>Voila!</h2>
<h3>&#8250;&#8250; Credits</h3>
<p>As usual, I must give props where props are due.</p>
<h4>People I owe a soul to</h4>
<ul>
<li><a href="http://www.twitter.com/sarakata">@sarakata</a> for the wonderful idea (and baking the brownies)</li>
<li><a href="http://www.twitter.com/pwnies">@pwnies</a> for the magical <a href="http://blog.localkinegrinds.com/wp-content/uploads/2010/08/for_the_horde.svg">Horde svg image file</a></li>
<li><a href="http://www.twitter.com/mirthlab">@mirthlab</a> for creating the <a href='http://blog.localkinegrinds.com/wp-content/uploads/2010/08/for_the_horde.pdf'>Horde pdf file</a></li>
<li>Last but not least, all the smarties on the Illlist who gave me a myriad of suggestions on how to accomplish this</li>
</ul>
<img src="http://blog.localkinegrinds.com/?ak_action=api_record_view&id=404&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.localkinegrinds.com/2010/08/05/for-the-horde-diy-world-of-warcraft-brownies/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ERB block comments in RHTML templates using Ruby on Rails</title>
		<link>http://blog.localkinegrinds.com/2008/05/02/erb-block-comments-in-rhtml-templates-using-ruby-on-rails/</link>
		<comments>http://blog.localkinegrinds.com/2008/05/02/erb-block-comments-in-rhtml-templates-using-ruby-on-rails/#comments</comments>
		<pubDate>Fri, 02 May 2008 14:05:23 +0000</pubDate>
		<dc:creator>ryankanno</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[block comment]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[comment]]></category>
		<category><![CDATA[erb]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[rhtml]]></category>
		<category><![CDATA[ror]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://blog.localkinegrinds.com/?p=169</guid>
		<description><![CDATA[This blog is simply a reminder to myself more than anything else. After searching the great Googs and reading here, here, and here about commenting out regions in your RHTML templates, I couldn&#8217;t find a (good) solution aside from the () paradigm. Using Rails 1.2.3 (I know, I know&#8230; we&#8217;re old school), to get block [...]]]></description>
			<content:encoded><![CDATA[<div class="bold info">This blog is simply a reminder to myself more than anything else.</div>
<p>After <a href="http://www.google.com/search?q=rhtml+comments&#038;ie=utf-8&#038;oe=utf-8&#038;aq=t&#038;rls=org.mozilla:en-US:official&#038;client=firefox-a">searching the great Googs</a> and reading <a href="http://www.neeraj.name/229/commenting-out-the-code-in-rhtml">here</a>, <a href="http://lists.netisland.net/archives/phillyonrails/phillyonrails-2005/msg00083.html">here</a>, and <a href="http://www.nabble.com/Re:-RHTML-comments-p12844273s27020.html">here</a> about commenting out regions in your RHTML templates, I couldn&#8217;t find a (good) solution aside from the (<... if false ...>) paradigm.  Using Rails 1.2.3 (I know, I know&#8230; we&#8217;re <a href="www.urbandictionary.com/define.php?term=old+school">old school</a>), to get block comments in Rails, the following worked for me, but unfortunately, still wasn&#8217;t recognized by <a href="http://www.netbeans.org/ ">NetBeans</a> 6.0 (Boo!).</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
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">&lt;table&gt;
  ...
  &lt;tbody&gt;
    &lt;tr id=&quot;<span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#996600;">&quot;photographer_#{photographer.id}&quot;</span><span style="color:#006600; font-weight:bold;">%&gt;</span>&quot;&gt;
      &lt;td&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span> 
<span style="color:#000080; font-style:italic;">=begin %&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%</span>= h photographer.<span style="color:#9900CC;">first_name</span> <span style="color:#9966CC; font-weight:bold;">unless</span> photographer.<span style="color:#9900CC;">blank</span>? <span style="color:#006600; font-weight:bold;">%&gt;&lt;%</span> 
=<span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
  ...
&lt;/table&gt;</pre></td></tr></table></div>

<h2>Happy Coding!</h2>
<img src="http://blog.localkinegrinds.com/?ak_action=api_record_view&id=169&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.localkinegrinds.com/2008/05/02/erb-block-comments-in-rhtml-templates-using-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Google App Engine on Win2K (using django-yui-layout-templates)</title>
		<link>http://blog.localkinegrinds.com/2008/04/17/google-app-engine-on-win2k-using-django-yui-layout-templates/</link>
		<comments>http://blog.localkinegrinds.com/2008/04/17/google-app-engine-on-win2k-using-django-yui-layout-templates/#comments</comments>
		<pubDate>Thu, 17 Apr 2008 10:38:38 +0000</pubDate>
		<dc:creator>ryankanno</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[appengine]]></category>
		<category><![CDATA[django-yui-layout-templates]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[yahoo!-ui]]></category>
		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://blog.localkinegrinds.com/?p=171</guid>
		<description><![CDATA[Update : September 1, 2008 I guess Googs finally caught on as their 1.1.2 installer works on Win2K! FTW! Update After finally getting time to play around with the Google App Engine Django helpers, here&#8217;s a few more steps to integrate nicely with the helper suite. Move the appengine installation from C:\AppEngine\ to where the [...]]]></description>
			<content:encoded><![CDATA[<h3>Update : September 1, 2008</h3>
<p>I guess Googs finally caught on as their <a href="http://googleappengine.googlecode.com/files/GoogleAppEngine_1.1.2.msi">1.1.2 installer</a> works on Win2K!  FTW!</p>
<hr/>
<h3>Update</h3>
<p>After finally getting time to play around with the <a href="http://code.google.com/p/google-app-engine-django/">Google App Engine Django helpers</a>, here&#8217;s a few more steps to integrate nicely with the helper suite.  </p>
<ul>
<li>Move the appengine installation from C:\AppEngine\ to where the Windows installer would have installed it to: <strong>C:\Program Files\Google\google_appengine</strong> (make sure to clean up your .pyc files)
<li>Add the following to your PYTHONPATH system variable: <strong>%APPENGINE%\;%APPENGINE%\lib;%APPENGINE%\lib\yaml\lib;%APPENGINE%\lib\webob;</strong></li>
</ul>
<p>After <a href="http://code.google.com/appengine/articles/appengine_helper_for_django.html">following the instructions</a>, you should be good to go with <a href="http://www.djangoproject.com">Django</a> + <a href="http://code.google.com/appengine/">AppEngine</a>! FTW! Whee. <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<hr/>
So I finally get an hour or so to play around with the <a href="http://code.google.com/appengine/">Googs App Engine</a> and luckily for me, all my machines decided to puke except for my Windows 2000 Server.  How ironic is that?  In disbelief, I downloaded <a href="http://code.google.com/appengine/downloads.html">the Google App Engine SDK Windows installer</a> and what do I get?</p>
<p class="center">
<a href='http://blog.localkinegrinds.com/wp-content/uploads/2008/04/google_windows_installer.jpg' rel="lightbox" title="h.a.t.e.r.a.d.e I tell you"><img src="http://blog.localkinegrinds.com/wp-content/uploads/2008/04/google_windows_installer-300x231.jpg" alt="Google App Engine Windows installer" title="google_windows_installer" width="300" height="231" class="thumb"/></a>
</p>
<h4>I sense some pure, unadultered haterade. (j/k)</h4>
<p>Since <a href="http://www.python.org">Python</a> is one of those insert_any_synonym_for_fun languages that just works, here&#8217;s how to get the Google App Engine SDK working in Win2K.  </p>
<ul>
<li><a href="http://code.google.com/appengine/downloads.html">Download</a> the Linux/Other platform package and unzip to somewhere neat.</li>
<li>Add a System Environment variable called &#8216;APP_ENGINE_HOME&#8217; that points to your App Engine installation.  (Notice, I installed mine into <strong>C:\AppEngine</strong>)
<p class="center"><a href='http://blog.localkinegrinds.com/wp-content/uploads/2008/04/system_variable.jpg' rel="lightbox" title="Adding a system environment variable"><img src="http://blog.localkinegrinds.com/wp-content/uploads/2008/04/system_variable-259x300.jpg" alt="Add system variable" title="Add system variable" width="259" height="300" class="thumb" /></a></p>
</li>
<li>Add the System Environment variable to your System Path so the Windows shell can execute the included Python files.</li>
<li>Make sure you have .py files associated with the python.exe executable located in your Python installation.  (Check file types under folder options)</li>
<li>Follow the tutorials: <a href="http://code.google.com/appengine/docs/gettingstarted/">here</a> and <a href="http://www.42topics.com/dumps/django/docs.html">here</a>, or <a href="http://www.appenginebase.com/">learn with others</a> &#8211; just to name a few.</li>
<li>Oh, and before I forget, if you develop an application and realize that you can&#8217;t kill the development appserver (<strong>dev_appserver.py</strong>) by pressing Ctrl-C, I <a href="http://boodebr.org/main/python/cherrypy-under-google-appserver">found a solution here</a>.  Basically, press Ctrl-C, hit the server with your browser one more time and voila, the development application server dies.  Thanks Frank!</li>
</ul>
<h3>As an added bonus&#8230;</h3>
<div class="info">Checkout my <a href="http://blog.localkinegrinds.com/2008/03/21/yahoo-ui-yui-django-templates-google-code-project-ftw/">my previous post</a> using the <a href="http://developer.yahoo.com/yui/">Yahoo UI library</a> to create a set of default <a href="http://http://www.djangoproject.com/documentation/templates/">Django templates</a>.  I&#8217;ve updated <a href="http://code.google.com/p/django-yui-layout-templates/"><strong>django-yui-layout-templates</strong></a> with patches and suggestions, and I&#8217;ve also created a few branches to support the Googly App Engine.  Check out the <a href="http://django-yui-layout-templates.googlecode.com/svn/branches/">branches directory in the Subversion repository</a>!</div>
<h3>Last but not least&#8230;</h3>
<p>Big ups to <a href="http://fitz.blogspot.com/">Mr. Fitz</a> for solving all my Google App Engine issues and thanks to <a href="http://www.nata2.org/">Mr. Harper</a> for causing them. <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<h2>Voila! (Enjoy)</h2>
<img src="http://blog.localkinegrinds.com/?ak_action=api_record_view&id=171&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.localkinegrinds.com/2008/04/17/google-app-engine-on-win2k-using-django-yui-layout-templates/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Yahoo! UI (YUI) + Django templates == Google Code project! FTW!</title>
		<link>http://blog.localkinegrinds.com/2008/03/21/yahoo-ui-yui-django-templates-google-code-project-ftw/</link>
		<comments>http://blog.localkinegrinds.com/2008/03/21/yahoo-ui-yui-django-templates-google-code-project-ftw/#comments</comments>
		<pubDate>Fri, 21 Mar 2008 19:56:50 +0000</pubDate>
		<dc:creator>ryankanno</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[base-css]]></category>
		<category><![CDATA[fonts-css]]></category>
		<category><![CDATA[grids-css]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[reset-css]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[yahoo!-ui]]></category>
		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://blog.localkinegrinds.com/2008/03/21/yahoo-ui-yui-django-templates-google-code-project-ftw/</guid>
		<description><![CDATA[Let me first preface this blog by saying that I&#8217;m not a designer. When it comes to art and creativity, I&#8217;m so left brained, I actually wonder if my right brain even partakes in the process. Three things spurred me to release django-yui-layout-templates. I&#8217;ve always wanted to see what GoogleCode offered in relation to SourceForge [...]]]></description>
			<content:encoded><![CDATA[<div class="disclaimer"><b>Let me first preface this blog by saying that I&#8217;m not a designer.</b>  When it comes to art and creativity, I&#8217;m so left brained, I actually wonder if my right brain even partakes in the process.</div>
<h3>Three things spurred me to release <a href="http://code.google.com/p/django-yui-layout-templates/">django-yui-layout-templates</a>.</h3>
<ol>
<li>I&#8217;ve always wanted to see what <a href="http://code.google.com/">GoogleCode</a> offered in relation to <a href="http://sourceforge.net/">SourceForge</a> / <a href="http://www.rubyforge.org/">RubyForge</a>.</li>
<li>I&#8217;m so caught up in corporate America staring at Java / Ruby code all day, not only haven&#8217;t I blogged about anything <a href="http://www.djangoproject.com/">Django</a> related in quite a while, but it&#8217;s nice to get some commentary from the community, i.e. &#8220;your code sucks&#8221;. (Brings me back to reality)</li>
<li>I found myself using the same templates on a variety of projects and figured that I could do my part and help eliminate unncessary cruft/duplication.</li>
</ol>
<p>So without further adieu, check out the project <a href="http://code.google.com/p/django-yui-layout-templates/">here</a>.  I know, I know &#8211; nothing revolutionary here, but I figure since Django is <a href="http://antoniocangiano.com/2008/03/20/djangos-tipping-point/">picking up some steam</a>, these templates might help a Djangonaut get a head start on their next million dollar idea. <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Voila! Enjoy!</h2>
<img src="http://blog.localkinegrinds.com/?ak_action=api_record_view&id=166&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.localkinegrinds.com/2008/03/21/yahoo-ui-yui-django-templates-google-code-project-ftw/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Upgrading your DVR: How to increase your DVR&#8217;s recording time</title>
		<link>http://blog.localkinegrinds.com/2008/02/01/upgrading-dvr-with-more-recording-time/</link>
		<comments>http://blog.localkinegrinds.com/2008/02/01/upgrading-dvr-with-more-recording-time/#comments</comments>
		<pubDate>Fri, 01 Feb 2008 10:05:14 +0000</pubDate>
		<dc:creator>ryankanno</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[8300hd]]></category>
		<category><![CDATA[dvr]]></category>
		<category><![CDATA[hawaii]]></category>
		<category><![CDATA[recording-time]]></category>
		<category><![CDATA[scientific-atlanta]]></category>
		<category><![CDATA[upgrade]]></category>

		<guid isPermaLink="false">http://blog.localkinegrinds.com/2008/02/01/upgrading-dvr-with-more-recording-time/</guid>
		<description><![CDATA[This blog is for all my Hawaii television addicts. Since I rarely have time to watch live television, my Oceanic Time Warner DVR is constantly filled to max capacity. This means I&#8217;m always battling my inner demons on what shows I have to erase&#8230; Rock of Love, A Shot at Love, Flavor of Love&#8230; you [...]]]></description>
			<content:encoded><![CDATA[<h2>This blog is for all my Hawaii television addicts.</h2>
<p>Since I rarely have time to watch live television, my <a href="http://www.oceanic.com/OceanicWebApps/Index.html">Oceanic Time Warner</a> DVR is constantly filled to max capacity.  This means I&#8217;m always battling my inner demons on what shows I have to erase&#8230; <a href="http://blog.vh1.com/2007-12-20/rock-of-love-2-first-look/">Rock of Love</a>, <a href="http://remotecontrol.mtv.com/2007/11/28/a-shot-at-love-recap-episode-8-lap-dance-granny/">A Shot at Love</a>, <a href="http://blog.vh1.com/2007-08-03/flavor-flavs-backwith-a-new-taste/">Flavor of Love</a>&#8230; you know, all the good stuff.  To solve my problem, I&#8217;ve finally decided to invest the $150 to upgrade my DVR and increase its total number of recording hours.</p>
<h4>Luckily for you, I&#8217;ll walk you through the steps to upgrade your own DVR!</h4>
<p style="width:95%; font-size:1em; background-color:#ffeeee; border:1px solid #990000; padding:1.5em; margin:1em 0;">
As a standard disclaimer, if you attempt to upgrade your own DVR and f-it up, I can&#8217;t and won&#8217;t fix it.  So&#8230; if technology scares you, please parents, do not try this unless supervised by your technology-oriented youngster.  If you don&#8217;t understand what SATA, external enclosures, or hard drives mean, do not, and I repeat <strong>do not try this at home!</strong>
</p>
<h3>The setup</h3>
<p>Before you can upgrade your DVR, you&#8217;ll need to make sure that you have the <a href="http://www.scientificatlanta.com/products/consumers/new_explorer8300HD.htm">Scientific Atlanta Explorer 8300HD</a>.  Just match what your DVR looks like to the one in the picture.  It&#8217;s not that hard.  This is what mine looks like: <a href='http://blog.localkinegrinds.com/wp-content/uploads/2008/01/cimg10500014.jpg' title='The front of my DVR' rel="lightbox">the front</a> and <a href='http://blog.localkinegrinds.com/wp-content/uploads/2008/01/cimg09170003.jpg' title='The back of my DVR' rel="lightbox">the back</a>. I do know for a fact that Oceanic has a few versions of their cable boxes out in the wild.  I&#8217;m pretty sure you can upgrade (some of) the other models as well, but I&#8217;ve personally only upgraded the 8300HD.  So if you want to be ballsy and upgrade a different cable box, feel totally free &#8211; just be warned that this guide won&#8217;t apply to you.  I&#8217;m not even sure if you can still turn in your old cable box because of the <a href="http://the.honoluluadvertiser.com/article/2007/Dec/17/ln/hawaii712170349.html">demand for HDTV in Hawaii</a>, but calling up Oceanic can&#8217;t hurt.</p>
<p>Aside from owning an 8300HD, you&#8217;ll need three additional components to make this upgrade work.  I&#8217;ve included links to where I purchased the following items.  Fear not, I don&#8217;t make any commissions on these links so feel free to buy these products from anywhere you see fit.  </p>
<ul>
<li>1 external SATA enclosure (I used a <a href="http://shop4.outpost.com/product/4573757;jsessionid=WwPVfJx9HgljtUbOWPH75Q**.node2?site=sr:SEARCH:MAIN_RSLT_PG">KingWin from Fry&#8217;s</a> for 30 bucks.)</li>
<li>1 SATA/IDE harddrive (I used a <a href="http://shop4.outpost.com/%7B2Qbw-GvA+uzSPeJ1taMJHQ**.node2%7D/product/4551377">Maxtor 500 GB</a> for about a 100.)</li>
<li>1 SATA to eSATA cable (I used a <a href="http://www.monoprice.com/products/product.asp?c_id=102&#038;cp_id=10226&#038;cs_id=1022603&#038;p_id=3750&#038;seq=1&#038;format=2">6 ft cable from Monoprice.com</a> for 5 bucks.)</li>
</ul>
<p>Here are a few pictures of the aforementioned items.</p>
<p style="text-align:center; margin:auto;">
<a href='http://blog.localkinegrinds.com/wp-content/uploads/2008/01/cimg10200005.jpg' title='External SATA enclosure' rel="lightbox[requirements]"><img src='http://blog.localkinegrinds.com/wp-content/uploads/2008/01/cimg10200005.thumbnail.jpg' alt='External SATA enclosure' class="thumb"/></a><a href='http://blog.localkinegrinds.com/wp-content/uploads/2008/01/cimg09060001.jpg' title='Maxtor SATA 500 GB hard drive' rel="lightbox[requirements]"><img src='http://blog.localkinegrinds.com/wp-content/uploads/2008/01/cimg09060001.thumbnail.jpg' alt='Maxtor SATA 500 GB hard drive' class="thumb"/></a><a href='http://blog.localkinegrinds.com/wp-content/uploads/2008/01/cimg10340008.jpg' title='eSATA to SATA cable' rel="lightbox[requirements]"><img src='http://blog.localkinegrinds.com/wp-content/uploads/2008/01/cimg10340008.thumbnail.jpg' alt='eSATA to SATA cable' class="thumb"/></a><a href='http://blog.localkinegrinds.com/wp-content/uploads/2008/01/cimg10280006.jpg' title='Everything unpacked!' rel="lightbox[requirements]"><img src='http://blog.localkinegrinds.com/wp-content/uploads/2008/01/cimg10280006.thumbnail.jpg' alt='Everything unpacked!' class="thumb"/></a>
</p>
<h3>The results</h3>
<p>First, make sure your 8300HD is turned off.  Place the hard drive into the external enclosure.  Next, after <a href='http://blog.localkinegrinds.com/wp-content/uploads/2008/01/cimg09180004.jpg' title='Connecting the hard drive to the dvr' rel="lightbox">connecting the external SATA enclosure to the 8300HD</a> (with the SATA to eSATA cable), power the external hard drive before turning the DVR box back on.  Note, it&#8217;s extremely important that the external SATA enclosure be turned on prior to the cable box being powered on.  Once booted, the 8300HD should recognize a new, external data source and prompt you to format the new drive.  The following message should appear:</p>
<p><a href='http://blog.localkinegrinds.com/wp-content/uploads/2008/01/cimg10400011.jpg' title='Format hard drive prompt' rel="lightbox"><img src='http://blog.localkinegrinds.com/wp-content/uploads/2008/01/cimg10400011.thumbnail.jpg' alt='Format hard drive prompt' class="thumb" /></a></p>
<p>Once formatted, you should see a success message:</p>
<p><a href='http://blog.localkinegrinds.com/wp-content/uploads/2008/01/cimg10410012.jpg' title='Format success!' rel="lightbox"><img src='http://blog.localkinegrinds.com/wp-content/uploads/2008/01/cimg10410012.thumbnail.jpg' alt='Format success!' class="thumb"/></a></p>
<h2>Voila! DVR Upgraded!</h2>
<h3>The benes</h3>
<p>There are numerous benefits to increasing your DVR&#8217;s total recording time.</p>
<ul>
<li>No more having to rush home because you forgot the DVR is full.</li>
<li>No more making those life-altering decisions about what movies to delete.</li>
<li>Being able to store almost a year&#8217;s worth of reality crap is fun!</li>
</ul>
<p>Of course, there&#8217;s the almost 4X increase in the DVR&#8217;s recording time as you can see by the  following before and after pictures.  Not bad!</p>
<p style="text-align:center; margin:auto;">
<a href='http://blog.localkinegrinds.com/wp-content/uploads/2008/01/cimg10380009.jpg' title='Before upgrade' rel="lightbox[results]"><img src='http://blog.localkinegrinds.com/wp-content/uploads/2008/01/cimg10380009.thumbnail.jpg' alt='Before upgrade' class="thumb"/></a><a href='http://blog.localkinegrinds.com/wp-content/uploads/2008/01/cimg10420013.jpg' title='After upgrade' rel="lightbox[results]"><img src='http://blog.localkinegrinds.com/wp-content/uploads/2008/01/cimg10420013.thumbnail.jpg' alt='After upgrade' class="thumb"/></a>
</p>
<h3>The cons</h3>
<p>There&#8217;s no such thing as a free pass in life&#8230; so here are a few of the cons.</p>
<ul>
<li>As I wrote earlier, the <strong style="font-size:110%;">external hard drive needs to be powered on before your cable box.</strong>  This means one of two things.  Either you always turn the external drive on first or leave it on permanently.  Since I know I could never remember to do the former, I&#8217;ve decided to leave the device on permanently &#8211; meaning a slightly larger electricity bill.  As someone trying to get off the grid, that makes me sad.</li>
<li>You can&#8217;t rip the recorded video off the external hard drive.  Unfortunately, the <a href="http://www.google.com/search?q=8300hd+encrypted&#038;ie=utf-8&#038;oe=utf-8&#038;aq=t&#038;rls=org.mozilla:en-US:official&#038;client=firefox-a">data is encrypted</a>.  Unless you&#8217;re a cryptographic expert, worked on the 8300HD, or have a few <a href="http://en.wikipedia.org/wiki/Beowulf_(computing)">Beowulf clusters</a>, deal with it.  You won&#8217;t be able to share your recordings.</li>
<li>$150 bucks is a lot to spend on easing one&#8217;s mind, but I think it&#8217;s money well spent considering the prices <a href="http://www.weaknees.com/maxtor-quickview-expander-qvx.php">here</a> and <a href="http://discountechnology.com/8300HD-eSATA-Hard-Drive-for-Scientific-Atlanta-8300HD-DVR-250GB?category=12">here</a>.
</ul>
<h3>Some linkage</h3>
<p>Of course I couldn&#8217;t have upgraded my DVR without the Internet.  Here&#8217;s a link to the forums and guides I read to assist me along the way.  Check them out, some of them are quite interesting.</p>
<ul>
<li><a href="http://www.scientificatlanta.com/ExplorerClubGuides/getting_started/4003870.pdf">Scientific Atlanta 8300HD User Guide</a></li>
<li><a href="http://www.avsforum.com/avs-vb/showthread.php?t=471859">AVSForum&#8217;s SA 8300 HD Tips &#038; Tricks &#8212; SARA thread</a></li>
<li><a href="http://baseportal.com/cgi-bin/baseportal.pl?htx=/xnappo/main">Scientific Atlanta 8300HD SARA eSATA Database</a></li>
</ul>
<p>Finally, check out <a href="http://flickr.com/photos/ryankanno/sets/72157603820776544/">my flickr set</a> if you need to see any more pictures!</p>
<h2>Enjoy!</h2>
<img src="http://blog.localkinegrinds.com/?ak_action=api_record_view&id=151&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.localkinegrinds.com/2008/02/01/upgrading-dvr-with-more-recording-time/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Using the extra() QuerySet modifier in Django for WeGoEat</title>
		<link>http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/</link>
		<comments>http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/#comments</comments>
		<pubDate>Wed, 24 Oct 2007 15:17:01 +0000</pubDate>
		<dc:creator>ryankanno</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[extra]]></category>
		<category><![CDATA[hawaii]]></category>
		<category><![CDATA[queryset]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[wegoeat]]></category>

		<guid isPermaLink="false">http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/</guid>
		<description><![CDATA[Since I actually used this method to reduce the number of Update:&#8221;explicit&#8221; SQL calls made in WeGoEat, I figured I&#8217;d write a little blog explaining the context in which it was used, and maybe, just maybe, it&#8217;ll help shed some light on how others can take advantage of this neat little function. Background As a [...]]]></description>
			<content:encoded><![CDATA[<p>Since I actually used this method to reduce the number of <strong>Update:&#8221;explicit&#8221;</strong> SQL calls made in <a href="http://www.wegoeat.com">WeGoEat</a>, I figured I&#8217;d write a little blog explaining the context in which it was used, and maybe, just maybe, it&#8217;ll help shed some light on how others can take advantage of this neat little function.</p>
<h2>Background</h2>
<p>As a <a href="http://www.djangoproject.com">Django</a> &#8220;proof-of-concept&#8221;, I&#8217;m working on a <a href="http://www.wegoeat.com/">local restaurant review site</a> for my home state of Hawai`i.  (I actually just released it yesterday).  For each restaurant, I want to be able to calculate the average of all reviews and <a href="http://www.wegoeat.com/restaurants/browse/by/island/oahu/page/1/records/50/">display this listing in a paginated view</a>.  (<em>Yes, I do realize there&#8217;s no average rating, but that has to do with there being no users. ;P</em>).</p>
<h2>The Problem</h2>
<p>Having a serious &#8220;wtf was I thinking moment&#8221;, I initially wrote a Restaurant model function that returned the average (review) rating for each restaurant instance.  Little did I realize that when I actually displayed the restaurant&#8217;s average reviews, I would be making an additional SQL avg() call for <strong>every</strong> restaurant.  Though I&#8217;m paging &#8220;n&#8221; records at a time, this function added an additional &#8220;n&#8221; SQL calls for <a href="http://www.wegoeat.com/restaurants/browse/by/letter/a/page/1/records/50/">every</a> <a href="http://www.wegoeat.com/restaurants/browse/by/letter/b/page/1/records/50/">view</a> <a href="http://www.wegoeat.com/restaurants/browse/by/letter/c/page/1/records/50/">that</a> <a href="http://www.wegoeat.com/restaurants/browse/by/letter/d/page/1/records/50/">contained</a> <a href="http://www.wegoeat.com/restaurants/browse/by/letter/g/page/1/records/50/">a restaurant</a> <a href="http://www.wegoeat.com/restaurants/browse/by/letter/h/page/1/records/50/">listing</a>, just to name a few.</p>
<p>In pseudo-code, my initial naive function resembled the following:  (I&#8217;m sure we&#8217;re all guilty of writing something of the sort&#8230; ok, fine, I know I was. ;P)</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> get_average_review<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
         query = <span style="color: #483d8b;">'QUERY TO GET AVERAGE (SELECT AVG(rating)...); (I have the query below)'</span>
         <span style="color: #808080; font-style: italic;"># Get cursor from connection</span>
        cursor = connection.<span style="color: black;">cursor</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        cursor.<span style="color: black;">execute</span><span style="color: black;">&#40;</span>query<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> cursor.<span style="color: black;">fetchall</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p><strong>Duh.</strong></p>
<p>Here&#8217;s a picture of the number of queries it took:</p>
<div style="text-align:center; padding:1.5em;"><img src='http://blog.localkinegrinds.com/wp-content/uploads/2007/10/duh.jpg' alt='Duh' style="border:1px solid #aaa;"/></div>
<h2>The &#8220;extra()&#8221; solution</h2>
<p>After profiling my application and realizing what a bone-headed mistake I made, I began researching the <a href="http://www.djangoproject.com/documentation/db-api/#extra-select-none-where-none-params-none-tables-none">extra() Queryset modifier</a>.  Yes, I realize that these extra lookups aren&#8217;t the most portable and often violate the DRY principle, but it&#8217;ll probably suffice for <strike>most of</strike> all my personal projects. <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Since I&#8217;m already retrieving a list of Restaurants and filtering them via <a href="http://wegoeat.com/restaurants/browse/by/letter/">letter</a>, <a href="http://wegoeat.com/restaurants/browse/by/island/">island</a>, and <a href="http://wegoeat.com/restaurants/browse/">what not</a>, I figured I could add an average rating subquery.  The entire call looks as such:</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="python" style="font-family:monospace;">     restaurants = Restaurant.<span style="color: black;">objects</span>.<span style="color: #008000;">filter</span><span style="color: black;">&#40;</span>name__istartswith = letter<span style="color: black;">&#41;</span>.<span style="color: black;">extra</span><span style="color: black;">&#40;</span>
             <span style="color: #dc143c;">select</span>=<span style="color: black;">&#123;</span><span style="color: #483d8b;">'avg_rating'</span>: <span style="color: #483d8b;">'SELECT AVG(overall_rating) FROM restaurants_restaurant as res, reviews_review, django_content_type <span style="color: #000099; font-weight: bold;">\</span>
                                          WHERE restaurants_restaurant.id = res.id <span style="color: #000099; font-weight: bold;">\</span>
                                          AND res.id = reviews_review.object_id <span style="color: #000099; font-weight: bold;">\</span>
                                          AND reviews_review.content_type_id = django_content_type.id <span style="color: #000099; font-weight: bold;">\</span>
                                          AND django_content_type.model = <span style="color: #000099; font-weight: bold;">\'</span>restaurant<span style="color: #000099; font-weight: bold;">\'</span>'</span><span style="color: black;">&#125;</span>,
                       <span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>As you can see, I&#8217;m exploiting the fact that restaurants_restaurant will be available from the Restaurant.objects.filter() call.  (I know, I know&#8230; bad for portability).</p>
<h2>But voila!</h2>
<p>Now, in my templates, when I iterate over the restaurants, I can get issue the following:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: black;">&#123;</span><span style="color: #66cc66;">%</span> <span style="color: #ff7700;font-weight:bold;">for</span> restaurant <span style="color: #ff7700;font-weight:bold;">in</span> restaurant_list <span style="color: #66cc66;">%</span><span style="color: black;">&#125;</span>
<span style="color: #66cc66;">&lt;</span>tr<span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;</span>td<span style="color: #66cc66;">&gt;&lt;</span>a href=<span style="color: #483d8b;">&quot;{{restaurant.get_absolute_url}}&quot;</span><span style="color: #66cc66;">&gt;</span><span style="color: black;">&#123;</span><span style="color: black;">&#123;</span> restaurant.<span style="color: black;">name</span> <span style="color: black;">&#125;</span><span style="color: black;">&#125;</span><span style="color: #66cc66;">&lt;</span>/a<span style="color: #66cc66;">&gt;&lt;</span>/td<span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;</span>td<span style="color: #66cc66;">&gt;</span><span style="color: black;">&#123;</span><span style="color: #66cc66;">%</span> <span style="color: #ff7700;font-weight:bold;">if</span> restaurant.<span style="color: black;">avg_rating</span> <span style="color: #66cc66;">%</span><span style="color: black;">&#125;</span>
	   <span style="color: black;">&#123;</span><span style="color: #66cc66;">%</span> load show_stars <span style="color: #66cc66;">%</span><span style="color: black;">&#125;</span> 
           <span style="color: #66cc66;">&lt;</span>span <span style="color: #ff7700;font-weight:bold;">class</span>=<span style="color: #483d8b;">&quot;average-rating&quot;</span><span style="color: #66cc66;">&gt;</span>
	   <span style="color: black;">&#123;</span><span style="color: #66cc66;">%</span> show_stars <span style="color: #66cc66;">&lt;</span>strong<span style="color: #66cc66;">&gt;</span>restaurant.<span style="color: black;">avg_rating</span><span style="color: #66cc66;">&lt;</span>/strong<span style="color: #66cc66;">&gt;</span> of <span style="color: #ff4500;">5</span> <span style="color: #008000;">round</span> to quarter <span style="color: #66cc66;">%</span><span style="color: black;">&#125;</span>
           <span style="color: #66cc66;">&lt;</span>/span<span style="color: #66cc66;">&gt;</span>
           <span style="color: black;">&#123;</span><span style="color: #66cc66;">%</span> endif <span style="color: #66cc66;">%</span><span style="color: black;">&#125;</span><span style="color: #66cc66;">&lt;</span>/td<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>/tr<span style="color: #66cc66;">&gt;</span>
<span style="color: black;">&#123;</span><span style="color: #66cc66;">%</span> endfor <span style="color: #66cc66;">%</span><span style="color: black;">&#125;</span></pre></td></tr></table></div>

<p>Notice how I used my <a href="http://blog.localkinegrinds.com/2007/10/02/displaying-stars-with-rounding-as-a-django-templatetag/">show_stars template tag</a> that I blogged about a few weeks ago to display the average restaurant rating.  (Cheap shameless plug, but damn effective! <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> )  I&#8217;d link to a page in action, but since I just opened up my site to a few select users, I&#8217;ll update this post when I actually have any reviews. <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p>Oh, and before I forget, thanks to my co-worker Stephen for assisting me with my SQL issues! <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Here&#8217;s a picture of the final result:</p>
<div style="text-align:center; padding:1.5em;"><img src='http://blog.localkinegrinds.com/wp-content/uploads/2007/10/yay.jpg' alt='Yay'  style="border:1px solid #aaa;"/></div>
<h2>Note:</h2>
<p>As an added bonus, I also realized a few other &#8216;spots&#8217; where the .extra() Queryset modifier would come in handy.  Since I&#8217;m also using the wonderful <a href="http://code.google.com/p/django-voting/">django-voting</a> application from <a href="http://insin.webfactional.com/weblog/">Jonathan Buchanan</a>, I came across <a href="http://groups.google.com/group/django-users/browse_thread/thread/119b5d6581d43dc6/671a25f972a082ed">this post about accessing a dictionary via a template</a> in the <a href="http://groups.google.com/group/django-users">Django-users Google Group</a>.</p>
<p>Basically, I had come across the same issue as the poster.  Since I allow users to vote on reviews (similar to <a href="http://www.amazon.com">Amazon</a>, <a href="http://www.yelp.com">Yelp</a>, etc.), I wanted to retrieve the score of each Review instance to display on a <a href="http://www.wegoeat.com/reviews/browse/latest/">paginated listing of all Reviews</a>.  Using the same extra() modifier, I was able to inject the total number of votes and the score when I retrieved all Reviews as such:</p>
<p><strong>Btw, I just injected most of the code from Jonathan&#8217;s template tag. <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">.<span style="color: black;">extra</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">select</span>=<span style="color: black;">&#123;</span><span style="color: #483d8b;">'total_votes'</span>: <span style="color: #483d8b;">'SELECT COUNT(vote) FROM votes as v, reviews_review as rev, django_content_type <span style="color: #000099; font-weight: bold;">\</span>
                                        WHERE reviews_review.id = rev.id <span style="color: #000099; font-weight: bold;">\</span>
                                        AND v.object_id = reviews_review.id <span style="color: #000099; font-weight: bold;">\</span>
                                        AND v.content_type_id = django_content_type.id <span style="color: #000099; font-weight: bold;">\</span>
                                        AND django_content_type.model = <span style="color: #000099; font-weight: bold;">\'</span>review<span style="color: #000099; font-weight: bold;">\'</span>'</span>, 
&nbsp;
                                        <span style="color: #483d8b;">'score'</span>: <span style="color: #483d8b;">'SELECT SUM(vote) FROM votes as v, reviews_review as rev, django_content_type <span style="color: #000099; font-weight: bold;">\</span>
                                        WHERE reviews_review.id = rev.id <span style="color: #000099; font-weight: bold;">\</span>
                                        AND v.object_id = reviews_review.id <span style="color: #000099; font-weight: bold;">\</span>
                                        AND v.content_type_id = django_content_type.id <span style="color: #000099; font-weight: bold;">\</span>
                                        AND django_content_type.model = <span style="color: #000099; font-weight: bold;">\'</span>review<span style="color: #000099; font-weight: bold;">\'</span>'</span><span style="color: black;">&#125;</span>,<span style="color: black;">&#41;</span></pre></td></tr></table></div>

<h3>Pretty neat right?</h3>
<p>Now, when iterating through the reviews, I can use the following:</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
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: black;">&#123;</span><span style="color: #66cc66;">%</span> <span style="color: #ff7700;font-weight:bold;">for</span> review <span style="color: #ff7700;font-weight:bold;">in</span> object_list <span style="color: #66cc66;">%</span><span style="color: black;">&#125;</span>
	<span style="color: #66cc66;">&lt;</span>tr<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>td<span style="color: #66cc66;">&gt;&lt;</span>a href=<span style="color: #483d8b;">&quot;{{review.content_object.get_absolute_url}}&quot;</span><span style="color: #66cc66;">&gt;</span><span style="color: black;">&#123;</span><span style="color: black;">&#123;</span> review.<span style="color: black;">content_object</span>.<span style="color: black;">name</span> <span style="color: black;">&#125;</span><span style="color: black;">&#125;</span><span style="color: #66cc66;">&lt;</span>/a<span style="color: #66cc66;">&gt;&lt;</span>/td<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>td<span style="color: #66cc66;">&gt;&lt;</span>a href=<span style="color: #483d8b;">&quot;{% url profile-detail username=review.user.username %}&quot;</span><span style="color: #66cc66;">&gt;</span><span style="color: black;">&#123;</span><span style="color: black;">&#123;</span> review.<span style="color: #dc143c;">user</span>.<span style="color: black;">username</span> <span style="color: black;">&#125;</span><span style="color: black;">&#125;</span><span style="color: #66cc66;">&lt;</span>/a<span style="color: #66cc66;">&gt;&lt;</span>/td<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>td<span style="color: #66cc66;">&gt;&lt;</span>nobr<span style="color: #66cc66;">&gt;</span><span style="color: black;">&#123;</span><span style="color: #66cc66;">%</span> load show_stars <span style="color: #66cc66;">%</span><span style="color: black;">&#125;</span>
			<span style="color: #66cc66;">&lt;</span>span <span style="color: #ff7700;font-weight:bold;">class</span>=<span style="color: #483d8b;">&quot;rating&quot;</span><span style="color: #66cc66;">&gt;</span><span style="color: black;">&#123;</span><span style="color: #66cc66;">%</span> show_stars review.<span style="color: black;">overall_rating</span> of <span style="color: #ff4500;">5</span> <span style="color: #008000;">round</span> to half <span style="color: #66cc66;">%</span><span style="color: black;">&#125;</span><span style="color: #66cc66;">&lt;</span>/span<span style="color: #66cc66;">&gt;</span>
			<span style="color: #66cc66;">&lt;</span>/nobr<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>/td<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>td<span style="color: #66cc66;">&gt;&lt;</span>span style=<span style="color: #483d8b;">&quot;font-weight:bold; color:#092e20;&quot;</span><span style="color: #66cc66;">&gt;</span><span style="color: black;">&#123;</span><span style="color: black;">&#123;</span> review.<span style="color: black;">get_recommendation_display</span> <span style="color: black;">&#125;</span><span style="color: black;">&#125;</span><span style="color: #66cc66;">&lt;</span>/span<span style="color: #66cc66;">&gt;&lt;</span>/td<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>td<span style="color: #66cc66;">&gt;&lt;</span>span style=<span style="color: #483d8b;">&quot;font-size:.875em;&quot;</span><span style="color: #66cc66;">&gt;</span><span style="color: black;">&#123;</span><span style="color: black;">&#123;</span> review.<span style="color: black;">submit_date</span>|timesince <span style="color: black;">&#125;</span><span style="color: black;">&#125;</span> ago<span style="color: #66cc66;">&lt;</span>/span<span style="color: #66cc66;">&gt;&lt;</span>/td<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>strong<span style="color: #66cc66;">&gt;&lt;</span>td<span style="color: #66cc66;">&gt;</span>Total of <span style="color: black;">&#123;</span><span style="color: black;">&#123;</span> review.<span style="color: black;">score</span>|default:<span style="color: #ff4500;">0</span> <span style="color: black;">&#125;</span><span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: black;">&#123;</span><span style="color: black;">&#123;</span> review.<span style="color: black;">total_votes</span> <span style="color: black;">&#125;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: black;">&#123;</span>  review.<span style="color: black;">total_votes</span>|pluralize:<span style="color: #483d8b;">&quot;person,people&quot;</span> <span style="color: black;">&#125;</span><span style="color: black;">&#125;</span>.<span style="color: #66cc66;">&lt;</span>/td<span style="color: #66cc66;">&gt;&lt;</span>/strong<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>/tr<span style="color: #66cc66;">&gt;</span>
<span style="color: black;">&#123;</span><span style="color: #66cc66;">%</span> endfor <span style="color: #66cc66;">%</span><span style="color: black;">&#125;</span></pre></td></tr></table></div>

<p>Hope y&#8217;all learned something like I did! <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   Oh, and before I forget my standard disclaimer, &#8220;since this is on my blog, feel free to take/use/steal/distribute/copy/modify any code you see fit, but if you find any bugs, have any comments, or think the code can be cleaner, Iâ€™d love to hear from you.&#8221;</p>
<h2>Enjoy!</h2>
<img src="http://blog.localkinegrinds.com/?ak_action=api_record_view&id=136&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Calling all (Django) programmers&#8230; (I need advice)</title>
		<link>http://blog.localkinegrinds.com/2007/10/10/calling-all-django-programmers-i-need-advice/</link>
		<comments>http://blog.localkinegrinds.com/2007/10/10/calling-all-django-programmers-i-need-advice/#comments</comments>
		<pubDate>Thu, 11 Oct 2007 06:41:23 +0000</pubDate>
		<dc:creator>ryankanno</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[hash-table]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://blog.localkinegrinds.com/2007/10/10/calling-all-django-programmers-i-need-advice/</guid>
		<description><![CDATA[Update According to Max, it&#8217;s against Facebook&#8217;s TOS to cache the data. I&#8217;ve totally must&#8217;ve skipped over it in the TOS&#8230; ok, fine&#8230; I admit, I didn&#8217;t even read it. Thanks Max! And to think this response was less than an hour after my post! Yay, community. In any case, this problem is still relevant [...]]]></description>
			<content:encoded><![CDATA[<h3>Update</h3>
<p>According to <a href="http://www.worldmaker.net/">Max</a>, it&#8217;s against <a href="http://developers.facebook.com/documentation.php?v=1.0&#038;doc=misc">Facebook&#8217;s TOS</a> to cache the data.  I&#8217;ve totally must&#8217;ve skipped over it in the TOS&#8230; ok, fine&#8230; I admit, I didn&#8217;t even read it.  Thanks Max!  And to think this response was less than an hour after my post!  Yay, community.  In any case, this problem is still relevant to many a graph-structured sites.  Comment on!</p>
<hr />
<p>Since I don&#8217;t know of many techies in Hawaii, I figured I would post a blog in hopes of attracting a solution from the <a href="http://www.eyeofhawaii.com/Pidgin/pidgin.htm">akamai</a> <a href="http://www.djangoproject.com/community/">Django community</a>.</p>
<h2>The Background</h2>
<p>I&#8217;m currently writing a <a href="http://www.facebook.com">Facebook</a> application in <a href="http://www.djangoproject.com">Django</a> (which I&#8217;ll be blogging about later).  </p>
<h2>The Problem</h2>
<p>I want to be able to programatically tell if you&#8217;ve updated your friends in Facebook.  Basically, at the end of the day, Facebook provides an <a href="http://wiki.developers.facebook.com/index.php/API">API</a> call that allows you to retrieve a list of uid&#8217;s that represent your &#8216;friends&#8217;.  I&#8217;m planning to cache this data within my own system.    I was wondering how <a href="http://en.wikipedia.org/wiki/Python_philosophy">Pythonic</a> people would solve the following:</p>
<p>Is there a data type or algorithm (or combination thereof) I can use to compare the returned uids with my uid data cache?  This comparison algorithm will tell me if you&#8217;ve added or subtracted new friends in Facebook.  As a bonus, I&#8217;d prefer this comparison optimized (for Python).</p>
<h2>Possible Solutions</h2>
<p>So I&#8217;ve sat down and made a list of possible solutions:</p>
<ul>
<li>Creating an in memory hash from my cached data and seeing which Facebook API returned uids collide and which don&#8217;t. <span style="font-weight:bold; color:#006600;">(EASY)</span></li>
<li>Using SET comparison in MySQL. <span style="font-weight:bold; color:#006600;">(EASY)</span></li>
<li>Possibly encoding the uids in a way to optimize the comparison of two sets; though I&#8217;d have to research this. <span style="font-weight:bold; color:#990000;">(EW)</span></li>
<li>&#8230;? (Your input goes here)</li>
</ul>
<p><strong>Btw, I&#8217;d never thought I&#8217;d say this, but without <a href="http://www.amazon.com/Introduction-Algorithms-Second-Thomas-Cormen/dp/0262531968">CLR</a>, I feel so lost. ;P</strong></p>
<p>Like I wrote in <a href="http://blog.localkinegrinds.com/2007/10/02/displaying-stars-with-rounding-as-a-django-templatetag/">my last post</a>, a few years out of grad school and a bunch of web applications later, and I&#8217;m really, really rusty.  In any case, feel free to leave any comments/ideas and I&#8217;ll be sure to credit you for your solution! </p>
<img src="http://blog.localkinegrinds.com/?ak_action=api_record_view&id=135&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.localkinegrinds.com/2007/10/10/calling-all-django-programmers-i-need-advice/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Displaying stars (with rounding) as a Django templatetag</title>
		<link>http://blog.localkinegrinds.com/2007/10/02/displaying-stars-with-rounding-as-a-django-templatetag/</link>
		<comments>http://blog.localkinegrinds.com/2007/10/02/displaying-stars-with-rounding-as-a-django-templatetag/#comments</comments>
		<pubDate>Wed, 03 Oct 2007 05:15:44 +0000</pubDate>
		<dc:creator>ryankanno</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[leah-culver]]></category>
		<category><![CDATA[pownce]]></category>
		<category><![CDATA[rounded-stars]]></category>
		<category><![CDATA[template-tag]]></category>
		<category><![CDATA[templatetag]]></category>

		<guid isPermaLink="false">http://blog.localkinegrinds.com/2007/10/02/displaying-stars-with-rounding-as-a-django-templatetag/</guid>
		<description><![CDATA[Since my last post was quite popular (by my simple blogging standards), I&#8217;ve decided to post another Django snippet that I&#8217;ve used while coding WeGoEat. (I know, I know&#8230; one of these days I&#8217;ll finish. I&#8217;ve just been really, really lazy busy.) After reading Leah&#8217;s blog (of Pownce fame) about &#8220;rounding to the nearest half&#8221;, [...]]]></description>
			<content:encoded><![CDATA[<p>Since <a href="http://blog.localkinegrinds.com/2007/09/06/digg-style-pagination-in-django/">my last post</a> was <a href="http://del.icio.us/url/f60c41652684b40dc55c0a1b91262f6f">quite popular</a> (by my simple blogging standards), I&#8217;ve decided to post another <a href="http://djangoproject.com">Django</a> snippet that I&#8217;ve used while coding <a href="http://www.wegoeat.com">WeGoEat</a>. (<em>I know, I know&#8230; one of these days I&#8217;ll finish.  I&#8217;ve just been really, really <strike>lazy</strike> busy.</em>)</p>
<p>After reading <a href="http://leahculver.com/2007/04/19/star-ratings/">Leah&#8217;s blog</a> (of <a href="http://www.pownce.com">Pownce</a> fame) about &#8220;rounding to the nearest half&#8221;, I was immediately struck by two sobering realities:</p>
<ol>
<li>I would need that exact same algorithm for my current site.</li>
<li>A few years out of grad school, and I couldn&#8217;t even begin to fathom a solution. Thank you, Internet.</li>
</ol>
<p>In any case, I figured I&#8217;d wrap my solution into a template tag that people could use/steal/copy.  Here&#8217;s a generated test page that illustrates what my template tag would display.</p>
<p><img src='http://blog.localkinegrinds.com/wp-content/uploads/2007/10/stars.jpg' alt='Stars!' /></p>
<p>You can even customize the display a bit:</p>
<p><img src='http://blog.localkinegrinds.com/wp-content/uploads/2007/10/25stars.jpg' alt='25 Stars!' /></p>
<p>I know, I know&#8230; I can do a lot better. <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />   In any case, here&#8217;s the code snippet that I placed in a file called show_stars.py:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">math</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">template</span> <span style="color: #ff7700;font-weight:bold;">import</span> Library, Node, TemplateSyntaxError, VariableDoesNotExist, resolve_variable
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">conf</span> <span style="color: #ff7700;font-weight:bold;">import</span> settings
&nbsp;
register = Library<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
IMG_TEMPLATE = <span style="color: #483d8b;">'&lt;img src=&quot;%s&quot; alt=&quot;%s&quot;/&gt;'</span>
&nbsp;
PATH_TO_WHOLE_STAR = IMG_TEMPLATE <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>settings.<span style="color: black;">MEDIA_URL</span> + <span style="color: #483d8b;">'img/stars/star.png'</span>, <span style="color: #483d8b;">&quot;Whole Star&quot;</span><span style="color: black;">&#41;</span>
PATH_TO_THREE_QUARTER_STAR = IMG_TEMPLATE <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>settings.<span style="color: black;">MEDIA_URL</span> + <span style="color: #483d8b;">'img/stars/three-quarter.png'</span>, <span style="color: #483d8b;">&quot;3/4 Star&quot;</span><span style="color: black;">&#41;</span>
PATH_TO_HALF_STAR = IMG_TEMPLATE <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>settings.<span style="color: black;">MEDIA_URL</span> + <span style="color: #483d8b;">'img/stars/half.png'</span>, <span style="color: #483d8b;">&quot;1/2 Star&quot;</span><span style="color: black;">&#41;</span>
PATH_TO_QUARTER_STAR = IMG_TEMPLATE <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>settings.<span style="color: black;">MEDIA_URL</span> + <span style="color: #483d8b;">'img/stars/quarter.png'</span>, <span style="color: #483d8b;">&quot;1/4 Star&quot;</span><span style="color: black;">&#41;</span>
PATH_TO_BLANK_STAR = IMG_TEMPLATE <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>settings.<span style="color: black;">MEDIA_URL</span> + <span style="color: #483d8b;">'img/stars/blank.png'</span>, <span style="color: #483d8b;">&quot;Empty Star&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> ShowStarsNode<span style="color: black;">&#40;</span>Node<span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot; Default rounding is to the whole unit &quot;&quot;&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, context_var, total_stars, round_to<span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">context_var</span> = context_var
        <span style="color: #008000;">self</span>.<span style="color: black;">total_stars</span> = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>total_stars<span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">round_to</span> = round_to.<span style="color: black;">lower</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> render<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, context<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">try</span>:
            stars = resolve_variable<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">context_var</span>, context<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">except</span> VariableDoesNotExist:
            <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">''</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">self</span>.<span style="color: black;">round_to</span> == <span style="color: #483d8b;">&quot;half&quot;</span>:
            stars = <span style="color: #008000;">round</span><span style="color: black;">&#40;</span>stars<span style="color: #66cc66;">*</span><span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>/<span style="color: #ff4500;">2</span>
        <span style="color: #ff7700;font-weight:bold;">elif</span> <span style="color: #008000;">self</span>.<span style="color: black;">round_to</span> == <span style="color: #483d8b;">&quot;quarter&quot;</span>:
            stars = <span style="color: #008000;">round</span><span style="color: black;">&#40;</span>stars<span style="color: #66cc66;">*</span><span style="color: #ff4500;">4</span><span style="color: black;">&#41;</span>/<span style="color: #ff4500;">4</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            stars = <span style="color: #008000;">round</span><span style="color: black;">&#40;</span>stars<span style="color: black;">&#41;</span>
&nbsp;
        fraction, integer = <span style="color: #dc143c;">math</span>.<span style="color: black;">modf</span><span style="color: black;">&#40;</span>stars<span style="color: black;">&#41;</span>
        integer = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>integer<span style="color: black;">&#41;</span>
        output = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">for</span> whole_star <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>integer<span style="color: black;">&#41;</span>:
            output.<span style="color: black;">append</span><span style="color: black;">&#40;</span>PATH_TO_WHOLE_STAR<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">self</span>.<span style="color: black;">round_to</span> == <span style="color: #483d8b;">'half'</span> <span style="color: #ff7700;font-weight:bold;">and</span> fraction == .5:
            output.<span style="color: black;">append</span><span style="color: black;">&#40;</span>PATH_TO_HALF_STAR<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">elif</span> <span style="color: #008000;">self</span>.<span style="color: black;">round_to</span> == <span style="color: #483d8b;">'quarter'</span>:
            <span style="color: #ff7700;font-weight:bold;">if</span> fraction == .25:
                output.<span style="color: black;">append</span><span style="color: black;">&#40;</span>PATH_TO_QUARTER_STAR<span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">elif</span> fraction == .5:
                output.<span style="color: black;">append</span><span style="color: black;">&#40;</span>PATH_TO_HALF_STAR<span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">elif</span> fraction == .75:
                output.<span style="color: black;">append</span><span style="color: black;">&#40;</span>PATH_TO_THREE_QUARTER_STAR<span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">if</span> fraction:
            integer += <span style="color: #ff4500;">1</span>
&nbsp;
        blanks = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">total_stars</span> - integer<span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">for</span> blank_star <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>blanks<span style="color: black;">&#41;</span>:
            output.<span style="color: black;">append</span><span style="color: black;">&#40;</span>PATH_TO_BLANK_STAR<span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;&quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>output<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #483d8b;">&quot;&quot;&quot; show_stars context_var of 5 round to half &quot;&quot;&quot;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> do_show_stars<span style="color: black;">&#40;</span><span style="color: #dc143c;">parser</span>, <span style="color: #dc143c;">token</span><span style="color: black;">&#41;</span>:
    args = <span style="color: #dc143c;">token</span>.<span style="color: black;">contents</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>args<span style="color: black;">&#41;</span> <span style="color: #66cc66;">!</span>= <span style="color: #ff4500;">7</span>:
        <span style="color: #ff7700;font-weight:bold;">raise</span> TemplateSyntaxError<span style="color: black;">&#40;</span><span style="color: #483d8b;">'%s tag requires exactly six arguments'</span> <span style="color: #66cc66;">%</span> args<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: #ff7700;font-weight:bold;">if</span> args<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">'of'</span>:
        <span style="color: #ff7700;font-weight:bold;">raise</span> TemplateSyntaxError<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;second argument to '%s' tag must be 'of'&quot;</span> <span style="color: #66cc66;">%</span> args<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: #ff7700;font-weight:bold;">if</span> args<span style="color: black;">&#91;</span><span style="color: #ff4500;">4</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">'round'</span>:
        <span style="color: #ff7700;font-weight:bold;">raise</span> TemplateSyntaxError<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;fourth argument to '%s' tag must be 'round'&quot;</span> <span style="color: #66cc66;">%</span> args<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: #ff7700;font-weight:bold;">if</span> args<span style="color: black;">&#91;</span><span style="color: #ff4500;">5</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">'to'</span>:
        <span style="color: #ff7700;font-weight:bold;">raise</span> TemplateSyntaxError<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;fourth argument to '%s' tag must be 'to'&quot;</span> <span style="color: #66cc66;">%</span> args<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: #ff7700;font-weight:bold;">return</span> ShowStarsNode<span style="color: black;">&#40;</span>args<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>, args<span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span>, args<span style="color: black;">&#91;</span><span style="color: #ff4500;">6</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>   
&nbsp;
register.<span style="color: black;">tag</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'show_stars'</span>, do_show_stars<span style="color: black;">&#41;</span></pre></div></div>

<p>I&#8217;ve also <a href='http://blog.localkinegrinds.com/wp-content/uploads/2007/10/stars.zip' title='Stars.zipped'>wrapped up the star graphics</a> I used.  A big ups to the <a href="http://www.famfamfam.com/lab/icons/silk/">Silk Icons</a> creator. <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />   For those of you that don&#8217;t care for <a href="http://blog.localkinegrinds.com/wp-content/uploads/2007/10/stars.zip">.zip files</a>, here&#8217;s all the star images I used:</p>
<p><img src='http://blog.localkinegrinds.com/wp-content/uploads/2007/10/blank.png' alt='Blank' /><img src='http://blog.localkinegrinds.com/wp-content/uploads/2007/10/quarter.png' alt='quarter' /><img src='http://blog.localkinegrinds.com/wp-content/uploads/2007/10/half.png' alt='half' /><img src='http://blog.localkinegrinds.com/wp-content/uploads/2007/10/three-quarter.png' alt='three quarter' /><img src='http://blog.localkinegrinds.com/wp-content/uploads/2007/10/star.png' alt='full' /></p>
<p>To use the tag, itâ€™ll look something like this in your templates:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: black;">&#123;</span><span style="color: #66cc66;">%</span> load show_stars <span style="color: #66cc66;">%</span><span style="color: black;">&#125;</span>
     <span style="color: black;">&#123;</span><span style="color: #66cc66;">%</span> show_stars context_var of <span style="color: #ff4500;">5</span> <span style="color: #008000;">round</span> to half <span style="color: #66cc66;">%</span><span style="color: black;">&#125;</span>
<span style="color: black;">&#123;</span><span style="color: #66cc66;">%</span> endif <span style="color: #66cc66;">%</span><span style="color: black;">&#125;</span></pre></div></div>

<p><strong>Note:</strong> You can change the following:</p>
<ol>
<li>context_var is whatever var contains the value you want rounded (it was &#8216;value&#8217; in the screenshots)</li>
<li>5 can be any integer; this is the maximum number of stars to display.  I should probably check to make sure you don&#8217;t put a number smaller than context_var, but I&#8217;ll leave that up to you. <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </li>
<li>half can be any of the following values: whole, half, or quarter</li>
<li>Make sure to edit the paths to the star files in the templatetag file</li>
</ol>
<p>And since this is on my blog, feel totally free to take/use/steal/distribute/copy/modify any code you see fit.  All I ask is if you find any bugs, have any comments, or can think of ways to make my ugly code cleaner &#8211; I&#8217;d love to hear from you. <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>Enjoy!</h3>
<img src="http://blog.localkinegrinds.com/?ak_action=api_record_view&id=124&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.localkinegrinds.com/2007/10/02/displaying-stars-with-rounding-as-a-django-templatetag/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Digg-style pagination in Django</title>
		<link>http://blog.localkinegrinds.com/2007/09/06/digg-style-pagination-in-django/</link>
		<comments>http://blog.localkinegrinds.com/2007/09/06/digg-style-pagination-in-django/#comments</comments>
		<pubDate>Thu, 06 Sep 2007 16:28:42 +0000</pubDate>
		<dc:creator>ryankanno</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[digg]]></category>
		<category><![CDATA[digg-style]]></category>
		<category><![CDATA[generic-list_object-view]]></category>
		<category><![CDATA[pagination]]></category>
		<category><![CDATA[paginatortag]]></category>

		<guid isPermaLink="false">http://blog.localkinegrinds.com/2007/09/06/digg-style-pagination-in-django/</guid>
		<description><![CDATA[Since I&#8217;ve finally been picked up by the Django community aggregator (Thanks Jacob!), I figured I&#8217;d put out a little snippet for people to use/critique; hopefully more use than critique. I really, really liked the PaginatorTag on the Django Wiki, but I&#8217;ve always wanted my sites to have configurable Digg-like behavior; if you wanna know [...]]]></description>
			<content:encoded><![CDATA[<p>Since I&#8217;ve finally been picked up by the <a href="http://www.djangoproject.com/community/">Django community aggregator</a> (Thanks <a href="http://www.jacobian.org/">Jacob!</a>), I figured I&#8217;d put out a little snippet for people to use/critique; hopefully more use than critique. <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />   I really, really liked the <a href="http://code.djangoproject.com/wiki/PaginatorTag">PaginatorTag on the Django Wiki</a>, but I&#8217;ve always wanted my sites to have configurable Digg-like behavior; if you wanna know what I&#8217;m talking about, just check out how pagination works on <a href="http://www.digg.com">Digg</a>.  </p>
<h3 style="margin:.5em 0em;">Here&#8217;s how the PaginatorTag looks compared to the Digg-style tags.</h3>
<p><img src='http://blog.localkinegrinds.com/wp-content/uploads/2007/09/pagination.gif' alt='Different paginators' /></p>
<p>Like the PaginatorTag, this tag is a very basic inclusion tag that builds on the variables already set on the context when paginating with the <a href="http://www.djangoproject.com/documentation/generic_views/#django-views-generic-list-detail-object-list">generic object_list view</a>.  There are a few additional context variables created:</p>
<ul>
<li><strong>page_numbers</strong> &#8211; a list of page numbers to display</li>
<li><strong>in_leading_range</strong> &#8211; boolean if the page is within the leading range</li>
<li><strong>in_trailing_range</strong> &#8211; boolean if the page is within the trailing range</li>
<li><strong>pages_outside_leading_range</strong> &#8211; a list of page numbers outside the leading range</li>
<li><strong>pages_outside_trailing_range</strong> &#8211; a list of page numbers outside the trailing range</li>
</ul>
<p>If you don&#8217;t understand what these are, don&#8217;t worry &#8211; I don&#8217;t remember either. <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />   I could&#8217;ve just appended what needed to be displayed in page_numbers, but instead, I broke it out into what needed to be displayed before and after the actual pages so one could customize the code a little more.  In any case, without further adieu, here&#8217;s the code snippet:</p>
<p>The first thing I did was create a file called digg_paginator.py.</p>

<div class="wp_syntax"><div 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
&nbsp;
register = template.<span style="color: black;">Library</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
LEADING_PAGE_RANGE_DISPLAYED = TRAILING_PAGE_RANGE_DISPLAYED = <span style="color: #ff4500;">10</span>
LEADING_PAGE_RANGE = TRAILING_PAGE_RANGE = <span style="color: #ff4500;">8</span>
NUM_PAGES_OUTSIDE_RANGE = <span style="color: #ff4500;">2</span> 
ADJACENT_PAGES = <span style="color: #ff4500;">4</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> digg_paginator<span style="color: black;">&#40;</span>context<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;is_paginated&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot; Initialize variables &quot;</span>
        in_leading_range = in_trailing_range = <span style="color: #008000;">False</span>
        pages_outside_leading_range = pages_outside_trailing_range = <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;pages&quot;</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">&lt;</span>= LEADING_PAGE_RANGE_DISPLAYED<span style="color: black;">&#41;</span>:
            in_leading_range = in_trailing_range = <span style="color: #008000;">True</span>
            page_numbers = <span style="color: black;">&#91;</span>n <span style="color: #ff7700;font-weight:bold;">for</span> n <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>, context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;pages&quot;</span><span style="color: black;">&#93;</span> + <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">if</span> n <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span> <span style="color: #ff7700;font-weight:bold;">and</span> n <span style="color: #66cc66;">&lt;</span>= context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;pages&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span>           
        <span style="color: #ff7700;font-weight:bold;">elif</span> <span style="color: black;">&#40;</span>context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;page&quot;</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">&lt;</span>= LEADING_PAGE_RANGE<span style="color: black;">&#41;</span>:
            in_leading_range = <span style="color: #008000;">True</span>
            page_numbers = <span style="color: black;">&#91;</span>n <span style="color: #ff7700;font-weight:bold;">for</span> n <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>, LEADING_PAGE_RANGE_DISPLAYED + <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">if</span> n <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span> <span style="color: #ff7700;font-weight:bold;">and</span> n <span style="color: #66cc66;">&lt;</span>= context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;pages&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span>
            pages_outside_leading_range = <span style="color: black;">&#91;</span>n + context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;pages&quot;</span><span style="color: black;">&#93;</span> <span style="color: #ff7700;font-weight:bold;">for</span> n <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, -NUM_PAGES_OUTSIDE_RANGE, -<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">elif</span> <span style="color: black;">&#40;</span>context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;page&quot;</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">&gt;</span> context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;pages&quot;</span><span style="color: black;">&#93;</span> - TRAILING_PAGE_RANGE<span style="color: black;">&#41;</span>:
            in_trailing_range = <span style="color: #008000;">True</span>
            page_numbers = <span style="color: black;">&#91;</span>n <span style="color: #ff7700;font-weight:bold;">for</span> n <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;pages&quot;</span><span style="color: black;">&#93;</span> - TRAILING_PAGE_RANGE_DISPLAYED + <span style="color: #ff4500;">1</span>, context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;pages&quot;</span><span style="color: black;">&#93;</span> + <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">if</span> n <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span> <span style="color: #ff7700;font-weight:bold;">and</span> n <span style="color: #66cc66;">&lt;</span>= context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;pages&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span>
            pages_outside_trailing_range = <span style="color: black;">&#91;</span>n + <span style="color: #ff4500;">1</span> <span style="color: #ff7700;font-weight:bold;">for</span> n <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, NUM_PAGES_OUTSIDE_RANGE<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>: 
            page_numbers = <span style="color: black;">&#91;</span>n <span style="color: #ff7700;font-weight:bold;">for</span> n <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;page&quot;</span><span style="color: black;">&#93;</span> - ADJACENT_PAGES, context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;page&quot;</span><span style="color: black;">&#93;</span> + ADJACENT_PAGES + <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">if</span> n <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span> <span style="color: #ff7700;font-weight:bold;">and</span> n <span style="color: #66cc66;">&lt;</span>= context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;pages&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span>
            pages_outside_leading_range = <span style="color: black;">&#91;</span>n + context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;pages&quot;</span><span style="color: black;">&#93;</span> <span style="color: #ff7700;font-weight:bold;">for</span> n <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, -NUM_PAGES_OUTSIDE_RANGE, -<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
            pages_outside_trailing_range = <span style="color: black;">&#91;</span>n + <span style="color: #ff4500;">1</span> <span style="color: #ff7700;font-weight:bold;">for</span> n <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, NUM_PAGES_OUTSIDE_RANGE<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#123;</span>
            <span style="color: #483d8b;">&quot;base_url&quot;</span>: context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;base_url&quot;</span><span style="color: black;">&#93;</span>,
            <span style="color: #483d8b;">&quot;is_paginated&quot;</span>: context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;is_paginated&quot;</span><span style="color: black;">&#93;</span>,
            <span style="color: #483d8b;">&quot;previous&quot;</span>: context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;previous&quot;</span><span style="color: black;">&#93;</span>,
            <span style="color: #483d8b;">&quot;has_previous&quot;</span>: context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;has_previous&quot;</span><span style="color: black;">&#93;</span>,
            <span style="color: #483d8b;">&quot;next&quot;</span>: context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;next&quot;</span><span style="color: black;">&#93;</span>,
            <span style="color: #483d8b;">&quot;has_next&quot;</span>: context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;has_next&quot;</span><span style="color: black;">&#93;</span>,
            <span style="color: #483d8b;">&quot;results_per_page&quot;</span>: context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;results_per_page&quot;</span><span style="color: black;">&#93;</span>,
            <span style="color: #483d8b;">&quot;page&quot;</span>: context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;page&quot;</span><span style="color: black;">&#93;</span>,
            <span style="color: #483d8b;">&quot;pages&quot;</span>: context<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;pages&quot;</span><span style="color: black;">&#93;</span>,
            <span style="color: #483d8b;">&quot;page_numbers&quot;</span>: page_numbers,
            <span style="color: #483d8b;">&quot;in_leading_range&quot;</span> : in_leading_range,
            <span style="color: #483d8b;">&quot;in_trailing_range&quot;</span> : in_trailing_range,
            <span style="color: #483d8b;">&quot;pages_outside_leading_range&quot;</span>: pages_outside_leading_range,
            <span style="color: #483d8b;">&quot;pages_outside_trailing_range&quot;</span>: pages_outside_trailing_range
        <span style="color: black;">&#125;</span>
&nbsp;
register.<span style="color: black;">inclusion_tag</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;digg_paginator.html&quot;</span>, takes_context=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span><span style="color: black;">&#40;</span>digg_paginator<span style="color: black;">&#41;</span></pre></div></div>

<p>To give a brief explanation of the file:</p>
<p><img src='http://blog.localkinegrinds.com/wp-content/uploads/2007/09/pagination-explanation.gif' alt='Explanation of pagination file' /></p>
<p>(LEADING_PAGE_RANGE and TRAILING_PAGE_RANGE is the number of pages before the views switch from the top view to the bottom view).</p>
<p>Also, there is a variable passed in from the view function called base_url which is basically the portion of the url before /page/.  Don&#8217;t worry, you&#8217;ll see what I mean after the template file.  Basically, I needed this url because I reconstruct the pagination links to:</p>
<p><strong>http://yoursite.com/model/page/page_number/records/num_records</strong></p>
<p>Next, I created a file called digg_paginator.html.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">{% spaceless %}
&nbsp;
{% if is_paginated %}
&lt;div class=&quot;paginator&quot;&gt;
{% if has_previous %}&lt;span class=&quot;prev&quot;&gt;&lt;a href=&quot;{{base_url}}/page/{{ previous }}/records/{{results_per_page}}&quot; title=&quot;Previous Page&quot;&gt;&amp;laquo; Previous&lt;/a&gt;&lt;/span&gt;{% else %}&lt;span class=&quot;prev-na&quot;&gt;&amp;laquo; Previous&lt;/span&gt;{% endif %}
&nbsp;
{% if not in_leading_range %}
	{% for num in pages_outside_trailing_range %}
		&lt;span class=&quot;page&quot;&gt;&lt;a href=&quot;{{base_url}}/page/{{ num }}/records/{{results_per_page}}&quot; &gt;{{ num }}&lt;/a&gt;&lt;/span&gt;
	{% endfor %}
	...
{% endif %}
&nbsp;
{% for num in page_numbers %}
  {% ifequal num page %}
    &lt;span class=&quot;curr&quot; title=&quot;Current Page&quot;&gt;{{ num }}&lt;/span&gt;
  {% else %}
  	&lt;span class=&quot;page&quot;&gt;&lt;a href=&quot;{{base_url}}/page/{{ num }}/records/{{results_per_page}}&quot; title=&quot;Page {{ num }}&quot;&gt;{{ num }}&lt;/a&gt;&lt;/span&gt;
  {% endifequal %}
{% endfor %}
&nbsp;
{% if not in_trailing_range %}
	...
	{% for num in pages_outside_leading_range reversed %}
		&lt;span class=&quot;page&quot;&gt;&lt;a href=&quot;{{base_url}}/page/{{ num }}/records/{{results_per_page}}&quot; &gt;{{ num }}&lt;/a&gt;&lt;/span&gt;
	{% endfor %}
{% endif %}
&nbsp;
{% if has_next %}&lt;span class=&quot;next&quot;&gt;&lt;a href=&quot;{{base_url}}/page/{{ next }}/records/{{results_per_page}}&quot; title=&quot;Next Page&quot;&gt;Next &amp;raquo;&lt;/a&gt;&lt;/span&gt;{% else %}&lt;span class=&quot;next-na&quot;&gt;Next &amp;raquo;&lt;/span&gt;{% endif %}
&lt;/div&gt; 
{% endif %}
&nbsp;
{% endspaceless %}</pre></div></div>

<p>Notice what the next, previous, and page urls look like.  You&#8217;ll have to make sure your urls.py file reflects this.  Here&#8217;s a snippet of what my urls.py looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">url<span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^browse/all/restaurants/page/(?P&lt;page&gt;[<span style="color: #000099; font-weight: bold;">\d</span>]+)/records/(?P&lt;records&gt;[<span style="color: #000099; font-weight: bold;">\d</span>]+)/$'</span>, restaurant_views.<span style="color: black;">browse_all</span><span style="color: black;">&#41;</span>,</pre></div></div>

<p>Finally, just so you can have the same Django-like color-scheme, here&#8217;s the relevant css.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/** PAGINATOR **/</span>
<span style="color: #6666ff;">.paginator</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">.5em</span> <span style="color: #933;">.75em</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">:</span><span style="color: #993333;">normal</span> <span style="color: #933;">.8em</span> arial<span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.paginator</span> .prev-na<span style="color: #00AA00;">,</span>
<span style="color: #6666ff;">.paginator</span> <span style="color: #6666ff;">.next-na</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">.3em</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">:</span><span style="color: #993333;">bold</span> <span style="color: #933;">.875em</span> arial<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.paginator</span> .prev-na<span style="color: #00AA00;">,</span>
<span style="color: #6666ff;">.paginator</span> <span style="color: #6666ff;">.next-na</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#f9f9f9</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#aaa</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.paginator</span> <span style="color: #6666ff;">.prev</span> a<span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.paginator</span> <span style="color: #6666ff;">.prev</span> a<span style="color: #3333ff;">:visited</span><span style="color: #00AA00;">,</span>
<span style="color: #6666ff;">.paginator</span> <span style="color: #6666ff;">.next</span> a<span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.paginator</span> <span style="color: #6666ff;">.next</span> a<span style="color: #3333ff;">:visited </span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#c2ee62</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#edfdd0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#234f32</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">.3em</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">:</span><span style="color: #993333;">bold</span> <span style="color: #933;">.875em</span> arial<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.paginator</span> <span style="color: #6666ff;">.prev</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.paginator</span> <span style="color: #6666ff;">.prev-na</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">.5em</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.paginator</span> <span style="color: #6666ff;">.next</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.paginator</span> <span style="color: #6666ff;">.next-na</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">.5em</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.paginator</span> .<span style="color: #000000; font-weight: bold;">page</span> a<span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.paginator</span> .<span style="color: #000000; font-weight: bold;">page</span> a<span style="color: #3333ff;">:visited</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.paginator</span> <span style="color: #6666ff;">.curr</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">.25em</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">:</span><span style="color: #993333;">normal</span> <span style="color: #933;">.875em</span> verdana<span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#C2EE62</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#EDFDD0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">0em</span> <span style="color: #933;">.25em</span><span style="color: #00AA00;">;</span>	
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#006000</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.paginator</span> <span style="color: #6666ff;">.curr</span> <span style="color: #00AA00;">&#123;</span> 
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#234f32</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#234f32</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">1em</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.paginator</span> .<span style="color: #000000; font-weight: bold;">page</span> a<span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">,</span>
<span style="color: #6666ff;">.paginator</span> <span style="color: #6666ff;">.curr</span> a<span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">,</span>
<span style="color: #6666ff;">.paginator</span> <span style="color: #6666ff;">.prev</span> a<span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">,</span>
<span style="color: #6666ff;">.paginator</span> <span style="color: #6666ff;">.next</span> a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#234f32</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#234f32</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Btw, I do realize that I didn&#8217;t do any checking of the variables in the digg_paginator.py.  I&#8217;m assuming that the developer won&#8217;t put in strange values.  (I know, I know &#8211; bad assumption).  If you wanna see what I&#8217;m talking about, try these values:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">LEADING_PAGE_RANGE_DISPLAYED = TRAILING_PAGE_RANGE_DISPLAYED = <span style="color: #ff4500;">10</span>
LEADING_PAGE_RANGE = TRAILING_PAGE_RANGE = <span style="color: #ff4500;">4</span>
NUM_PAGES_OUTSIDE_RANGE = <span style="color: #ff4500;">6</span>
ADJACENT_PAGES = <span style="color: #ff4500;">6</span></pre></div></div>

<p>Oh, one last thing.  To use the tag, it&#8217;ll look something like this in your templates:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: black;">&#123;</span><span style="color: #66cc66;">%</span> load utils.<span style="color: black;">paginator</span>.<span style="color: black;">digg_paginator</span> <span style="color: #66cc66;">%</span><span style="color: black;">&#125;</span>
<span style="color: black;">&#123;</span><span style="color: #66cc66;">%</span> digg_paginator <span style="color: #66cc66;">%</span><span style="color: black;">&#125;</span></pre></div></div>

<p>Oh, and since this is on my blog, feel free to take/use/steal/distribute/copy/modify any code you see fit, but since I threw this together in a few hours, if you find any bugs, have any comments, or think the code can be cleaner, I&#8217;d love to hear from you. <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>Enjoy!</h3>
<img src="http://blog.localkinegrinds.com/?ak_action=api_record_view&id=121&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.localkinegrinds.com/2007/09/06/digg-style-pagination-in-django/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>Yahoo! UI Grids &#8211; footerStickAlt (w/ jQuery goodness)</title>
		<link>http://blog.localkinegrinds.com/2007/06/30/yahoo-ui-grids-footerstickalt-w-jquery-goodness/</link>
		<comments>http://blog.localkinegrinds.com/2007/06/30/yahoo-ui-grids-footerstickalt-w-jquery-goodness/#comments</comments>
		<pubDate>Sat, 30 Jun 2007 22:17:51 +0000</pubDate>
		<dc:creator>ryankanno</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[dimensions]]></category>
		<category><![CDATA[footerStickAlt]]></category>
		<category><![CDATA[grids]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[yahoo]]></category>
		<category><![CDATA[yahoo!-ui]]></category>

		<guid isPermaLink="false">http://blog.localkinegrinds.com/2007/06/30/yahoo-ui-grids-footerstickalt-w-jquery-goodness/</guid>
		<description><![CDATA[My co-worker, Stephen, and I have implemented our layouts using the Yahoo! UI Grids library. One of the dilemmas we&#8217;ve been facing is the inability to use Cameron Adams&#8217; footerStickAlt CSS solution @ The Man In Blue. Basically, footerStickAlt is best described as sites that require the Web page footer to be positioned either at [...]]]></description>
			<content:encoded><![CDATA[<p>My co-worker, Stephen, and I have implemented our layouts using the <a href="http://developer.yahoo.com/yui/grids/">Yahoo! UI Grids </a>library.  One of the dilemmas we&#8217;ve been facing is the inability to use Cameron Adams&#8217; <a href="http://www.themaninblue.com/experiment/footerStickAlt/">footerStickAlt</a> CSS solution @ <a href="http://www.themaninblue.com/">The Man In Blue</a>.</p>
<p>Basically, footerStickAlt is best described as</p>
<blockquote><p>
sites that require the Web page footer to be positioned either at the bottom of the browser window or at the bottom of the Web page â€“ whichever is visually lowest.
</p></blockquote>
<p>Fast forward to the present, and using <a href="http://jquery.com/">JQuery</a>, <a href="http://jquery.com/plugins/project/dimensions">JQuery Dimensions plugin</a>, and a little nifty Javascript, we wrote up a solution at work for our Yahoo! layouts.  One thing to remember is that this solution won&#8217;t work in browsers with Javascript disabled, i.e. it degrades to whatever Yahoo! grid layout you&#8217;re using.</p>
<p>It&#8217;s been tested in <a href="http://www.microsoft.com/windows/products/winfamily/ie/default.mspx">IE</a> 5.5+ and <a href="http://www.mozilla.com/en-US/firefox/">Firefox</a> 2. (I think =P). </p>
<p>*<b>Note</b>*:  In this implementation, I don&#8217;t check for the margin on the &#8216;body&#8217; element since we&#8217;ve set all our margins and padding on <body> to 0.  See the demos for details.</p>
<h2 style="text-decoration:underline;">Requirements</h2>
<ol>
<li>Yahoo! UI Grids [<a href="http://developer.yahoo.com/yui/download/">download</a>]
<li>JQuery 1.1.2+ [<a href="http://code.jquery.com/jquery-latest.js">uncompressed</a>] [<a href="http://code.jquery.com/jquery-latest.pack.js">compressed</a>]</li>
<li>Dimensions plugin 1.0.0-b2 [<a href="http://jquery.com/plugins/files/dimensions-1.0b2.zip">zip</a>]</li>
<li>The Javascript below in a file of your choosing! Don&#8217;t forget to include it in your page!</li>
</ol>
<pre style="font-size:125%; background-color:#ffffee; border:1px solid #ccc; padding:1em;">
$(document).ready(function() {
     if ($(window).height() > $(document).height()) {
          $('#bd').css({
               height: $('#bd').height() +
                         ($(window).height() -
                          $(document).height()) + 'px'
          });
     }
});
</pre>
<p>Check out the demos here: <a href="http://www.localkinegrinds.com/demo/footerStickAlt/demo-short.html">page with short content</a>, <a href="http://www.localkinegrinds.com/demo/footerStickAlt/demo-long.html">page with long content</a>!</p>
<h3>Enjoy!</h3>
<img src="http://blog.localkinegrinds.com/?ak_action=api_record_view&id=109&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.localkinegrinds.com/2007/06/30/yahoo-ui-grids-footerstickalt-w-jquery-goodness/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: blog.localkinegrinds.com @ 2012-02-07 20:44:54 -->
