<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>The Bit Guru</title><link>http://www.thebitguru.com/blog/</link><description>thebitguru.com blog feed.</description><language>en-us</language><lastBuildDate>Thu, 02 Jul 2009 06:52:18 -0500</lastBuildDate><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/TheBitGuru" type="application/rss+xml" /><item><title>Firefox 3.5 upgrade didn&amp;#39;t import your passwords?
</title><link>http://feedproxy.google.com/~r/TheBitGuru/~3/QF2bZvpfERE/305-Firefox%203.5%20upgrade%20didn%27t%20import%20your%20passwords</link><description>&lt;div class="attachment_float_right"&gt;&lt;img src="/site_media/uploads/attachments/208_Firefox_PNG.png" alt="Firefox Logo" /&gt;&lt;/div&gt;

	&lt;p&gt;Yesterday I upgraded to Firefox 3.5 and noticed that my saved passwords didn&amp;#8217;t show up.  Instead it had a new &amp;#8220;password store,&amp;#8221; i.e. the ones that I was saving now were working fine, but the ones from 3.0 were lost.  After some research I ended up on &lt;a href="http://forums.mozillazine.org/viewtopic.php?f=23&amp;#38;t=1307985"&gt;this post&lt;/a&gt;.  So, Firefox 3.5 uses an &lt;a href="http://www.sqlite.org/"&gt;sqlite&lt;/a&gt; database (&lt;code&gt;signons.sqlite&lt;/code&gt;) to save passwords while 3.0 used a plain text file (&lt;code&gt;signons3.txt&lt;/code&gt;).  The normal upgrade process would have migrated your passwords correctly, but in my case I had Minefield (Firefox&amp;#8217;s dev version) installed before the developers got around to creating the migration script.  So, I had &lt;code&gt;signons.sqlite&lt;/code&gt; by the time I upgraded to the official release, which ended up leaving that as-is.  Anyways to fix this&amp;#8230;&lt;/p&gt;

	&lt;ol&gt;
		&lt;li&gt;Go to your profile folder &lt;code&gt;%APPDATA%/Mozilla/Firefox/Profiles/xxxxxxxx.default/&lt;/code&gt;&lt;/li&gt;
		&lt;li&gt;Make sure there is &lt;code&gt;signons3.txt&lt;/code&gt; in this folder.  This is your passwords files from Firefox 3.0.&lt;/li&gt;
		&lt;li&gt;Close any open Firefox windows.&lt;/li&gt;
		&lt;li&gt;Backup &lt;code&gt;signons.sqlite&lt;/code&gt; somewhere and remove it from this folder.&lt;/li&gt;
		&lt;li&gt;Restart Firefox.&lt;/li&gt;
	&lt;/ol&gt;

	&lt;p&gt;This should recreate signons.sqlite and your passwords should be recovered.  Have fun.&lt;/p&gt;


&lt;script src="http://feeds.feedburner.com/~s/TheBitGuru?i=/blog/view/305-Firefox%203.5%20upgrade%20didn%27t%20import%20your%20passwords?" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheBitGuru?a=QF2bZvpfERE:BtghBJ8z6uU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheBitGuru?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheBitGuru?a=QF2bZvpfERE:BtghBJ8z6uU:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheBitGuru?i=QF2bZvpfERE:BtghBJ8z6uU:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheBitGuru?a=QF2bZvpfERE:BtghBJ8z6uU:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheBitGuru?i=QF2bZvpfERE:BtghBJ8z6uU:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Farhan</dc:creator><pubDate>Thu, 02 Jul 2009 06:52:18 -0500</pubDate><guid isPermaLink="false">http://www.thebitguru.com/blog/view/305-Firefox%203.5%20upgrade%20didn%27t%20import%20your%20passwords?</guid><feedburner:origLink>http://www.thebitguru.com/blog/view/305-Firefox%203.5%20upgrade%20didn%27t%20import%20your%20passwords?</feedburner:origLink></item><item><title>Fake USB Drive
</title><link>http://feedproxy.google.com/~r/TheBitGuru/~3/tEfyCCxJvSE/304-Fake%20USB%20Drive</link><description>&lt;p&gt;Earlier today I went to the Pearl Market in Beijing to check out what kind of stuff they had.  Being a geek, electronics really got my attention, especially the prices.  I knew most of the stuff was fake and I had heard about &lt;span class="caps"&gt;USB&lt;/span&gt; drive capacity issues, but I wanted to experience it first hand :)  So, I went a head and bought a 16GB flash drive.  I had them plug it in and Windows reported 16GB.  I also had them copy some data, but it was interesting because as more and more files were being copied the seller was getting nervous.  I knew something was wrong.  I was still curious so I went ahead and purchased it anyways.  Once I got back to my room I decided to run a few tests and below are the results for your amusement.  Remember that this is supposed to be a 16GB drive :)&lt;/p&gt;

&lt;div class="attachment_float_right"&gt;&lt;a href="/site_media/uploads/attachments/207_fake_iphone.JPG" rel="lightbox" title="A Fake iPhone"&gt;&lt;img src="/site_media/uploads/attachments/resized/207_fake_iphone--200x200.jpg" alt="A Fake iPhone" /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;pre&gt;
Warning: Only 16138 of 16140 MByte tested.
The media is likely to be defective.
446.7 MByte OK (914944 sectors)
15.3 GByte DATA LOST (32135680 sectors)
Details:0 KByte overwritten (0 sectors)
0 KByte slightly changed (&amp;#60; 8 bit/sector, 0 sectors)
15.3 GByte corrupted (32135680 sectors)
0 KByte aliased memory (0 sectors)
First error at offset: 0x0000000000000008
Expected: 0x0000000000000011
Found: 0x0000000000000000
H2testw version 1.3
Writing speed: 19.0 MByte/s
Reading speed: 7.39 MByte/s
H2testw v1.4
&lt;/pre&gt;

	&lt;p&gt;Also, on the right side is a picture of a fake 8GB iPhone.&lt;/p&gt;


&lt;script src="http://feeds.feedburner.com/~s/TheBitGuru?i=/blog/view/304-Fake%20USB%20Drive" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheBitGuru?a=tEfyCCxJvSE:tTHvQmy3UyQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheBitGuru?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheBitGuru?a=tEfyCCxJvSE:tTHvQmy3UyQ:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheBitGuru?i=tEfyCCxJvSE:tTHvQmy3UyQ:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheBitGuru?a=tEfyCCxJvSE:tTHvQmy3UyQ:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheBitGuru?i=tEfyCCxJvSE:tTHvQmy3UyQ:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Farhan</dc:creator><pubDate>Wed, 24 Jun 2009 08:26:11 -0500</pubDate><guid isPermaLink="false">http://www.thebitguru.com/blog/view/304-Fake%20USB%20Drive</guid><feedburner:origLink>http://www.thebitguru.com/blog/view/304-Fake%20USB%20Drive</feedburner:origLink></item><item><title>Quick tip: Opening last window in Chrome
</title><link>http://feedproxy.google.com/~r/TheBitGuru/~3/W1hdZCPfCQ8/303-Quick%20tip:%20Opening%20last%20window%20in%20Chrome</link><description>&lt;p&gt;My main browser is Firefox, but I like Chrome&amp;#8217;s short startup time and general javascript speed.  Here is a useful tip if you use Chrome.  Chrome doesn&amp;#8217;t ask for confirmation if you close a window with multiple tabs.  Don&amp;#8217;t worry, it is very easy to bring those back.  To bring the last session press CTRL+SHIFT+T simultaneously and your last window will popup.&lt;/p&gt;

	&lt;p&gt;This is also true across sessions, i.e. if you completely close Chrome or after you restart.  In these cases open a new Chrome window, then press this combination and you will get another window with your last set of tabs.&lt;/p&gt;


&lt;script src="http://feeds.feedburner.com/~s/TheBitGuru?i=/blog/view/303-Quick%20tip:%20Opening%20last%20window%20in%20Chrome" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheBitGuru?a=W1hdZCPfCQ8:mo2Rms6tVaE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheBitGuru?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheBitGuru?a=W1hdZCPfCQ8:mo2Rms6tVaE:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheBitGuru?i=W1hdZCPfCQ8:mo2Rms6tVaE:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheBitGuru?a=W1hdZCPfCQ8:mo2Rms6tVaE:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheBitGuru?i=W1hdZCPfCQ8:mo2Rms6tVaE:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Farhan</dc:creator><pubDate>Sat, 06 Jun 2009 17:53:47 -0500</pubDate><guid isPermaLink="false">http://www.thebitguru.com/blog/view/303-Quick%20tip:%20Opening%20last%20window%20in%20Chrome</guid><feedburner:origLink>http://www.thebitguru.com/blog/view/303-Quick%20tip:%20Opening%20last%20window%20in%20Chrome</feedburner:origLink></item><item><title>Performance difference between varchar and text in PostgreSQL
</title><link>http://feedproxy.google.com/~r/TheBitGuru/~3/PHph1JeUNWU/302-Performance%20difference%20between%20varchar%20and%20text%20in%20PostgreSQL</link><description>&lt;p&gt;I am one of the people that does read the documentation.  My business partner, Jake, asked why use varchar with an artificial limit for fields that don&amp;#8217;t really have a limit.  My initial thought was because of performance benefits, but I had never verified this.  So, I spent a few minutes to verify this and guess what I find in the &lt;a href="http://www.postgresql.org/docs/8.3/interactive/datatype-character.html"&gt;PostgreSQL documentation&lt;/a&gt;.&lt;/p&gt;

	&lt;blockquote&gt;
		&lt;p&gt;... If you desire to store long strings with no specific upper limit, use text or character varying without a length specifier, rather than making up an arbitrary length limit.)&lt;/p&gt;
	&lt;/blockquote&gt;

	&lt;p&gt;It continues on and says&amp;#8230;&lt;/p&gt;

	&lt;blockquote&gt;
		&lt;p&gt;Tip:  There are no performance differences between these three types, apart from increased storage size when using the blank-padded type, and a few extra cycles to check the length when storing into a length-constrained column. While character(n) has performance advantages in some other database systems, it has no such advantages in PostgreSQL. In most situations text or character varying should be used instead.&lt;/p&gt;
	&lt;/blockquote&gt;

	&lt;p&gt;Exactly what I was looking for!  This is what I call great documentation.&lt;/p&gt;

	&lt;p&gt;I have used MySQL in the past, but my experience with PostgreSQL has been awesome.  Great database that scales relatively well (we will find that out soon :)), supports most of what you expect from a db, and has &lt;em&gt;good&lt;/em&gt; documentation!&lt;/p&gt;


&lt;script src="http://feeds.feedburner.com/~s/TheBitGuru?i=/blog/view/302-Performance%20difference%20between%20varchar%20and%20text%20in%20PostgreSQL" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheBitGuru?a=PHph1JeUNWU:jIrUURxsECk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheBitGuru?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheBitGuru?a=PHph1JeUNWU:jIrUURxsECk:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheBitGuru?i=PHph1JeUNWU:jIrUURxsECk:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheBitGuru?a=PHph1JeUNWU:jIrUURxsECk:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheBitGuru?i=PHph1JeUNWU:jIrUURxsECk:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Farhan</dc:creator><pubDate>Fri, 29 May 2009 08:02:19 -0500</pubDate><guid isPermaLink="false">http://www.thebitguru.com/blog/view/302-Performance%20difference%20between%20varchar%20and%20text%20in%20PostgreSQL</guid><feedburner:origLink>http://www.thebitguru.com/blog/view/302-Performance%20difference%20between%20varchar%20and%20text%20in%20PostgreSQL</feedburner:origLink></item><item><title>What I don&amp;#39;t like about Firefox
</title><link>http://feedproxy.google.com/~r/TheBitGuru/~3/kPKC22VkvZ4/301-What%20I%20don%27t%20like%20about%20Firefox</link><description>&lt;p&gt;I love firefox, but everything has its bad sides, and this is one bad side of Firefox that I don&amp;#8217;t like.&lt;/p&gt;

	&lt;p style="text-align:center;"&gt;&lt;img src="/site_media/uploads/attachments/206_BadFirefox.jpg" alt="Bad Firefox" /&gt;&lt;/p&gt;


&lt;script src="http://feeds.feedburner.com/~s/TheBitGuru?i=/blog/view/301-What%20I%20don%27t%20like%20about%20Firefox" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheBitGuru?a=kPKC22VkvZ4:SA0NvhQZvDQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheBitGuru?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheBitGuru?a=kPKC22VkvZ4:SA0NvhQZvDQ:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheBitGuru?i=kPKC22VkvZ4:SA0NvhQZvDQ:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheBitGuru?a=kPKC22VkvZ4:SA0NvhQZvDQ:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheBitGuru?i=kPKC22VkvZ4:SA0NvhQZvDQ:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Farhan</dc:creator><pubDate>Fri, 15 May 2009 19:19:33 -0500</pubDate><guid isPermaLink="false">http://www.thebitguru.com/blog/view/301-What%20I%20don%27t%20like%20about%20Firefox</guid><feedburner:origLink>http://www.thebitguru.com/blog/view/301-What%20I%20don%27t%20like%20about%20Firefox</feedburner:origLink></item><item><title>Django running slow on Windows?
</title><link>http://feedproxy.google.com/~r/TheBitGuru/~3/QkdraZiPO0A/300-Django%20running%20slow%20on%20Windows</link><description>&lt;p&gt;I generally do my development on a dedicated development server running Linux with a fairly good amount of &lt;span class="caps"&gt;RAM&lt;/span&gt; (2GB) and a fast processor (the server does a lot more than just server django :)).  Even when I am out of office I &lt;span class="caps"&gt;SSH&lt;/span&gt; to the development server.  A few weeks ago I was on a trip where I wasn&amp;#8217;t going to have good internet access for a lot of time.  So, I decided to setup django on my tablet (Windows) to work locally.  Everything was great until I had to access the site.&lt;/p&gt;

	&lt;p&gt;http://localhost:8000&lt;/p&gt;

	&lt;p&gt;waiting&amp;#8230;&lt;/p&gt;

	&lt;p&gt;waiting&amp;#8230;&lt;/p&gt;

	&lt;p&gt;Finally, after a few seconds the main page showed up.  Then I clicked on a link.&lt;/p&gt;

	&lt;p&gt;waiting&amp;#8230;&lt;/p&gt;

	&lt;p&gt;waiting&amp;#8230;&lt;/p&gt;

	&lt;p&gt;Once again the page showed up after a few seconds.  I was surprised how slow this was behaving.  I booted to Linux and there it was very snappy.  Unsatisfied with this performance issue, I did some searching and debugging and finally found out that the 'localhost&amp;#8217; is what was causing the problem.  As soon as I switched to the local IP address (127.0.0.1), the server came back to life!&lt;/p&gt;

	&lt;p&gt;If you are developing on Windows and the server seems to be a little slow then make sure to use &amp;#8217;127.0.0.1:8000&amp;#8217; instead of 'localhost:8000&amp;#8217;.  If you are curious about the cause then search on google for complete explanation.  Apparently this has to do with IPv6 and might a be non-IE issue.&lt;/p&gt;


&lt;script src="http://feeds.feedburner.com/~s/TheBitGuru?i=/blog/view/300-Django%20running%20slow%20on%20Windows?" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheBitGuru?a=QkdraZiPO0A:HnKGodaCN-M:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheBitGuru?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheBitGuru?a=QkdraZiPO0A:HnKGodaCN-M:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheBitGuru?i=QkdraZiPO0A:HnKGodaCN-M:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheBitGuru?a=QkdraZiPO0A:HnKGodaCN-M:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheBitGuru?i=QkdraZiPO0A:HnKGodaCN-M:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Farhan</dc:creator><pubDate>Wed, 06 May 2009 00:33:04 -0500</pubDate><guid isPermaLink="false">http://www.thebitguru.com/blog/view/300-Django%20running%20slow%20on%20Windows?</guid><feedburner:origLink>http://www.thebitguru.com/blog/view/300-Django%20running%20slow%20on%20Windows?</feedburner:origLink></item><item><title>Adding * to required fields
</title><link>http://feedproxy.google.com/~r/TheBitGuru/~3/Tmnk7ZtGE6M/299-Adding%20*%20to%20required%20fields</link><description>&lt;p&gt;Django&amp;#8217;s &lt;a href="http://docs.djangoproject.com/en/dev/ref/forms/api/"&gt;forms&lt;/a&gt; (previously knows as newforms) framework has a lot cool functionality including the ability to output label tags.  So, instead of typing the complete label and setting the correct &lt;code&gt;for&lt;/code&gt;, you can just do &lt;code&gt;form.field_name.label_tag&lt;/code&gt; and everything else is taken care of for you.  The only problem is that there is no easy, documented way of adding an indicator (e.g. *) for required fields.  One way would be to do if&amp;#8217;s on each field and manually add an asterisk in the template, but that&amp;#8217;s not &lt;a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself"&gt;DRY&lt;/a&gt;.  After some search a few weeks ago I found &lt;a href="http://adil.2scomplement.com/2008/08/django-adding-to-every-required-field/"&gt;an interesting post by Adil Saleem&lt;/a&gt; that showed one way of easily accomplishing this without changing all of your templates.&lt;/p&gt;

	&lt;p&gt;I really liked Adil&amp;#8217;s solution, but I also wanted to change the class on the label so I could make those fields stand out (through &lt;span class="caps"&gt;CSS&lt;/span&gt;), and I also realized that he was really creating a python decorator, but in a weird way.  So, here is a revised version of his solution with a slightly different approach (overriding &lt;code&gt;label_tag&lt;/code&gt; instead of &lt;code&gt;__init__&lt;/code&gt;) that adds the required field indicator and specifies a special &lt;span class="caps"&gt;CSS&lt;/span&gt; class (&amp;#8220;required&amp;#8221;) through a python decorator.&lt;/p&gt;

	&lt;p&gt;First we define two functions.&lt;/p&gt;

	&lt;p&gt;&lt;div class="sourcecodeencap"&gt;&lt;table class="sourcecodetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17&lt;/pre&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="sourcecode"&gt;&lt;pre&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;django.utils.html&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;escape&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;add_required_label_tag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;original_function&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="sd"&gt;&amp;quot;&amp;quot;&amp;quot;Adds the &amp;#39;required&amp;#39; CSS class and an asterisks to required field labels.&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;required_label_tag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;contents&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;attrs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;contents&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;contents&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;escape&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;field&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;endswith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot; *&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot; *&amp;quot;&lt;/span&gt;
        &lt;span class="n"&gt;contents&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot; *&amp;quot;&lt;/span&gt;
      &lt;span class="n"&gt;attrs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;class&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;required&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;original_function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;contents&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;attrs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;required_label_tag&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;decorate_bound_field&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
  &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;django.forms.forms&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;BoundField&lt;/span&gt;
  &lt;span class="n"&gt;BoundField&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;label_tag&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;add_required_label_tag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BoundField&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;label_tag&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/p&gt;

	&lt;p&gt;The first function is a &lt;a href="http://www.python.org/dev/peps/pep-0318/"&gt;decorator&lt;/a&gt; that provides the functionality and the second function assigns this decorator to &lt;code&gt;BoundField.label_tag&lt;/code&gt;.  The second function is really a helper function that allows you to easily add this to all your form modules.&lt;/p&gt;

	&lt;p&gt;Add the above code to one of your library files (maybe &lt;code&gt;project.forms.__init__.py&lt;/code&gt;) and then in the module that defines your forms add the following code.&lt;/p&gt;

	&lt;p&gt;&lt;div class="sourcecodeencap"&gt;&lt;table class="sourcecodetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;pre&gt;1
2&lt;/pre&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="sourcecode"&gt;&lt;pre&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;project.forms&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;decorate_bound_field&lt;/span&gt;
&lt;span class="n"&gt;decorate_bound_field&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/p&gt;

	&lt;p&gt;Other than this you need to define the &amp;#8220;required&amp;#8221; &lt;span class="caps"&gt;CSS&lt;/span&gt; class.&lt;/p&gt;

	&lt;p&gt;&lt;div class="sourcecodeencap"&gt;&lt;table class="sourcecodetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;pre&gt;1&lt;/pre&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="sourcecode"&gt;&lt;pre&gt;&lt;span class="nt"&gt;label&lt;/span&gt;&lt;span class="nc"&gt;.required&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;font-weight&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="k"&gt;bold&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/p&gt;

	&lt;p&gt;Refresh your page with the form and all of your required fields will have an asterisk and the labels will be bold.  Credit goes to &lt;a href="http://adil.2scomplement.com/2008/08/django-adding-to-every-required-field/"&gt;Adil Saleem&lt;/a&gt; for coming up with the initial version, this is just a refinement :)&lt;/p&gt;


&lt;script src="http://feeds.feedburner.com/~s/TheBitGuru?i=/blog/view/299-Adding%20*%20to%20required%20fields" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheBitGuru?a=Tmnk7ZtGE6M:ks9rXzSWb-w:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheBitGuru?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheBitGuru?a=Tmnk7ZtGE6M:ks9rXzSWb-w:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheBitGuru?i=Tmnk7ZtGE6M:ks9rXzSWb-w:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheBitGuru?a=Tmnk7ZtGE6M:ks9rXzSWb-w:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheBitGuru?i=Tmnk7ZtGE6M:ks9rXzSWb-w:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Farhan</dc:creator><pubDate>Thu, 30 Apr 2009 21:51:57 -0500</pubDate><guid isPermaLink="false">http://www.thebitguru.com/blog/view/299-Adding%20*%20to%20required%20fields</guid><feedburner:origLink>http://www.thebitguru.com/blog/view/299-Adding%20*%20to%20required%20fields</feedburner:origLink></item><item><title>Presenting at TechNow09 tomorrow
</title><link>http://feedproxy.google.com/~r/TheBitGuru/~3/CMl81dogSvw/298-Presenting%20at%20TechNow09%20tomorrow</link><description>&lt;p&gt;Tomorrow is the &lt;a href="http://www.technow09.com/companies.php"&gt;TechNow09&lt;/a&gt; event happening in Royal Oak, MI.  &lt;a href="http://www.shopfiber.com"&gt;ShopFiber&lt;/a&gt; is one of the companies presenting.  We will be doing a short skit about what ShopFiber is and how it can help the average consumer shopping for electronics.  I will be playing the role of &amp;#8220;Bob,&amp;#8221; an average consumer and &lt;a href="http://www.twitter.com/jakelumetta"&gt;Jake&lt;/a&gt; will be playing the role of &amp;#8220;Neo,&amp;#8221; a gadget lover.  We are hoping that this will be a very entertaining way to showcase ShopFiber.  There is a plan to broadcast the event on ustream and I will post a link once the setup is finalized.  I will tweet the link as soon as I find out, so &lt;a href="http://www.twitter.com/farhanahmad"&gt;follow me&lt;/a&gt; on twitter if you would like to watch the live stream.&lt;/p&gt;

	&lt;p&gt;I am planning on being there for most of the time after the main event so come and say hi if you have a chance.&lt;/p&gt;


&lt;script src="http://feeds.feedburner.com/~s/TheBitGuru?i=/blog/view/298-Presenting%20at%20TechNow09%20tomorrow" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheBitGuru?a=CMl81dogSvw:zo_7sV4RdRc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheBitGuru?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheBitGuru?a=CMl81dogSvw:zo_7sV4RdRc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheBitGuru?i=CMl81dogSvw:zo_7sV4RdRc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheBitGuru?a=CMl81dogSvw:zo_7sV4RdRc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheBitGuru?i=CMl81dogSvw:zo_7sV4RdRc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Farhan</dc:creator><pubDate>Wed, 22 Apr 2009 22:46:24 -0500</pubDate><guid isPermaLink="false">http://www.thebitguru.com/blog/view/298-Presenting%20at%20TechNow09%20tomorrow</guid><feedburner:origLink>http://www.thebitguru.com/blog/view/298-Presenting%20at%20TechNow09%20tomorrow</feedburner:origLink></item></channel></rss>
