<?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 &#187; django</title>
	<atom:link href="http://prettyprinted.net/blog/tag/django/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>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>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>
