<?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>mikhail panchenko / blog &#187; django</title>
	<atom:link href="http://mihasya.com/blog/tag/django/feed/" rel="self" type="application/rss+xml" />
	<link>http://mihasya.com/blog</link>
	<description>good things now come in packages of three</description>
	<lastBuildDate>Thu, 22 Mar 2012 21:08:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Django Admin: Sorting on Related Object&#8217;s Property</title>
		<link>http://mihasya.com/blog/django-admin-sorting-on-related-objects-property/</link>
		<comments>http://mihasya.com/blog/django-admin-sorting-on-related-objects-property/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 08:03:28 +0000</pubDate>
		<dc:creator>mihasya</dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[foreign key]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[sorting]]></category>

		<guid isPermaLink="false">http://mihasya.com/blog/?p=362</guid>
		<description><![CDATA[This is mostly a note to myself for the future, but I&#8217;m sure someone else out there will find it helpful. The Problem In one of the apps I work on, I have a pretty standard setup for extending the User object in Django: I have a UserProfile model with a ForeignKey to the auth.User [...]]]></description>
			<content:encoded><![CDATA[<p>This is mostly a note to myself for the future, but I&#8217;m sure someone else out there will find it helpful.</p>

<h2>The Problem</h2>

<p>In one of the apps I work on, I have a pretty standard setup for extending the User object in Django: I have a <code>UserProfile</code> model with a <code>ForeignKey</code> to the <code>auth.User</code> model and have <code>AUTH_PROFILE_MODULE</code> pointing at that model, so that the appropriate row gets returned when I call <code>user.get_profile()</code></p>

<p>I&#8217;ve populated the UserProfile model with a bunch of fields that the client wanted to be able to see in the admin view. Nice and easy so far.</p>

<p>I was then asked to add the date the user joined the site to that view, and also make it sortable. &#8220;Easy!&#8221; I thought. I immediately went and added <code>user__date_joined</code> to the <code>ModelAdmin</code>&#8216;s <code>list_display</code> Turns out it&#8217;s not that easy! Doing this causes a 500.</p>

<p>At first I was baffled that a simple relationship could not be traversed. I went into the Django source and figured out that the error was being thrown by <code>admin.validation.validate()</code> I took out the check to see what would happen if it the field were just allowed to be in there (I was half expecting it to just work, since putting <code>user__date_joined</code> in <code>search_fields</code> worked fine.. I thought maybe the check was accidentally too strict) and that&#8217;s when I understood why it&#8217;s not allowed: by allowing a field on another model to be included in a certain model&#8217;s admin class, an assumption is introduced that 1. that model/field have all the methods required to be displayed and 2. that those methods do what the writer of the <code>ModelAdmin</code> in question expects. Not a good idea.</p>

<h2>The Solution</h2>

<p>I brought this up in a django IRC channel, and <a href="http://inzain.net/">Zain</a> quickly suggested that I just add a callable to the <code>ModelAdmin</code> that simply returns the user&#8217;s <code>date_joined</code>. I already knew I could do that, and the reason I hadn&#8217;t was that I needed to be able to sort by that field &#8211; something that is impossible if it&#8217;s generated by a callable.</p>

<p>That&#8217;s when Zain pointed out <code>admin_order_field</code> to me &#8211; turns out you can tell the admin site to use a specific column to back sort queries against a callable. The resulting code looks like this:</p>

<pre><code>class UserProfileAdmin(admin.ModelAdmin):
    list_select_related = True
    list_display = ( [...] 'date_joined')

    def date_joined(self, profile):
        return profile.user.date_joined

    date_joined.admin_order_field = 'user__date_joined'
</code></pre>

<p>That&#8217;s all there is to it. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://mihasya.com/blog/django-admin-sorting-on-related-objects-property/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Django: exposing settings in templates, the easy way</title>
		<link>http://mihasya.com/blog/django-exposing-settings-in-templates-the-easy-way/</link>
		<comments>http://mihasya.com/blog/django-exposing-settings-in-templates-the-easy-way/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 21:08:00 +0000</pubDate>
		<dc:creator>mihasya</dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[context processors]]></category>
		<category><![CDATA[settings]]></category>

		<guid isPermaLink="false">http://mihasya.com/blog/?p=285</guid>
		<description><![CDATA[NOTE: I have submitted a patch to have this functionality as part of Django core. I&#8217;m posting this code here in case the patch gets rejected, since similar motions have previously been rejected. The ticket is at http://code.djangoproject.com/ticket/3818, and I will update this post if the patch gets accepted. I find it very handy to [...]]]></description>
			<content:encoded><![CDATA[<p><strong>NOTE: I have submitted a patch to have this functionality as part of Django core. I&#8217;m posting this code here in case the patch gets rejected, since similar motions have previously been rejected. The ticket is at <a title="Django Ticket 3818" href="http://code.djangoproject.com/ticket/3818">http://code.djangoproject.com/ticket/3818</a>, and I will update this post if the patch gets accepted.</strong></p>

<p>I find it very handy to be able to expose parts of settings.py in templates. The Django docs show you how to do this using context processors and give the code for the MEDIA_URL context processor here. However, it seems silly to me to have to write custom processors all the time. Instead, I propose a single processor that exposes a list of settings (stored in settings.py itself) to the template layer.</p>

<p>The gist containing the code is here: <a title="Gist for settings context processor" href="http://gist.github.com/155894">http://gist.github.com/155894</a></p>

<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://mihasya.com/blog/django-exposing-settings-in-templates-the-easy-way/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>APIMuni by Danny Roa &#8211; Bringing NextMuni To The Masses</title>
		<link>http://mihasya.com/blog/apimuni-by-danny-roa-bringing-nextmuni-to-the-masses/</link>
		<comments>http://mihasya.com/blog/apimuni-by-danny-roa-bringing-nextmuni-to-the-masses/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 05:44:53 +0000</pubDate>
		<dc:creator>mihasya</dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[gae]]></category>
		<category><![CDATA[google app engine]]></category>
		<category><![CDATA[nextbus]]></category>
		<category><![CDATA[yourmuni]]></category>

		<guid isPermaLink="false">http://mihasya.com/blog/?p=245</guid>
		<description><![CDATA[Danny Roa, whom I met at the last Django Meetup, has put out a quick API for accessing Nextbus data. It&#8217;s hosted on the App Engine and can be found here. His writeup is here. He recycled the scraping code from yourmuni, props to him for giving props Of course, that just means that when [...]]]></description>
			<content:encoded><![CDATA[<p>Danny Roa, whom I met at the last <a title="Django Meetup Group" href="http://www.meetup.com/The-San-Francisco-Django-Meetup-Group/calendar/9527778/">Django Meetup</a>, has put out a quick API for accessing Nextbus data.</p>

<p>It&#8217;s hosted on the App Engine and can be found <a title="APIMuni" href="http://apimuni.appspot.com/">here</a>.</p>

<p>His writeup is <a title="Danny Roa - APIMuni Post" href="http://blog.dannyroa.com/2009/02/28/apimuni-on-google-app-engine/">here</a>.</p>

<p>He recycled the scraping <a title="yourmuni source" href="http://github.com/mihasya/yourmuni">code</a> from <a title="Yourmuni" href="http://yourmuni.appspot.com">yourmuni</a>, props to him for giving props <img src='http://mihasya.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Of course, that just means that when Nextbus gets angry, they&#8217;re going to come after me first!</p>

<p>Developers don&#8217;t create API&#8217;s for nothing, so I am eagerly anticipating what Danny is going to use this API for.</p>
]]></content:encoded>
			<wfw:commentRss>http://mihasya.com/blog/apimuni-by-danny-roa-bringing-nextmuni-to-the-masses/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reusable Logging in Django Apps</title>
		<link>http://mihasya.com/blog/reusable-logging-in-django-apps/</link>
		<comments>http://mihasya.com/blog/reusable-logging-in-django-apps/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 21:21:45 +0000</pubDate>
		<dc:creator>mihasya</dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[logging]]></category>

		<guid isPermaLink="false">http://mihasya.com/blog/?p=237</guid>
		<description><![CDATA[I have 3 drafts sitting in my queue &#8211; 1 really long post and 2 short ones. I&#8217;ve been picking away at the long post on the shuttle rides, but in the meantime I&#8217;m gonna try to push out the two quick ones. This is one of the quick ones. I was trying to figure [...]]]></description>
			<content:encoded><![CDATA[<p>I have 3 drafts sitting in my queue &#8211; 1 really long post and 2 short ones. I&#8217;ve been picking away at the long post on the shuttle rides, but in the meantime I&#8217;m gonna try to push out the two quick ones. This is one of the quick ones.</p>

<p>I was trying to figure out how to set up reusable logging in my apps and have it fairly decoupled from the overall project. Here&#8217;s what I came up with:</p>

<ol>
    <li>Set up a logger object using <a title="Python logging module" href="http://docs.python.org/library/logging.html" target="_blank">these</a> instructions in settings.py and store it in the LOGGER variable.</li>
    <li>Grab it inside apps using django.conf.settings like so:</li>
</ol>

<p><pre>from django.conf import settings
try:
    logging = settings.LOGGER
except AttributeError:
    import logging</pre>
Then just use logging.debug, logging.info etc. Thus, if a LOGGER is configured inside the project&#8217;s settings.py, we use that (django.conf.settings points to the settings.py for whatever project you&#8217;re working inside of, so you can move your app project to project no problem). Otherwise, we just use vanilla logging functions with the global logging configuration. Nice and sweet.</p>

<p>Suggestions on other ways to do this are, as always, welcome.</p>

<p>Example on django snippets: <a title="Reusable Logging on Django Snippets" href="http://www.djangosnippets.org/snippets/1345/" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://mihasya.com/blog/reusable-logging-in-django-apps/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Django Tip: Using Dictionaries For Model Method Parameters</title>
		<link>http://mihasya.com/blog/django-tip-using-dictionaries-for-model-method-parameters/</link>
		<comments>http://mihasya.com/blog/django-tip-using-dictionaries-for-model-method-parameters/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 07:40:17 +0000</pubDate>
		<dc:creator>mihasya</dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[orm]]></category>

		<guid isPermaLink="false">http://mihasya.com/blog/?p=230</guid>
		<description><![CDATA[I&#8217;ve been working a whole lot outside of my job, mostly writing Python and working with Django. I don&#8217;t have much energy for a real blog post about something awesome, but I do have a tip to share. Advanced &#8220;pythonistas&#8221; won&#8217;t be impressed, but I haven&#8217;t seen this documented prominently anywhere, so I&#8217;ll toss it [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working a whole lot outside of my job, mostly writing Python and working with Django. I don&#8217;t have much energy for a real blog post about something awesome, but I do have a tip to share. Advanced &#8220;pythonistas&#8221; won&#8217;t be impressed, but I haven&#8217;t seen this documented prominently anywhere, so I&#8217;ll toss it up anyway.</p>

<p>As we all know, Python supports keyword arguments, and the Django ORM takes full advantage of this. When doing lookups, the ORM parses keyword parameters in order to determine what SQL query to execute. A typical ORM call will look like this:
<pre>all_oatmeal = Cookie.objects.filter(cookie_type='oatmeal')</pre>
That&#8217;s very cool and expressive. However, what if our search criteria depend somehow on user input? For example, what if we have a search form with multiple fields, but only want to search by the fields that a user entered something into.</p>

<p>We could have a series of convoluted if/else statements to determine which variables were set and have a corresponding .filter() call for each possibility, but that would be dumb, convoluted, and hard to read later. Also, dumb.</p>

<p>Instead, we can use an alternative way of passing keyword arguments provided by Python (details <a title="Python - Keyword Arguments" href="http://docs.python.org/tutorial/controlflow.html#keyword-arguments">here</a>): putting ** in front of a dictionary being passed to a function makes Python unpack the dictionary and pass the pairs as keyword arguments to the function. Using that technique, we can arbitrarily construct a dictionary of the search parameters, then pass it to a single .filter() call at the bottom.</p>

<h3>An over-simplified example, in which I assume that our form fields match up exactly with model properties</h3>

<p><pre>for key in form_data:
    if form_data[key]=='':
        del form_data[key]
wanted_cookies = Cookie.objects.filter(**form_data)</pre>
I&#8217;m sure there&#8217;s a more elegant way to do the empty value stripping too, but that&#8217;s not our focus (comments on the subject are welcome, though, for to make me smarter). The point is this: this technique allows for very clean, easy to read, efficient code.</p>

<h3>Creating model instances</h3>

<p><pre>cookie_data = {
    'cookie_type': 'oatmeal',
    'cookie_size': '3in',
    'cookie_touched': True
}
c = Cookie(**cookie_data)
c.save()</pre>
Obviously, this applies to more than just Django &#8211; there are many many use cases where this trick can come in handy. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://mihasya.com/blog/django-tip-using-dictionaries-for-model-method-parameters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>yourmuni now has instant stop lookup</title>
		<link>http://mihasya.com/blog/youmuni-now-has-instant-stop-lookup/</link>
		<comments>http://mihasya.com/blog/youmuni-now-has-instant-stop-lookup/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 08:10:12 +0000</pubDate>
		<dc:creator>mihasya</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[google app engine]]></category>
		<category><![CDATA[muni]]></category>
		<category><![CDATA[yourmuni]]></category>

		<guid isPermaLink="false">http://mihasya.com/blog/?p=226</guid>
		<description><![CDATA[After another successful hack session on the shuttle ride home, yourmuni now lets you just look up any given stop on the spot without creating a bookmark. Now you can has the best of both worlds all on one site. Up next is adding other regions/agencies covered by nextbus (easy, probably done by the end [...]]]></description>
			<content:encoded><![CDATA[<p>After another successful hack session on the shuttle ride home, <a title="yourmuni" href="http://yourmuni.appspot.com">yourmuni</a> now lets you just look up any given stop on the spot without creating a bookmark. Now you can has the best of both worlds all on one site. Up next is adding other regions/agencies covered by nextbus (easy, probably done by the end of this week while I ride the shuttle) and an API.</p>

<p>Site is at <a title="yourmuni" href="http://yourmuni.appspot.com">http://yourmuni.appspot.com</a></p>

<p>Latest code is at <a title="yourmuni source" href="https://github.com/mihasya/yourmuni/tree">Github</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mihasya.com/blog/youmuni-now-has-instant-stop-lookup/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>yourmuni makes commuting easier</title>
		<link>http://mihasya.com/blog/yourmuni-makes-commuting-easier/</link>
		<comments>http://mihasya.com/blog/yourmuni-makes-commuting-easier/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 21:39:17 +0000</pubDate>
		<dc:creator>mihasya</dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[google app engine]]></category>
		<category><![CDATA[muni]]></category>
		<category><![CDATA[nextbus]]></category>

		<guid isPermaLink="false">http://mihasya.com/blog/?p=203</guid>
		<description><![CDATA[I am proud to present my latest app yourmuni. It is a cross between momuni.com and Paul Hammond&#8217;s minimuni. Its purpose is to make it easier for people to get to and from places they frequent, such as jobs, gyms, favorite spots, and bootycalls. yourmuni lets you define bookmarks which represent collections of transit stops, [...]]]></description>
			<content:encoded><![CDATA[<dl class="wp-caption alignright" style="width: 330px;"> <dt class="wp-caption-dt"><img class="size-full wp-image-206" title="yourmuni screenshot" src="http://mihasya.com/blog/wp-content/uploads/2009/01/photo.jpg" alt="what PH's &quot;to work&quot; bookmark would look like" width="320" height="480" /></dt> </dl>

<p>I am proud to present my latest app <a title="yourmuni" href="http://yourmuni.appspot.com">yourmuni</a>. It is a cross between <a title="momuni" href="http://momuni.com">momuni.com</a> and Paul Hammond&#8217;s <a title="minimuni" href="http://minimuni.paulhammond.org">minimuni</a>. Its purpose is to make it easier for people to get to and from places they frequent, such as jobs, gyms, favorite spots, and bootycalls. yourmuni lets you define bookmarks which represent collections of transit stops, and then view the bus/train arrival information for each bookmark on a single page. For example, if Paul didn&#8217;t already have his highly personalized mimimuni app, he could log onto yourmuni, define a &#8220;To Work&#8221; bookmark, and assign to it the same stops that he currently scrapes. See the screenshot on the right for an example.</p>

<p>While it&#8217;s obviously not a &#8220;disruptive&#8221; innovation, I think it&#8217;s a nice incremental improvement on what most people do, which is look up multiple routes using momuni or nextbus.com while walking out the door. I know I&#8217;ve been using it, and it has saved me a tremendous amount of time/clicking around on my iPhone, looking like an idiot.</p>

<p>Though yourmuni was developed with my iPhone in mind, it appears to work just fine on most phones.</p>

<p>Still on the burner:</p>

<ul>
    <li>Instant stop lookup (ala momuni)</li>
    <li>using other agencies that nextbus covers (including ones outside of NorCal)</li>
    <li>deleting stops from bookmarks</li>
    <li>better instructions while setting up bookmarks</li>
    <li>cleaning up some code</li>
</ul>

<p>yourmuni was demoed at the January Django Meetup, and everyone seemed to like it. I was very flattered by the positive feedback, since it&#8217;s a rather simple app.</p>

<h3>Technical Details</h3>

<p>yourmuni is written using the latest Django at the time of the start of the project, which was r9768. My previous post about getting the latest Django to work on the Google App Engine was the result of me setting yourmuni up on said App Engine, which is where it now lives. The source is <a title="yourmuni source" href="http://github.com/mihasya/yourmuni">on github</a>. It&#8217;s far from perfect, as it was my first real Django/Python project, and I am aware of several precise places in the code that could use a minor rewrite. However, here are the parts that I put lots of thought into, and that I think might be useful to others.</p>

<h4>App Engine userRequired Decorator</h4>

<p>Since the login_required decorator from django.contrib is useless when using the App Engine, I wrote my own, which checks to see if the user is logged in and, if not,  redirects them to the Google Accounts login page, while saving the URL they were trying to access as the callback URL. Here&#8217;s the source for all to enjoy (gist <a title="gist for @userRequired" href="http://gist.github.com/48451">here</a>):
<pre>def userRequired(fn):
    """decorator for forcing a login"""
    def new(<em>args, **kws):
        user = users.get_current_user()
        if not (user):
            r = args[0]
            return HttpResponseRedirect(users.create_login_url(
                                            r.build_absolute_uri()))
        else:
            return fn(</em>args, **kws)
    return new</pre></p>

<h4>Encapsulating Slug Generation in Form Code</h4>

<p>Since I only ask for one field (&#8220;Description&#8221;) when creating a bookmark and place no restrictions on that field (i want it to look like whatever the user wants to see in the interface), I need some way to generate an identifier for the bookmark. I could just give it a numeric or hash identifier, but then it would be useless to the user in terms of seeing it in their browser history (I want to allow the user to jump straight to the bookmark they want if their browser shows it as an option after they type &#8216;y&#8217;). I needed to create a slug. I could accept the &#8220;Description&#8221; field and then process it in my addBmark view, but instead I defined the form to have two fields, one optional, and used the contents of the description field to automatically populate the &#8220;name&#8221; field using Django&#8217;s built in slugify method available in the template API (thanks to the folks at the Django Meetup who pointed this out). This allows me to encapsulate the validation within the form, so my view code looks very clean &#8211; I just have to call the is_valid() method on the form, and the form then has two properties that give me everything I need to create the bookmark. Here&#8217;s the code (full source <a title="forms.py on github" href="http://github.com/mihasya/yourmuni/blob/master/forms.py">here</a>).
<pre>class AddBmarkForm(forms.Form):
    name = forms.CharField(max_length=50, required=False)
    description = forms.CharField(max_length=255, required=True)</p>

<pre><code>def clean_description(self):
    desc = self.cleaned_data['description']
    name = slugify(desc).decode()
    q = db.Query(Bmark)
    q.filter('name =', name)
    q.filter('user =', users.get_current_user())
    if (q.get()):
        raise forms.ValidationError(_("A bookmark with that \
                    name exists already"))
    else:
        self.cleaned_data['name'] = name
        return desc&lt;/pre&gt;
</code></pre>

<h4>Scraping Nextbus</h4>

<p>For an unclear reason, nextbus does not have a clean, public API. My assumption is that they want to sell their data, but that's sort of pointless since they provide a free, publicly accessible website everywhere they provide service. It just sucks. So in order to make something better, I basically had to scrape that same publicly accessible website. It wasn't easy, as apparently nextbus hired a live bear to write their markup. Though all of their pages look almost identical, each has its own qurky combination of li, a, nobr, and font tags. I still managed to write a single scrape function to handle all of them, but it ended up being a bit more complex than it needed to be. Thank the powers that be for the BeautifulSoup library. The scrape code is <a title="nextbus scrape code" href="http://github.com/mihasya/yourmuni/blob/master/lib/nextbus.py">here</a>.</p>

<h4>Misc Stuff</h4>

<p>As I had mentioned before, I used the latest Django avaialble to me at the start of development. Though I don't get to play with the cool ORM stuff that's been added recently, I did get to use some of the new template tags, such as the {% empty %} tag to specify the behavior in the event of an empty {% for %} loop (docs <a title="docs for django empty tag" href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#for-empty">here</a>, used <a title="source of template using empty django tag" href="http://github.com/mihasya/yourmuni/blob/028cd96a90e8e73f835606b7d97a7e33927c1a7e/tpl/user/catch.html">here</a>).</p>

<p>All in all, I hope this helps people get to and from wherever it is they're going easier. This is the first project I've actually launched in a very long time, and certainly the most useful one.</p>
]]></content:encoded>
			<wfw:commentRss>http://mihasya.com/blog/yourmuni-makes-commuting-easier/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django SVN on Google App Engine</title>
		<link>http://mihasya.com/blog/django-svn-on-google-app-engine/</link>
		<comments>http://mihasya.com/blog/django-svn-on-google-app-engine/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 00:58:32 +0000</pubDate>
		<dc:creator>mihasya</dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[app engine]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://mihasya.com/blog/?p=199</guid>
		<description><![CDATA[The Google How-To for using a version of Django other than the built in 0.96 appears to be a bit out of date, as signal handling has changed since the writing. Here&#8217;s what needs to be changed: NOTE: These changes apply to this document dated April 2008. If the date at the top of the [...]]]></description>
			<content:encoded><![CDATA[<p>The Google How-To for using a version of Django other than the built in 0.96 appears to be a bit out of date, as signal handling has changed since the writing. Here&#8217;s what needs to be changed:</p>

<p><span style="color: #800000;"><strong>NOTE:</strong> These changes apply to <a title="App Engine Django Howto" href="http://code.google.com/appengine/articles/django.html">this</a> document dated April 2008. If the date at the top of the document is different, the how-to may have been updated since the writing of this post. Django Rev 9699 is what I&#8217;m using.
</span></p>

<p>The main.py portion of the how-to says that two signal handlers need to be changed. Here&#8217;s the original source:
<pre class="prettyprint"><span class="com"># Log errors.</span><span class="pln">
django</span><span class="pun">.</span><span class="pln">dispatch</span><span class="pun">.</span><span class="pln">dispatcher</span><span class="pun">.</span><span class="pln">connect</span><span class="pun">(</span><span class="pln">
   log_exception</span><span class="pun">,</span><span class="pln"> django</span><span class="pun">.</span><span class="pln">core</span><span class="pun">.</span><span class="pln">signals</span><span class="pun">.</span><span class="pln">got_request_exception</span><span class="pun">)</span><span class="pln"></p>

<p></span><span class="com"># Unregister the rollback event handler.</span><span class="pln">
django</span><span class="pun">.</span><span class="pln">dispatch</span><span class="pun">.</span><span class="pln">dispatcher</span><span class="pun">.</span><span class="pln">disconnect</span><span class="pun">(</span><span class="pln">
    django</span><span class="pun">.</span><span class="pln">db</span><span class="pun">.</span><span class="pln">_rollback_on_exception</span><span class="pun">,</span><span class="pln">
    django</span><span class="pun">.</span><span class="pln">core</span><span class="pun">.</span><span class="pln">signals</span><span class="pun">.</span><span class="pln">got_request_exception</span><span class="pun">)</span><span class="pln">
</span></pre>
Since the writing of the how-to, the connect and disconnect methods have been moved to the Signal object itself; the legacy functions have been removed (see <a title="dispatcher.py diff" href="http://code.djangoproject.com/changeset?new=django%2Ftrunk%2Fdjango%2Fdispatch%2Fdispatcher.py%408291&amp;old=django%2Ftrunk%2Fdjango%2Fdispatch%2Fdispatcher.py%408223">diff</a>). The code SHOULD be:
<pre># Log errors.
django.core.signals.got_request_exception.connect(log_exception)</p>

<h1>Unregister the rollback event handler.</h1>

<p>django.core.signals.got_request_exception.disconnect(
    django.db._rollback_on_exception)</pre>
TADA! Your shit should work on at least revision 9699 of Django.</p>
]]></content:encoded>
			<wfw:commentRss>http://mihasya.com/blog/django-svn-on-google-app-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

