<?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>Prettyprinted</title>
	<atom:link href="http://prettyprinted.net/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://prettyprinted.net/blog</link>
	<description>Django, Python and Drunken Ramblings</description>
	<lastBuildDate>Thu, 26 Nov 2009 21:45:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Pushing Django Objects To The iPhone</title>
		<link>http://prettyprinted.net/blog/pushing-django-objects-to-the-iphone/</link>
		<comments>http://prettyprinted.net/blog/pushing-django-objects-to-the-iphone/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 19:07:45 +0000</pubDate>
		<dc:creator>steingrd</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[django-plist]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://prettyprinted.net/blog/?p=38</guid>
		<description><![CDATA[iPhone application development often involves writing a web service counterpart that the iPhone application uses. A key issue when writing a web service for iPhone&#8217;s is to figure out how to communicate your server side objects onto your iPhone device. Luckily Cocoa, the application framework for iPhone development, comes with a predefined XML format that store [...]]]></description>
			<content:encoded><![CDATA[<p>iPhone application development often involves writing a web service counterpart that the iPhone application uses. A key issue when writing a web service for iPhone&#8217;s is to figure out how to communicate your server side objects onto your iPhone device. Luckily Cocoa, the application framework for iPhone development, comes with a predefined XML format that store serialized objects and utility methods for deserializing this format into NSArray and NSDictionary objects.</p>
<p>That file format is called <a href="http://en.wikipedia.org/wiki/Property_list">Property List</a> because they often store application properties such as user settings.</p>
<p>This blog post introductes a Django application for serializing Django model objects and regular Python types into Property List XML!</p>
<p>The package is called <a href="http://wiki.github.com/steingrd/django-plist">django-plist</a> and <a href="http://github.com/steingrd/django-plist">the source is available at Github</a>. It is also available from the Python Package Index, install it with <code>easy_install django_plist</code>.</p>
<p>The <a href="http://github.com/steingrd/django-plist/blob/master/README.markdown">README</a> file documents the installation process and how to use the application to serialize Django objects, but I&#8217;ll give a small teaser here, just to get your attention!</p>
<p>Say we have a model Blog and we want to expose all Blog objects as an array of objects at one URL endpoint and single Blog objects as a dictionary at another endpoint. Point your Objective-C code to the URLs and read it with <code>[NSArray arrayWithContentsOfUrl]</code> and <code>[NSDictionary dictionaryWithContentsOfUrl]</code>. And voilá your Python objects are available as arrays and dictionaries in Objective-C!</p>
<p>The main interface for django-plist is two generic views, you&#8217;ll use these views just as you would use the generic views in Django:</p>
<pre>from django_plist.views.generic import plist_array, plist_dict

blog_info = {'queryset': Blog.objects.all()}

urlpatterns = patterns('',
    url('^all_entries/$', plist_array, blog_info),
    url('^single_entry/(?P&lt;object_id&gt;\d+)/$', plist_dict, blog_info),
)</pre>
<p>Read about the different ways you can customize the generic views and the parameters they take in <a href="http://wiki.github.com/steingrd/django-plist">the documentation</a>.</p>
<p>If you find django-plist useful, please drop me a line!</p>
]]></content:encoded>
			<wfw:commentRss>http://prettyprinted.net/blog/pushing-django-objects-to-the-iphone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More Cygwin Goodies</title>
		<link>http://prettyprinted.net/blog/more-cygwin-goodies/</link>
		<comments>http://prettyprinted.net/blog/more-cygwin-goodies/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 18:34:48 +0000</pubDate>
		<dc:creator>steingrd</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cygwin]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://prettyprinted.net/blog/?p=25</guid>
		<description><![CDATA[I stumpled upon a couple of Cygwin .bashrc goodness whilst browsing Reddit today. As a result I stopped for a moment and remembered that I too have a few goodies that I use and love every day.
The default Cygwin terminal emulator is cmd.exe. Instead of replacing this with Putty as Athul suggests I&#8217;ve edited c:\cygwin\cygwin.bat [...]]]></description>
			<content:encoded><![CDATA[<p>I stumpled upon a couple of <a href="http://blog.athulacharya.com/2009/03/cygwin-bashrc-goodness.html">Cygwin .bashrc goodness</a> whilst browsing Reddit today. As a result I stopped for a moment and remembered that I too have a few goodies that I use and love every day.</p>
<p>The default Cygwin terminal emulator is <code>cmd.exe</code>. Instead of replacing this with Putty as Athul suggests I&#8217;ve edited <code>c:\cygwin\cygwin.bat</code> to open a <code>rxvt</code> terminal with a nice font:</p>
<pre>
@echo off
C:
chdir C:\Cygwin\bin
rxvt -bg black -fn "Lucida Console-12" -e bash --login -i
</pre>
<p>Finally a decent terminal emulator with copy and paste the way it&#8217;s supposed to be!</p>
<p>If you&#8217;re like me you hate the default <code>/cygdrive/c</code> setup. To save me from typing <code>cd /cygdrive</code> all the time. I always run this one-liner on fresh Cygwin installations:</p>
<pre>
for d in $(/bin/ls /cygdrive); do ln -s "/cygdrive/$d" "/$d"; done
</pre>
<p>It creates symlinks from <code>/cygdrive/c</code> to <code>/c</code> for all your drives. Saves me from a lot of typing, every day.</p>
]]></content:encoded>
			<wfw:commentRss>http://prettyprinted.net/blog/more-cygwin-goodies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Subclassing Django&#8217;s CommentForm</title>
		<link>http://prettyprinted.net/blog/subclassing-djangos-commentform/</link>
		<comments>http://prettyprinted.net/blog/subclassing-djangos-commentform/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 18:32:03 +0000</pubDate>
		<dc:creator>steingrd</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[comments]]></category>

		<guid isPermaLink="false">http://prettyprinted.net/blog/?p=20</guid>
		<description><![CDATA[Django comes with batteries included and a very powerful and useful battery is the django.contrib.comments framework. However, to make it in time for the long awaited 1.0 release the comments framework was released without customization hooks. See #8630 for more details.
The long story in a short sentence is that you cannot subclass or customize CommentForm [...]]]></description>
			<content:encoded><![CDATA[<p>Django comes with batteries included and a very powerful and useful battery is the <code>django.contrib.comments</code> framework. However, to make it in time for the long awaited 1.0 release the comments framework was released without customization hooks. See <a href="http://code.djangoproject.com/ticket/8630">#8630</a> for more details.</p>
<p>The long story in a short sentence is that you cannot subclass or customize <code>CommentForm</code> in todays version without getting your hands dirty.</p>
<p>I recently enabled <a href="http://en.wikipedia.org/wiki/Captcha">Captcha</a> verification to comments on this site to prevent spammers from filling my database with non-public comments. Tor Brede Vekterli has <a href="http://arcticinteractive.com/2008/10/16/adding-recaptcha-support-django-10-comments/">written about how to do this</a> by using signals, but for technical reasons I&#8217;d rather not go down that road. So I landed on the next possible strategy, namely subclassing <code>CommentForm</code>.</p>
<p>My subclass is a standard Django form:</p>
<pre>class CaptchaCommentForm(CommentForm):
    captcha = forms.CharField(max_length=20, label='Enter this word')

    def clean_captcha(self):
        # verify self.cleaned_data['captcha'] here, details omitted,
        # raise forms.ValidationError if verification fails</pre>
<pre></pre>
<p>Since I wanted to control the way this field is displayed by adding an image I also edited my form template. In my <code>comments/form.html</code> template I added a check to include the captcha image:</p>
<pre>{% for field in form %}
    {% ifequal field.name "captcha" %}
        do whatever it takes to display the custom field.
    {% else %}
        display regular comment form field
    {% endifequal %}
{% endfor %}</pre>
<p>As I mentioned above the comments framework is not really designed to be extended or customized in this way. To make the framework use my <code>CaptchaCommentForm</code> instead of its own <code>CommentForm</code> I resorted to <a href="http://en.wikipedia.org/wiki/Monkey_patch">monkeypatching</a>!</p>
<p>The framework uses a single function, <code>comments.get_form</code>, whenever it needs a fresh <code>CommentForm</code> instance. What I wanted is for that function to return my <code>CaptchaCommentForm</code> instead. Here is what I did to my <code>urls.py</code>:</p>
<pre>from django.contrib import comments
from forms import CaptchaCommentForm

def override_get_form():
    return CaptchaCommentForm()
comments.get_form = override_get_form</pre>
<p>Thanks to the dynamic features of Python we can simply replace the original function with our own that returns the correct instance. Not pretty, but it works.</p>
]]></content:encoded>
			<wfw:commentRss>http://prettyprinted.net/blog/subclassing-djangos-commentform/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Is gst a bot?</title>
		<link>http://prettyprinted.net/blog/is-gst-a-bot/</link>
		<comments>http://prettyprinted.net/blog/is-gst-a-bot/#comments</comments>
		<pubDate>Mon, 27 Oct 2008 18:18:00 +0000</pubDate>
		<dc:creator>steingrd</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://prettyprinted.net/blog/?p=16</guid>
		<description><![CDATA[I recently noticed that nearly all of the links in the programming section on Reddit that I follow is posted by a certain user named gst. Curious about this user I checked out his Reddit profile only to find that he has submitted a lot of links. No surprise there!
The normal Google searches turned out [...]]]></description>
			<content:encoded><![CDATA[<p>I recently noticed that nearly all of the links in the programming section on Reddit that I follow is posted by a certain user named gst. Curious about this user I checked out his <a href="http://www.reddit.com/user/gst/">Reddit profile</a> only to find that he has submitted a lot of links. No surprise there!</p>
<p>The normal Google searches turned out amazingly few clues as to who this person is.</p>
<p>Apparently <a href="http://www.reddit.com/comments/6wnmb/save_me_from_gst/">some people</a> feel that he is spamming Reddit and posted a request to &#8220;be saved from gst&#8221;. The discussion that followed suggested that gst is not a regular user, but a bot posting links from [gerd.storm] <a href="http://delicious.com/gerd.storm">gstdelicious</a>&#8217;s <a href="http://delicious.com/">Delicious</a> account:</p>
<blockquote><p>gst scrapes from gerd storm from del.icio.us. (hence the name gst for gerd storm)</p></blockquote>
<p>However in <a href="http://www.reddit.com/r/programming/comments/6oabz/ask_gst_where_do_you_get_all_the_wonderful_links/">another thread</a> gst is asked where he gets his links from and he replies:</p>
<blockquote><p>blogsearch.google.com. google reader. dzone.com. news.ycombinator.com. scanning google groups for python haskell lisp and scheme. following interesting links.</p></blockquote>
<p><a href="http://www.reddit.com/r/Python/comments/6p7l0/you_gotta_hand_it_to_gst_without_him_this/c04i532">Some</a> felt that such an answer implies that he is in fact human, however judging by the looks of his <a href="http://www.reddit.com/user/gst/comments/">average comment</a> I am inclined to say the opposite.</p>
<p>One thing is for sure; gst is posting <em>a lot</em> of links to Reddit. Averaging one every few minutes he&#8217;s probably the most active user on Reddit. One would think that such a user kept a high profile, but my searches tonight has led me nowhere. I still can not answer the question; is gst a bot?</p>
<p>If gst is a bot, I&#8217;d love to see the sources and its input. If he&#8217;s 100% human I&#8217;d <em>really</em> love to hear how he manages such a high volume.</p>
]]></content:encoded>
			<wfw:commentRss>http://prettyprinted.net/blog/is-gst-a-bot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SlugField and Django 1.0</title>
		<link>http://prettyprinted.net/blog/slugfield-and-django-1-0/</link>
		<comments>http://prettyprinted.net/blog/slugfield-and-django-1-0/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 18:02:12 +0000</pubDate>
		<dc:creator>steingrd</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[admin]]></category>

		<guid isPermaLink="false">http://prettyprinted.net/wp/?p=3</guid>
		<description><![CDATA[I stumbled upon this non-functional fix for using prepopulated admin fields in Django 1.0. If you manage to read the code you&#8217;ll notice that it really does not conform to Django-1.0 standards; it uses old-style inner Admin-classes.
The proper way to do this is of course to use the ModelAdmin classes that were introduced with the [...]]]></description>
			<content:encoded><![CDATA[<p>I stumbled upon <a href="http://innovationsopen.com/?p=31">this non-functional</a> fix for using prepopulated admin fields in Django 1.0. If you manage to read the code you&#8217;ll notice that it really does not conform to Django-1.0 standards; it uses old-style inner <code>Admin</code>-classes.</p>
<p>The <em>proper</em> way to do this is of course to use the <code>ModelAdmin</code> classes that were introduced with the merge of the newforms-admin branch.</p>
<p>Declare your model as usual in <code>models.py</code> <em>without</em> the inner Admin class:</p>
<pre>class Article(models.Model):
    title = models.CharField()
    slug = models.SlugField()
</pre>
<p>Then declare the <code>ModelAdmin</code> class in <code>admins.py</code>. This is where you set properties regarding the admin interface, it replaces the old-style inner <code>Admin</code> class:</p>
<pre>class ArticleAdmin(admin.ModelAdmin):
    prepopulated_fields = {"slug": ("title",)}
admin.site.register(Article, ArticleAdmin)</pre>
<p>This is the <em>correct</em> way to do it. Rip out the inner <code>Admin</code>-classes and create new <code>ModelAdmin</code>-classes. Read the new and updated <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/">documentation</a> for more on newforms-admin.</p>
]]></content:encoded>
			<wfw:commentRss>http://prettyprinted.net/blog/slugfield-and-django-1-0/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.190 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2010-09-03 16:30:58 -->
