<?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>Joe Lanman</title>
	<atom:link href="http://www.joelanman.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.joelanman.com</link>
	<description>Web design and development when not playing computer games</description>
	<lastBuildDate>Sat, 18 Dec 2010 19:10:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Straightening images in Inkscape</title>
		<link>http://www.joelanman.com/2010/12/straightening-images-in-inkscape/</link>
		<comments>http://www.joelanman.com/2010/12/straightening-images-in-inkscape/#comments</comments>
		<pubDate>Sat, 18 Dec 2010 19:10:15 +0000</pubDate>
		<dc:creator>Joe Lanman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.joelanman.com/?p=92</guid>
		<description><![CDATA[Inkscape is one of the most successful and usable open-source applications around &#8211; it&#8217;s a drawing app, useful for designing icons and logos, or laying out posters and leaflets. I used it to design my pocket calendar cards. I fired it up recently to design a leaflet for my Mum&#8217;s guest house, featuring lots of [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sourceforge.net/projects/inkscape/" class="aga aga_3">Inkscape</a> is one of the most successful and usable open-source applications around &#8211; it&#8217;s a drawing app, useful for designing icons and logos, or laying out posters and leaflets. I used it to design my <a href="http://formd.net/portfolio/calendar_cards/" class="aga aga_4">pocket calendar cards</a>.</p>
<p>I fired it up recently to design a leaflet for my Mum&#8217;s <a href="http://www.sanbrelade.co.uk/" class="aga aga_5">guest house</a>, featuring lots of photos of the local area. I&#8217;d previously rotated them to some jaunty angles and needed to straighten them up. I couldn&#8217;t find anything in the interface to do this (boo) but then remembered that one great feature of Inkscape is that it stores the state of the document as an editable SVG file. Even if there wasn&#8217;t a way to remove the rotations in the interface, I could do it by editing the data directly (hooray!), it&#8217;s a sort of View Source for illustration/page layout.</p>
<ol>
<li>Open the Edit menu, select XML Editor</li>
<li>Select the image you&#8217;d like to straighten on the page</li>
<li>In the XML Editor, click Transform attribute, and click the Delete Attribute button above</li>
</ol>
<p><a rel="attachment wp-att-93" href="http://www.joelanman.com/2010/12/straightening-images-in-inkscape/screenshot-2/" ><img class="alignnone size-medium wp-image-93" title="Inkscape XML Editor" src="http://www.joelanman.com/wp-content/uploads/2010/12/Screenshot-2-580x318.png" alt="" width="580" height="318" /></a></p>
<p>Boom &#8211; straight images.</p>
<p>Obviously, it would be nice to have a button to do this (maybe there is &#8211; feel free to let me know in the comments), but I like that the use of an open image format, and the tools to edit the data directly allows me to achieve what I need to do. Do you have any Inkscape tips?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joelanman.com/2010/12/straightening-images-in-inkscape/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Transferring TFL cycle routes to Android</title>
		<link>http://www.joelanman.com/2010/09/tfl-cycle-maps-to-android/</link>
		<comments>http://www.joelanman.com/2010/09/tfl-cycle-maps-to-android/#comments</comments>
		<pubDate>Sun, 05 Sep 2010 09:58:21 +0000</pubDate>
		<dc:creator>Joe Lanman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[cycling]]></category>
		<category><![CDATA[london]]></category>
		<category><![CDATA[maps]]></category>
		<category><![CDATA[tfl]]></category>

		<guid isPermaLink="false">http://www.joelanman.com/?p=87</guid>
		<description><![CDATA[Transport for London have recently started offering a very handy cycle journey planner on their site, great &#8211; but it&#8217;d be much more handy in interactive form on my Android phone. Here&#8217;s a quick guide on how to do that: 1) Plan your route, then click upload to GPS device (top right). This will give you [...]]]></description>
			<content:encoded><![CDATA[<p>Transport for London have recently started offering a very handy <a href="http://cyclejourneyplanner.tfl.gov.uk/cycle/XSLT_TRIP_REQUEST2?language=en" class="aga aga_10">cycle journey planner</a> on their site, great &#8211; but it&#8217;d be much more handy in interactive form on my Android phone. Here&#8217;s a quick guide on how to do that:</p>
<p>1) Plan your route, then click <strong>upload to GPS device</strong> (top right). This will give you a GPX file to download.</p>
<p>2) <a href="http://www.cyrket.com/p/android/com.robert.maps/" class="aga aga_11">Download </a><strong><a href="http://www.cyrket.com/p/android/com.robert.maps/" class="aga aga_12">RMaps</a><span style="font-weight: normal;"> &#8211; this is what we&#8217;re going to use to view the route on Android, and its a fantastic map app to have anyway, its main advantage over Google Maps being it can cache maps offline for you &#8211; if you happen to be hiking out of mobile range for instance.</span></strong></p>
<p><strong><span style="font-weight: normal;">3) </span>Transfer your GPX file<span style="font-weight: normal;"> to your phone. I used the <a href="https://www.dropbox.com/android" class="aga aga_13">Android Dropbox app</a>, but you could just use USB, or a couple of floppies.</span></strong></p>
<p><strong><span style="font-weight: normal;">4) </span>Open the route with RMaps</strong> &#8211; in RMaps, press Menu -&gt;More -&gt; Tracks. Now press Menu again -&gt; Import, and select your GPX file. The route name should now appear on the screen, tap it to get a tick &#8211; it is now displayed on the map screen.</p>
<p>5) <strong>And you&#8217;re done</strong> &#8211; press Back until you see the map screen &#8211; if you zoom in you should see your route highlighted in purple.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joelanman.com/2010/09/tfl-cycle-maps-to-android/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Prototyping with jsFiddle.net</title>
		<link>http://www.joelanman.com/2010/07/prototyping-with-jsfiddle-net/</link>
		<comments>http://www.joelanman.com/2010/07/prototyping-with-jsfiddle-net/#comments</comments>
		<pubDate>Sun, 04 Jul 2010 17:49:11 +0000</pubDate>
		<dc:creator>Joe Lanman</dc:creator>
				<category><![CDATA[Front-end]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jsfiddle]]></category>
		<category><![CDATA[web-apps]]></category>

		<guid isPermaLink="false">http://www.joelanman.com/?p=43</guid>
		<description><![CDATA[I&#8217;m a big fan of applications that do a simple thing well; jsFiddle.net is an innovative environment to work on HTML, CSS and JavaScript in the browser. Coded by Piotr Zalewa and designed by Oskar Krawczyk, it&#8217;s a tool I&#8217;ve found really useful for me and my team &#8211; the simple four-pane layout is brilliantly suited to front-end [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a big fan of applications that do a simple thing well; <a href="http://jsfiddle.net" class="aga aga_18">jsFiddle.net</a> is an innovative environment to work on HTML, CSS and JavaScript in the browser. Coded by <a href="http://webdev.zalewa.info/" class="aga aga_19">Piotr Zalewa</a> and designed by <a href="http://nouincolor.com/" class="aga aga_20">Oskar Krawczyk</a>, it&#8217;s a tool I&#8217;ve found really useful for me and my team &#8211; the simple four-pane layout is brilliantly suited to front-end development:<br />
<a rel="attachment wp-att-49" href="http://www.joelanman.com/2010/07/prototyping-with-jsfiddle-net/jsfiddle-01-2/" ><img class="alignnone size-medium wp-image-49" style="margin: 20px 0;" title="jsFiddle-01" src="http://www.joelanman.com/wp-content/uploads/2010/07/jsFiddle-011-580x465.png" alt="" width="580" height="465" /></a><span id="more-43"></span></p>
<p><strong>Prototyping</strong></p>
<p>jsFiddle is really fast to work with &#8211; the layout means all your code is available at once, and it comes with &#8216;batteries included&#8217; &#8211; you can select from common JavaScript libraries to have preloaded. All this means it&#8217;s great for prototyping little interaction ideas &#8211; say a menu or dialog box.</p>
<p>Collaboration is easy &#8211; send the url to a colleague for them to comment on your work, or edit it and send you the updated version &#8211; code as conversation. Even versioning is supported- every change adds a number to the URL, eg. http://jsfiddle.net/ATFcS/1 becomes http://jsfiddle.net/ATFcS/2 when saved, so it&#8217;s easy to go back and review older versions &#8211; a brilliant touch.</p>
<p><strong>Teaching</strong></p>
<p><strong><span style="font-weight: normal;">Learning is always easier when you&#8217;re given examples, and being able to then play with the examples is even better. I&#8217;ve found jsFiddle perfect for explaining aspects of web development to people &#8211; I&#8217;ll knock up a simple example with just the features that we&#8217;re discussing, and the recipient can see what I&#8217;m talking about and modify the code to really cement their understanding. There&#8217;s even a lovely <a href="http://piotr.zalewa.info/embedding_jsfiddle" class="aga aga_21">embedded mode</a> &#8211; next time you talk about a JavaScript/CSS/HTML technique  online, why not make it in jsFiddle and embed an interactive example?</span></strong></p>
<p><strong>Debugging</strong></p>
<p><strong><span style="font-weight: normal;">When faced with a bug in a complex design,  it can be hard to track down exactly what&#8217;s causing the issue. I&#8217;ve found it can be very helpful to recreate a simplified set-up in jsFiddle &#8211; if I can replicate the issue it&#8217;s then very fast to manipulate the code to find a solution.</span></strong></p>
<p>So those are a few uses for jsFiddle &#8211; please feel free to leave your own tips and tricks in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joelanman.com/2010/07/prototyping-with-jsfiddle-net/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>IE Bug: Fading animation makes text render without anti-aliasing</title>
		<link>http://www.joelanman.com/2009/12/ie-bug-fading-animation-makes-text-render-without-anti-aliasing/</link>
		<comments>http://www.joelanman.com/2009/12/ie-bug-fading-animation-makes-text-render-without-anti-aliasing/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 15:28:20 +0000</pubDate>
		<dc:creator>Joe Lanman</dc:creator>
				<category><![CDATA[IE Bugs]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[workarounds]]></category>

		<guid isPermaLink="false">http://www.joelanman.com/?p=15</guid>
		<description><![CDATA[Affects: IE6, IE7 Description When using jQuery to fade elements, Internet Explorer will remove anti-aliasing from text (causing it to appear pixelated) . Workaround Remove the &#8216;filter&#8217; attribute used by IE to fade elements once the fade is complete (view the full post to read the code) Code based on GBegen&#8217;s comment on Stack Overflow [...]]]></description>
			<content:encoded><![CDATA[<p>Affects: IE6, IE7</p>
<p><strong>Description</strong></p>
<p>When using jQuery to fade elements, Internet Explorer will remove anti-aliasing from text (causing it to appear pixelated) .</p>
<p><strong>Workaround</strong></p>
<p>Remove the &#8216;filter&#8217; attribute used by IE to fade elements once the fade is complete (view the full post to read the code)</p>
<p><span id="more-15"></span></p>
<p>Code based on GBegen&#8217;s comment on Stack Overflow</p>
<p><a href="http://stackoverflow.com/questions/778208/jquery-fadein-leaves-text-not-anti-aliased-in-ie7" class="aga aga_23">http://stackoverflow.com/questions/778208/jquery-fadein-leaves-text-not-anti-aliased-in-ie7</a></p>
<pre><code>(function($) {
    $.fn.fadeIn = function(speed, callback) {
        return this.animate({opacity: 'show'}, speed, function() {
                if ( $.browser.msie )
                {
                       this.style.removeAttribute('filter');
                }
                if ( $.isFunction(callback) )
                {
		callback.call(this);
                }
        });
    };

    $.fn.fadeOut = function(speed, callback) {
        return this.animate({opacity: 'hide'}, speed, function() {
                if ( $.browser.msie )
                {
                      this.style.removeAttribute('filter');
                }
                if ( $.isFunction(callback) )
                {
		callback.call(this);
                }
        });
    };

    $.fn.fadeTo = function(speed, to, callback) {
        return this.animate({opacity: to}, speed, function() {
                if ( to == 1 &amp;&amp; $.browser.msie )
                {
                     this.style.removeAttribute('filter');
                }
                if ( $.isFunction(callback) )
                {
	         callback.call(this);
	     }
        });
    };
})(jQuery);</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.joelanman.com/2009/12/ie-bug-fading-animation-makes-text-render-without-anti-aliasing/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>IE Bug: Fading does not work on child elements that have position rules</title>
		<link>http://www.joelanman.com/2009/12/ie-bug-fading-does-not-work-on-child-elements-that-have-position-rules/</link>
		<comments>http://www.joelanman.com/2009/12/ie-bug-fading-does-not-work-on-child-elements-that-have-position-rules/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 15:10:00 +0000</pubDate>
		<dc:creator>Joe Lanman</dc:creator>
				<category><![CDATA[IE Bugs]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[workarounds]]></category>

		<guid isPermaLink="false">http://www.joelanman.com/?p=14</guid>
		<description><![CDATA[Affects: IE 8 Description When using jQuery or similar to fade an element (animate its opacity) IE 8 does not fade child elements that have any &#8216;position&#8217; property set (&#8216;relative&#8217;, &#8216;absolute&#8217;, etc). Workaround Removing position rules will work, but presumably you&#8217;re using them to, well position stuff. The only workaround I have found is to [...]]]></description>
			<content:encoded><![CDATA[<p>Affects: IE 8</p>
<p><strong>Description</strong></p>
<p>When using jQuery or similar to fade an element (animate its opacity) IE 8 does not fade child elements that have any &#8216;position&#8217; property set (&#8216;relative&#8217;, &#8216;absolute&#8217;, etc).</p>
<p><strong>Workaround</strong></p>
<p>Removing position rules will work, but presumably you&#8217;re using them to, well position stuff. The only workaround I have found is to use the <a href="http://msdn.microsoft.com/en-us/library/cc288325(VS.85).aspx" class="aga aga_27">IE 7 compatibility meta tag</a> to force IE 8 to render as 7 would.</p>
<p>Unfortunately this means you have to deal with the IE6/7 text anti-alias bug &#8211; <a href="http://www.joelanman.com/archives/15" >workaround here</a></p>
<p><strong>See also</strong></p>
<p><a href="http://glow-project.lighthouseapp.com/projects/33663/tickets/161-fade-animation-children-with-positionrelative-ignore-the-opacity-of-the-parent-in-ie" class="aga aga_28">http://glow-project.lighthouseapp.com/projects/33663/tickets/161-fade-animation-children-with-positionrelative-ignore-the-opacity-of-the-parent-in-ie</a></p>
<p><a href="http://flowplayer.org/tools/forum/55/28425" class="aga aga_29">http://flowplayer.org/tools/forum/55/28425</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.joelanman.com/2009/12/ie-bug-fading-does-not-work-on-child-elements-that-have-position-rules/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>IE bug: 1px vertical margin around input fields</title>
		<link>http://www.joelanman.com/2009/12/ie-bug-1px-vertical-margin-around-input-fields/</link>
		<comments>http://www.joelanman.com/2009/12/ie-bug-1px-vertical-margin-around-input-fields/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 14:20:38 +0000</pubDate>
		<dc:creator>Joe Lanman</dc:creator>
				<category><![CDATA[IE Bugs]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[workarounds]]></category>

		<guid isPermaLink="false">http://www.joelanman.com/?p=13</guid>
		<description><![CDATA[Affects: IE7, IE8 Description Input fields wrapped with an inline element will render with an extra 1 pixel margin above and below, regardless of the &#8216;margin&#8217; property set in the CSS rule. Workaround 1) Use a conditional comment or similar to serve a margin rule to IE that is 1px less than desired. So for [...]]]></description>
			<content:encoded><![CDATA[<p>Affects: IE7, IE8</p>
<p><strong>Description</strong></p>
<p>Input fields wrapped with an inline element will render with an extra 1 pixel margin above and below, regardless of the &#8216;margin&#8217; property set in the CSS rule.</p>
<p><strong>Workaround</strong></p>
<p>1) Use a <a href="http://www.quirksmode.org/css/condcom.html" class="aga aga_31">conditional comment</a> or similar to serve a margin rule to IE that is 1px less than desired. So for no margin:</p>
<pre><code>form input, form textarea{
    margin:			-1px 0;
}</code></pre>
<p>2) Remove the border from the input &#8211; this will also remove the extra margin.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joelanman.com/2009/12/ie-bug-1px-vertical-margin-around-input-fields/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Usable multiple-selection with checkbox lists and jQuery</title>
		<link>http://www.joelanman.com/2009/03/simple-multiple-selection-with-checkbox-lists-and-jquery/</link>
		<comments>http://www.joelanman.com/2009/03/simple-multiple-selection-with-checkbox-lists-and-jquery/#comments</comments>
		<pubDate>Sat, 21 Mar 2009 19:00:51 +0000</pubDate>
		<dc:creator>Joe Lanman</dc:creator>
				<category><![CDATA[Front-end]]></category>
		<category><![CDATA[User Experience]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[usability]]></category>

		<guid isPermaLink="false">http://www.joelanman.com/?p=11</guid>
		<description><![CDATA[There are two out-of-the-box methods for multiple selection in HTML: checkboxes and the &#60;select&#62; tag. Neither are perfect &#8211; I&#8217;ll be discussing why, and proposing a sort of mashup of the best aspects of both, using jQuery. The vanilla HTML implementations of these two methods are shown below: 1) Select tag: Bad Off the Wall [...]]]></description>
			<content:encoded><![CDATA[<p>There are two out-of-the-box methods for multiple selection in HTML: checkboxes and the &lt;select&gt; tag. Neither are perfect &#8211; I&#8217;ll be discussing why, and proposing a sort of mashup of the best aspects of both, using jQuery.</p>
<p><span id="more-11"></span></p>
<p>The vanilla HTML implementations of these two methods are shown below:</p>
<p><strong>1) Select tag:</strong></p>
<select multiple="multiple" size="3">
<option>Bad</option>
<option>Off the Wall</option>
<option>Thriller</option>
</select>
<p>(Hold ctrl or command to select multiple values)</p>
<p><strong>2) Checkboxes and Label tag:</strong></p>
<div>
<input id="check_a" type="checkbox" /><label for="check_a">Bad</label></div>
<div>
<input id="check_b" type="checkbox" /><label for="check_b">Off the Wall</label></div>
<div>
<input id="check_c" type="checkbox" /><label for="check_c">Thriller</label></div>
<p>Note that the &lt;label&gt; tag allows users to click the label to toggle the checkbox on and off.</p>
<p>In terms of usability,  the checkbox method is more straightforward &#8211; it is obvious how to select multiple values, whereas with the select method we have to tell the user which keys to hold down. In addition to that, if a user has selected multiple items, and then forgets to hold the correct key on the next click, their selection is lost and only the last value clicked is selected. On a list that can be scrolled, it may not even be apparent that the other selections have been lost.</p>
<p>The disadvantages of the checkbox method are:</p>
<ul>
<li>It&#8217;s not obvious that the label can be clicked.</li>
<li>It would be nice if a larger area were clickable, as with the SELECT example</li>
<li>It would be nice if the entire row were highlighted, as with the SELECT example</li>
<li>The values are not scrollable &#8211; adding more will simply show a longer list</li>
</ul>
<p>We&#8217;re going to fix all that with some simple CSS and Javascript (using JQuery).</p>
<p><a href="/static/examples/multiple_selection">Click to see an example page</a></p>
<p><strong>Edit 1 &#8211; 9/4/09:</strong> Simplify code as per Victor&#8217;s comments, and fix refresh issue in Firefox</p>
<p><strong>Edit 2 &#8211; 9/4/09: </strong>Simplified again, using just the label tags, without &lt;a&gt; tags, from the <a href="http://www.reddit.com/r/web_design/comments/8b876/my_blog_post_on_usable_multipleselection_any/" class="aga aga_33">reddit comments</a></p>
<pre><code>
	$(document).ready(function() {

		// make sure labels are drawn in the correct state

		$('label').each(function()
		{

			if ($(this).find(':checkbox').attr('checked'))
				$(this).addClass('selected');

		});

		// toggle label css when checkbox is clicked

		$(':checkbox').click(function(e)
		{

			var checked = $(this).attr('checked');
			$(this).closest('label').toggleClass('selected', checked);

		});

	});
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.joelanman.com/2009/03/simple-multiple-selection-with-checkbox-lists-and-jquery/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Uploading images and making thumbnails with web.py and PIL</title>
		<link>http://www.joelanman.com/2008/09/uploading-images-and-making-thumbnails-with-webpy-and-pil/</link>
		<comments>http://www.joelanman.com/2008/09/uploading-images-and-making-thumbnails-with-webpy-and-pil/#comments</comments>
		<pubDate>Sat, 27 Sep 2008 18:02:26 +0000</pubDate>
		<dc:creator>Joe Lanman</dc:creator>
				<category><![CDATA[Back-end]]></category>
		<category><![CDATA[pil]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[thumbnail]]></category>
		<category><![CDATA[upload]]></category>
		<category><![CDATA[web.py]]></category>

		<guid isPermaLink="false">http://www.joelanman.com/?p=10</guid>
		<description><![CDATA[I ran into an issue today while trying to implement image uploads. It&#8217;s a very basic implementation: taking files from a POST request, copying them to a local folder, and then making thumbnails of them. I started with the file upload tutorial in the web.py cookbook. The problem I was getting was that the Python [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into an issue today while trying to implement image uploads. It&#8217;s a very basic implementation: taking files from a POST request, copying them to a local folder, and then making thumbnails of them.</p>
<p>I started with the <a href="http://webpy.org/cookbook/fileupload" class="aga aga_36">file upload tutorial</a> in the web.py cookbook.</p>
<p>The problem I was getting was that the Python Image library (PIL) was failing to make the thumbnails, with the error &#8216;image file is truncated&#8217;.</p>
<p><span id="more-10"></span></p>
<p>Guessing that the upload was not yet complete when the thumbnail was initiated, I googled around for some help and came across the idea of &#8216;chunking&#8217;. This method copies the file upload to the destination folder in chunks as it arrives.</p>
<p>From <a href="http://www.aurigma.com/Support/DocViewer/28/WritingServerSideUploadCode.htm.aspx" class="aga aga_37">this tutorial</a>:</p>
<pre>
<code>
while 1:
        chunk = sourceFile.file.read( 10000 )
        if not chunk:
            break
        destFile.write( chunk )
    destFile.close()
</code>
</pre>
<p>I tried this method in web.py, using web.input(file = {}) to get the file field from the POST form, and then file.value.read(10000) in the code above. This fails because file.value does not have a .read() method &#8211; this is a file object method. Using file.file.read(10000) instead seems to work fine.</p>
<p>I&#8217;ve ended up with this:</p>
<pre>
<code>
    def POST(self, path = ''):

        self.path = path

        input = web.input(file = {})

        action = input['action']

        if action == 'upload':

            file = input['file']

            f = open(config.root + 'static/uploads/' + file.filename, "wb")

            while 1:
                chunk = file.file.read(10000 )
                if not chunk:
                    break
                f.write( chunk )
            f.close()

            self.thumbnail(path, file.filename)

        self.output()

    def thumbnail(self, path, filename):

        size = 128, 128

        outfile = open(config.root + 'static/resized/' + filename, "wb")

        im = Image.open(config.root + 'static/uploads/' + filename)
        im.thumbnail(size)
        im.save(outfile, "JPEG")
</code>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.joelanman.com/2008/09/uploading-images-and-making-thumbnails-with-webpy-and-pil/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Passing variables from a child template to a parent in Mako</title>
		<link>http://www.joelanman.com/2008/09/passing-variables-from-a-child-template-to-a-parent-in-mako/</link>
		<comments>http://www.joelanman.com/2008/09/passing-variables-from-a-child-template-to-a-parent-in-mako/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 15:35:40 +0000</pubDate>
		<dc:creator>Joe Lanman</dc:creator>
				<category><![CDATA[Back-end]]></category>
		<category><![CDATA[bayer]]></category>
		<category><![CDATA[mako]]></category>
		<category><![CDATA[michael]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[templating]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://www.joelanman.com/?p=9</guid>
		<description><![CDATA[After looking at Web.py&#8217;s own templating system, and considering Cheetah, I&#8217;ve ended up going with Mako for now. So far I&#8217;ve found it very straightforward, with some powerful-looking features to expand into in the future. One of the great features is template inheritance &#8211; but I hit an issue recently with passing a variable from [...]]]></description>
			<content:encoded><![CDATA[<p>After looking at Web.py&#8217;s own templating system, and considering Cheetah, I&#8217;ve ended up going with <a href="http://www.makotemplates.org/" class="aga aga_41">Mako</a> for now. So far I&#8217;ve found it very straightforward, with some powerful-looking features to expand into in the future.</p>
<p>One of the great features is template inheritance &#8211; but I hit an issue recently with passing a variable from a child template to a parent. It&#8217;s not immediately obvious how to do this, but I found the answer on the Mako Google Groups archive (<a href="http://markmail.org/message/wjbo3wvmw3zygmxj#query:mako%20pass%20variable%20to%20parent%20template+page:1+mid:wjbo3wvmw3zygmxj+state:results" class="aga aga_42">link here</a>):</p>
<p>Child:</p>
<pre>
<code>
&lt;%inherit file="meta.html"/&gt;

&lt;%def name="vars()"&gt;

	&lt;% return (meta.id,) %&gt;

&lt;/%def&gt;
</code>
</pre>
<p>Parent:</p>
<pre>
<code>
&lt;% (id,) = self.vars() %&gt;
</code>
</pre>
<p>On a side note, I found out today that two of the Python libraries I&#8217;m using, Mako and SQLAlchemy, were coded by the same guy &#8211; Michael Bayer. Clever chap &#8211; not only are the libraries pretty impressive, but they are both well documented and he regularly contributes to the mailing lists for both projects. <em>And</em> he doesn&#8217;t even have a big internet head like some developers &#8211; though I tracked his blog down here:</p>
<p><a href="http://techspot.zzzeek.org/" class="aga aga_43">http://techspot.zzzeek.org/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.joelanman.com/2008/09/passing-variables-from-a-child-template-to-a-parent-in-mako/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making a copy of a SQLAlchemy object</title>
		<link>http://www.joelanman.com/2008/09/making-a-copy-of-a-sqlalchemy-object/</link>
		<comments>http://www.joelanman.com/2008/09/making-a-copy-of-a-sqlalchemy-object/#comments</comments>
		<pubDate>Mon, 15 Sep 2008 17:12:47 +0000</pubDate>
		<dc:creator>Joe Lanman</dc:creator>
				<category><![CDATA[Back-end]]></category>
		<category><![CDATA[copy]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[sqlalchemy]]></category>

		<guid isPermaLink="false">http://www.joelanman.com/?p=8</guid>
		<description><![CDATA[Should that be &#8216;a&#8217; or &#8216;an&#8217; SQLAlchemy object? My current CMS project is based on creating templates in the back-end, and then using these to produce &#8216;inherited&#8217; objects with the same attributes. I quickly found that it&#8217;s surprisingly tricky to grab a template object using SQLAlchemy, and copy it into a similar, but separate, entity. [...]]]></description>
			<content:encoded><![CDATA[<p>Should that be &#8216;a&#8217; or &#8216;an&#8217; SQLAlchemy object?</p>
<p>My current CMS project is based on creating templates in the back-end, and then using these to produce &#8216;inherited&#8217; objects with the same attributes.</p>
<p><img src="http://gonet.cz/~tri65dnigalerie/porad/250/3/385fe0f0f6919d0c88db26dac9ff1fb1.jpg" alt="multiplicity" /></p>
<p>I quickly found that it&#8217;s surprisingly tricky to grab a template object using SQLAlchemy, and copy it into a similar, but separate, entity. Using the Python &#8216;copy&#8217; function confuses SQLAlchemy &#8211; when you try to save it, it thinks it is merely a representation of the original (template) object.</p>
<p>Here&#8217;s how I create separate &#8216;clones&#8217; from my template objects, defining a function on the object itself:</p>
<p><span id="more-8"></span></p>
<pre>
<code>
def clone (self, source, table):

    for c in table.c:

        if not c.name.endswith('id'):

            setattr(self, c.name, getattr(source, c.name))
</code>
</pre>
<p>Here&#8217;s a usage example:</p>
<pre>
<code>
template_meta = self.session.query(Meta).filter(and_(Meta.is_template == 1, Meta.id == id)).one()

new_meta = Meta(new_object.id)

new_meta.clone(template_meta, table_meta)
</code>
</pre>
<p>The clone function takes the object&#8217;s table as an argument, so that only the basic column values are copied. The table object has an attribute called c &#8211; these are the table columns in long form (eg. meta.id, meta.title, etc). Using c.name gives us just the name of the column.</p>
<p>Looping through the source object&#8217;s attributes would result in SQLA attributes and any child objects being copied too, which is not what we want.</p>
<p>Notice too that anything ending in &#8216;id&#8217; is ignored &#8211; otherwise we would get the original object&#8217;s relationships &#8211; again this is not what I want in this situation. The new object should have its own relationships.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joelanman.com/2008/09/making-a-copy-of-a-sqlalchemy-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.526 seconds -->
<!-- Cached page served by WP-Cache -->

