<?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>Mellow Morning &#187; Django</title>
	<atom:link href="http://www.mellowmorning.com/category/django/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mellowmorning.com</link>
	<description>Blogging the world of IT and Business</description>
	<lastBuildDate>Wed, 01 Feb 2012 19:00:15 +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>Facebook open graph publishing simplified</title>
		<link>http://www.mellowmorning.com/2012/02/01/facebook-open-graph/</link>
		<comments>http://www.mellowmorning.com/2012/02/01/facebook-open-graph/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 19:00:15 +0000</pubDate>
		<dc:creator>tschellenbach</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Fashiolista]]></category>
		<category><![CDATA[Marketing]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[f8]]></category>
		<category><![CDATA[open graph]]></category>
		<category><![CDATA[open graph beta]]></category>

		<guid isPermaLink="false">http://www.mellowmorning.com/?p=583</guid>
		<description><![CDATA[Facebook has just enabled the open graph for 60 lucky apps. The new open graph beta allows you to post a user&#8217;s actions to their timeline. This activity is shown to the user&#8217;s friends in Facebook&#8217;s newsfeed and ticker. Furthermore your data is nicely aggregated on a user&#8217;s Facebook profile. Fashiolista&#8217;s aggregation for instance looks [...]]]></description>
			<content:encoded><![CDATA[<p>Facebook has just enabled the open graph for <a href="http://mashable.com/2012/01/18/facebook-60-apps-timeline/" target="_blank">60 lucky apps</a>. The new open graph beta allows you to post a user&#8217;s actions to their timeline. This activity is shown to the user&#8217;s friends in Facebook&#8217;s newsfeed and ticker. Furthermore your data is nicely aggregated on a user&#8217;s Facebook profile. Fashiolista&#8217;s aggregation for instance looks like this:</p>
<p><a href="http://www.mellowmorning.com/wp-content/uploads/2012/01/aggregation.png"><img src="http://www.mellowmorning.com/wp-content/uploads/2012/01/aggregation.png" alt="" title="aggregation" width="417" height="196" class="aligncenter size-full wp-image-638" style="margin-left:70px;" /></a></p>
<p>Posting these actions on Facebook can greatly enhance the viral growth of your company. Spotify, one of the launch partners, has grown by more than <a href="http://techcrunch.com/2011/11/08/music-app-stats/" target="_blank"></a>4mil active users. This blogpost explains how to use <a href="https://github.com/tschellenbach/Django-facebook" target="_blank">Django Facebook</a> to integrate your Django based site with Facebook.</p>
<h3>How open graph works</h3>
<p>Before going into the code though we need to understand the basic concepts of the open graph: <b>actions</b> and <b>objects</b>. Facebook&#8217;s getting started interface explains it best:</p>
<p><a href="http://www.mellowmorning.com/wp-content/uploads/2011/12/Open-Graph-Getting-Started.png"><img class="aligncenter size-full wp-image-608" title="Open Graph Getting Started" src="http://www.mellowmorning.com/wp-content/uploads/2011/12/Open-Graph-Getting-Started.png" alt="" width="533" height="87" style="margin-left:40px;" /></a></p>
<p>Actions are the verb, objects are what the action is applied to. You submit the data for these actions and objects to Facebook. An example would be watching (action) the movie Pan&#8217;s Labyrinth (object). Every object should be represented by a dedicated URL. For instance if you look at <a href="http://www.fashiolista.com/style/chiaraferragni/" target="_blank">Chiara&#8217;s profile (object)</a> on Fashiolista you will see the following open graph data:</p>
<pre class="python" name="code">&lt;meta property="og:title" content="ChiaraFerragni" /&gt;
&lt;meta property="og:image" content="http://bit.ly/rso3ig" /&gt;
&lt;meta property="og:type" content="fashiolista:fashiolista" /&gt;
&lt;meta property="og:site_name" content="Fashiolista" /&gt;</pre>
<p>To post to the open graph you specify an action and the url for the object. You can read more about it in <a href="https://developers.facebook.com/docs/opengraph/" target="_blank" />Facebook&#8217;s open graph docs</a>.</p>
<h3>Getting permission</h3>
<p>Users only need to give you permission to the open graph once. You specifically need the <b>publish_actions</b> permission. When asking for this permission a pretty permission interface as shown below will appear:</p>
<p><a href="http://www.mellowmorning.com/wp-content/uploads/2012/01/authentication.png"><img src="http://www.mellowmorning.com/wp-content/uploads/2012/01/authentication.png" alt="" title="authentication" width="639" height="335" class="aligncenter size-full wp-image-633" /></a></p>
<p>Notice the tiny add to timeline box displayed at the bottom right corner of the interface.</p>
<h3>Posting to the graph</h3>
<p>The code below will show you how to post to the open graph. There are however a few requirements which you&#8217;ll need to go through.</p>
<ol>
<li><a href="https://developers.facebook.com/apps" target="_blank">Register your own Facebook app and define actions and items</a></li>
<li><a href="https://github.com/tschellenbach/Django-facebook" target="_blank">Have Django Facebook installed</a></li>
</ol>
<h4>Simple posting to the graph</h4>
<p>After receiving this permission we can post to the user&#8217;s timeline. Below is the most basic example:</p>
<pre class="python" name="code">@facebook_required(scope='publish_actions')
def open_graph_beta(request):
    '''
    Simple example view on how to do open graph postings
    '''
    fb = get_persistent_graph(request)
    entity_url = 'http://www.fashiolista.com/item/2081202/'
    result = fb.set('me/fashiolista:love', item=entity_url)
    messages.info(request, 'The item has been shared to fashiolista:love')
</pre>
<p>This posts the action <b>love</b> to the users timeline with the object data found at the url http://www.fashiolista.com/item/2081202/.<br />
The syntax me/fashiolista:love translates to post to <b>me</b> in the namespace <b>fashiolista</b> with the action <b>love</b>.</p>
<h4>Asynchronous posting to the graph</h4>
<p>While the above example works, you often won&#8217;t want to keep your users waiting for the Facebook API request. Especially since they are quite sluggish at the moment.<br />
Below there&#8217;s a version of the code using <a href="http://celeryproject.org/" target="_blank">celery</a>. Celery is a task queuing system which enables you to run tasks asynchronously.</p>
<pre class="python" name="code">@task.task(ignore_result=True)
def open_graph_beta(user):
    '''
    Example posting to open graph using a celery task
    '''
    profile = user.get_profile()
    fb = profile.get_offline_graph()
    entity_url = 'http://www.fashiolista.com/item/2081202/'
    result = fb.set('me/fashiolista:love', item=entity_url)</pre>
<h3>Concluding</h3>
<p>Integrating with open graph is easy. Head over to the <a href="https://github.com/tschellenbach/Django-facebook" target="_blank">github page of Django Facebook</a> to get started. Contributions are more than welcome.</p>
<h3>Fashiolista Jobs</h3>
<p>Do you also see the beauty in clean code? Are you experienced with high scalability web apps? Currently we&#8217;re looking for additional talent over at our Amsterdam office. Feel free to drop me a line at my personal email for more information: thierryschellenbach[át]gmail.com</p>



Share and Enjoy:


	<a rel="nofollow" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.mellowmorning.com%2F2012%2F02%2F01%2Ffacebook-open-graph%2F&amp;title=Facebook%20open%20graph%20publishing%20simplified" title="Digg"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://sphinn.com/submit.php?url=http%3A%2F%2Fwww.mellowmorning.com%2F2012%2F02%2F01%2Ffacebook-open-graph%2F&amp;title=Facebook%20open%20graph%20publishing%20simplified" title="Sphinn"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/sphinn.gif" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.mellowmorning.com%2F2012%2F02%2F01%2Ffacebook-open-graph%2F&amp;title=Facebook%20open%20graph%20publishing%20simplified" title="del.icio.us"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.mellowmorning.com%2F2012%2F02%2F01%2Ffacebook-open-graph%2F&amp;t=Facebook%20open%20graph%20publishing%20simplified" title="Facebook"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.mellowmorning.com%2F2012%2F02%2F01%2Ffacebook-open-graph%2F&amp;title=Facebook%20open%20graph%20publishing%20simplified" title="Mixx"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.mellowmorning.com%2F2012%2F02%2F01%2Ffacebook-open-graph%2F&amp;title=Facebook%20open%20graph%20publishing%20simplified" title="Google"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google" alt="Google" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.mellowmorning.com/2012/02/01/facebook-open-graph/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django Facebook 3.2 &#8211; Simple image upload and wall posts</title>
		<link>http://www.mellowmorning.com/2011/10/23/django-facebook-3-2-simple-image-upload-and-wall-posts/</link>
		<comments>http://www.mellowmorning.com/2011/10/23/django-facebook-3-2-simple-image-upload-and-wall-posts/#comments</comments>
		<pubDate>Sun, 23 Oct 2011 22:21:27 +0000</pubDate>
		<dc:creator>tschellenbach</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Fashiolista]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[decorator]]></category>
		<category><![CDATA[facebook_required]]></category>

		<guid isPermaLink="false">http://www.mellowmorning.com/?p=568</guid>
		<description><![CDATA[Most of the Facebook examples are written in PHP and unfortunately for us they always seem so damn simple. I think the Python libraries should allow you to write more elegant code and the new version of Django Facebook let&#8217;s you do just that.
Much of the new found simplicity comes from the facebook_required decorator. This [...]]]></description>
			<content:encoded><![CDATA[<p>Most of the <a href="http://developers.facebook.com/blog/post/498">Facebook examples </a>are written in PHP and unfortunately for us they always seem so damn simple. I think the Python libraries should allow you to write more elegant code and the new version of <a href="https://github.com/tschellenbach/Django-facebook">Django Facebook</a> let&#8217;s you do just that.</p>
<p>Much of the new found simplicity comes from the facebook_required decorator. This decorator is similar to login_required, but instead checks the Facebook permissions given to you. Writing the input of a form to someone&#8217;s wall is now as simple as this:</p>
<pre class="python" name="code">
@facebook_required(scope='publish_stream')
def wall_post(request):
    fb = get_persistent_graph(request)

    message = request.POST.get('message')
    fb.set('me/feed', message=message)

    messages.info(request, 'Posted the message to your wall')

    return next_redirect(request)
</pre>
<p>Another example would be uploading some photos to a user&#8217;s timeline:</p>
<pre class="python" name="code">
@facebook_required(scope='publish_stream,user_photos')
def image_upload(request):
    fb = get_persistent_graph(request)
    pictures = request.POST.getlist('pictures')

    for picture in pictures:
        fb.set('me/photos', url=picture, message='the writing is one The '
            'wall image %s' % picture)

    messages.info(request, 'The images have been added to your profile!')

    return next_redirect(request)
</pre>
<p>As you can see the syntax is very straightforward. You no longer have any technical excuse against integrating Facebook.<br />
More examples and installation instructions can be found on <a href="https://github.com/tschellenbach/Django-facebook">Django Facebook&#8217;s github</a>.</p>



Share and Enjoy:


	<a rel="nofollow" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F10%2F23%2Fdjango-facebook-3-2-simple-image-upload-and-wall-posts%2F&amp;title=Django%20Facebook%203.2%20-%20Simple%20image%20upload%20and%20wall%20posts" title="Digg"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://sphinn.com/submit.php?url=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F10%2F23%2Fdjango-facebook-3-2-simple-image-upload-and-wall-posts%2F&amp;title=Django%20Facebook%203.2%20-%20Simple%20image%20upload%20and%20wall%20posts" title="Sphinn"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/sphinn.gif" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F10%2F23%2Fdjango-facebook-3-2-simple-image-upload-and-wall-posts%2F&amp;title=Django%20Facebook%203.2%20-%20Simple%20image%20upload%20and%20wall%20posts" title="del.icio.us"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F10%2F23%2Fdjango-facebook-3-2-simple-image-upload-and-wall-posts%2F&amp;t=Django%20Facebook%203.2%20-%20Simple%20image%20upload%20and%20wall%20posts" title="Facebook"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F10%2F23%2Fdjango-facebook-3-2-simple-image-upload-and-wall-posts%2F&amp;title=Django%20Facebook%203.2%20-%20Simple%20image%20upload%20and%20wall%20posts" title="Mixx"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F10%2F23%2Fdjango-facebook-3-2-simple-image-upload-and-wall-posts%2F&amp;title=Django%20Facebook%203.2%20-%20Simple%20image%20upload%20and%20wall%20posts" title="Google"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google" alt="Google" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.mellowmorning.com/2011/10/23/django-facebook-3-2-simple-image-upload-and-wall-posts/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Amsterdam based, VC funded startup, Fashiolista looking for new team members</title>
		<link>http://www.mellowmorning.com/2011/08/15/amsterdam-based-vc-funded-startup-fashiolista-looking-for-new-team-members/</link>
		<comments>http://www.mellowmorning.com/2011/08/15/amsterdam-based-vc-funded-startup-fashiolista-looking-for-new-team-members/#comments</comments>
		<pubDate>Mon, 15 Aug 2011 08:44:32 +0000</pubDate>
		<dc:creator>tschellenbach</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Fashiolista]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.mellowmorning.com/?p=424</guid>
		<description><![CDATA[Over the past months Fashiolista has grown to be one of the largest fashion communities worldwide. Dividing attention between scaling the site and creating new features has been quite a challenge. We are looking for a very experienced django developer to join our team.
About Fashiolista
Fashiolista is best described as &#8220;twitter for fashion&#8221;. Girls follow each [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mellowmorning.com/wp-content/uploads/2011/08/logo_fashiolista_700x350_new1.png"><img class="alignleft" title="logo_fashiolista_700x350_new[1]" src="http://www.mellowmorning.com/wp-content/uploads/2011/08/logo_fashiolista_700x350_new1-e1313257985852.png" alt="" width="200" height="100" /></a>Over the past months Fashiolista has grown to be one of the largest fashion communities worldwide. Dividing attention between scaling the site and creating new features has been quite a challenge. We are looking for a very experienced django developer to join our team.</p>
<h3>About Fashiolista</h3>
<p>Fashiolista is best described as &#8220;twitter for fashion&#8221;. Girls follow each other&#8217;s fashion finds and indicate which items they love. We are funded by Atomico ventures and several high profile angel investors.</p>
<h3>Why you will love working at Fashiolista</h3>
<p>- Young team, startup culture<br />
- Developers in the founding team<br />
- The team has been working with Django for more than 4 years<br />
- Modern stack (Django 1.3, postgres, redis, memcached, jquery, celery, solr, GIT)<br />
- Learning culture</p>
<p>Did I mention we are located in the centre of Amsterdam?</p>
<h3>Who we are looking for</h3>
<p>We are looking for a talented Django developer with experience in building highly scalable applications. Since our team is small, strong experience with Linux or Freebsd system administration would be a big plus.</p>
<ul>
<li>Experienced with Django and Python (&gt; 3 years preferably)</li>
<li>Knowledge of SQL and query optimization</li>
<li>Javascript experience</li>
<li>Test driven development</li>
<li>Memcached and other caching techniques</li>
<li>GIT</li>
</ul>
<p><strong>Bonus points for</strong>:</p>
<ul>
<li>Knowledge of FreeBSD or Linux system administration</li>
<li>Redis/ NoSql experience</li>
<li>SOLR experience</li>
<li>Postgres Trigger experience</li>
<li>Celery experience</li>
<li>CS degree</li>
</ul>
<p>For this position you need to be willing to work in The Netherlands/ Amsterdam. Furthermore the position is full time.</p>
<h3>To conclude</h3>
<p>We are looking for someone with an excellent work attitude and considerable experience. It doesn’t matter if you are a student, cum laude graduate, or drop out, as long as you&#8217;re extremely passionate about what you do. You will be working in a startup and we expect your input on a wide range of challenges.</p>
<p>If you recognize yourself in the above description or would like more information please contact me at:<br />
thierry&#8230;fashiolista.com</p>



Share and Enjoy:


	<a rel="nofollow" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F08%2F15%2Famsterdam-based-vc-funded-startup-fashiolista-looking-for-new-team-members%2F&amp;title=Amsterdam%20based%2C%20VC%20funded%20startup%2C%20Fashiolista%20looking%20for%20new%20team%20members" title="Digg"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://sphinn.com/submit.php?url=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F08%2F15%2Famsterdam-based-vc-funded-startup-fashiolista-looking-for-new-team-members%2F&amp;title=Amsterdam%20based%2C%20VC%20funded%20startup%2C%20Fashiolista%20looking%20for%20new%20team%20members" title="Sphinn"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/sphinn.gif" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F08%2F15%2Famsterdam-based-vc-funded-startup-fashiolista-looking-for-new-team-members%2F&amp;title=Amsterdam%20based%2C%20VC%20funded%20startup%2C%20Fashiolista%20looking%20for%20new%20team%20members" title="del.icio.us"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F08%2F15%2Famsterdam-based-vc-funded-startup-fashiolista-looking-for-new-team-members%2F&amp;t=Amsterdam%20based%2C%20VC%20funded%20startup%2C%20Fashiolista%20looking%20for%20new%20team%20members" title="Facebook"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F08%2F15%2Famsterdam-based-vc-funded-startup-fashiolista-looking-for-new-team-members%2F&amp;title=Amsterdam%20based%2C%20VC%20funded%20startup%2C%20Fashiolista%20looking%20for%20new%20team%20members" title="Mixx"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F08%2F15%2Famsterdam-based-vc-funded-startup-fashiolista-looking-for-new-team-members%2F&amp;title=Amsterdam%20based%2C%20VC%20funded%20startup%2C%20Fashiolista%20looking%20for%20new%20team%20members" title="Google"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google" alt="Google" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.mellowmorning.com/2011/08/15/amsterdam-based-vc-funded-startup-fashiolista-looking-for-new-team-members/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django Facebook 3.0 &#8211; OAuth migration &#8211; Time to upgrade!</title>
		<link>http://www.mellowmorning.com/2011/08/13/django-facebook-3-0-oauth-migration-time-to-upgrade/</link>
		<comments>http://www.mellowmorning.com/2011/08/13/django-facebook-3-0-oauth-migration-time-to-upgrade/#comments</comments>
		<pubDate>Sat, 13 Aug 2011 14:40:16 +0000</pubDate>
		<dc:creator>tschellenbach</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Fashiolista]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[django facebook]]></category>
		<category><![CDATA[open graph]]></category>
		<category><![CDATA[open graph api]]></category>

		<guid isPermaLink="false">http://www.mellowmorning.com/?p=434</guid>
		<description><![CDATA[Facebook is migrating to HTTPS and OAuth to increase the safety of their users. Unfortunately these changes aren&#8217;t backwards compatible and will require some effort to follow. To support the new Facebook system you need to upgrade to Django Facebook 3.0 before October 1st.
In addition to the required migrations, this version also includes several new [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Facebook is migrating to HTTPS and OAuth to increase the safety of their users. Unfortunately these changes aren&#8217;t backwards compatible and will require some effort to follow. To support the new Facebook system you need to upgrade to <a href="https://github.com/tschellenbach/Django-facebook">Django Facebook 3.0</a> before October 1st.</strong></p>
<p>In addition to the required migrations, this version also includes several new features. The largest change is the underlying Facebook API client. You can read about the improvements here or skip down to the upgrade instructions.</p>
<h3>Open Facebook &#8211; New Python Facebook client</h3>
<p>Open Facebook is a python client to the Facebook graph API. Currently it&#8217;s included in Django Facebook, but in time it will be spun of as a separate project. The client is supported, tested and up to date with the current version of Facebook&#8217;s graph API.<br />
It handles connection issues cleanly and raises separate error classes for various Facebook error scenarios.<br />
The syntax is very straightforward to use:</p>
<pre class="python" name="code">
open_facebook = OpenFacebook(token)
#info about me
open_facebook.me()

#retrieving a page
open_facebook.get('fashiolista')

#retrieving your albums
open_facebook.get('me/albums')

#posting a message on your wall
open_facebook.set('me/feed', message='Check out Fashiolista', picture=image_url)

#setting a like
open_facebook.set('fashiolista/likes')

#fql example
result = open_facebook.fql('SELECT name FROM user WHERE uid = me()')

#authorization is handled separately from the API class
token = FacebookAuthorization.get_app_access_token()
test_user = FacebookAuthorization.create_test_user(token)
</pre>
<h4>Album upload Example</h4>
<p>Uploading pictures to Facebook is as simple as this:</p>
<pre class="python" name="code">
open_facebook = get_facebook_graph(request)
photo_urls = [
    'http://d.fashiocdn.com/images/entities/0/6/t/p/d/0.365x365.jpg',
    'http://e.fashiocdn.com/images/entities/0/5/E/b/Q/0.365x365.jpg',
]
for photo in photo_urls:
    uploaded = open_facebook.set('me/photos', url=photo,
        message='Fashiolista is awesome', name='FashiolistaTest'
    )
</pre>
<p>So there are good reasons to upgrade even if Facebook didn&#8217;t force us to :)</p>
<h3>How to upgrade to 3.0</h3>
<p><b>First Step &#8211; Install Django Facebook 3.0</b><br />
Follow the <a href="https://github.com/tschellenbach/Django-facebook/">installation instructions.</a></p>
<p><b>Javascript changes</b><br />
In your Facebook initialization code enable OAuth. </p>
<pre class="javascript" name="code">
FB.init({appId: facebookAppId, status: false, cookie: true, xfbml: true, oauth: true});
</pre>
<p>Perms has been renamed to scope.</p>
<pre class="javascript" name="code">
FB.login(function() {}, {'scope' : 'offline_access'});
</pre>
<p><b>Django Facebook changes</b><br />
The get_facebook_graph function is no longer persistent by default, if you want the old behavior use get_persistent_graph.<br />
Furthermore the FacebookUserConverter class and the core Facebook API client are now separated. get_facebook_graph returns the core facebook API client. To go from the API class to the user converter class use something like</p>
<pre class="python" name="code">
graph = get_facebook_graph(request)
facebook = FacebookUserConverter(graph)
</pre>
<p>That should be all.<br />
If you are encountering problems feel free to let me know in the comments.</p>
<p><b>Last Step &#8211; Enable the new Facebook Migrations</b><br />
Go to the <a href="https://developers.facebook.com/apps">Facebook Apps page</a> and enable the OAuth migration.<br />
Select your app -> About -> Advanced -> Migrations<br />
Enable Force OAuth<br />
Enable OAuth Migration</p>
<h3>Background reading</h3>
<p><a href="http://developers.facebook.com/blog/post/497/">Moving to OAuth 2.0 + HTTPS</a><br />
<a href="http://developers.facebook.com/blog/post/525/">Updated JavaScript SDK and OAuth 2.0 Roadmap</a><br />
<a href="http://developers.facebook.com/docs/authentication/">New Facebook Authentication Docs</a><br />
<a href="http://developers.facebook.com/blog/post/534/">PHP SDK v.3.1.1</a><br />
<a href="http://developers.facebook.com/blog/post/503/">PHP SDK v3.0.0</a></p>
<h3>We&#8217;re hiring!</h3>
<p>Do you also see the beauty in clean code? Are you experienced with high scalability web apps? Currently we&#8217;re looking for additional talent over at our Amsterdam office. Feel free to drop me a line at my personal email for more information: thierryschellenbach[at]gmail.com</p>



Share and Enjoy:


	<a rel="nofollow" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F08%2F13%2Fdjango-facebook-3-0-oauth-migration-time-to-upgrade%2F&amp;title=Django%20Facebook%203.0%20-%20OAuth%20migration%20-%20Time%20to%20upgrade%21" title="Digg"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://sphinn.com/submit.php?url=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F08%2F13%2Fdjango-facebook-3-0-oauth-migration-time-to-upgrade%2F&amp;title=Django%20Facebook%203.0%20-%20OAuth%20migration%20-%20Time%20to%20upgrade%21" title="Sphinn"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/sphinn.gif" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F08%2F13%2Fdjango-facebook-3-0-oauth-migration-time-to-upgrade%2F&amp;title=Django%20Facebook%203.0%20-%20OAuth%20migration%20-%20Time%20to%20upgrade%21" title="del.icio.us"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F08%2F13%2Fdjango-facebook-3-0-oauth-migration-time-to-upgrade%2F&amp;t=Django%20Facebook%203.0%20-%20OAuth%20migration%20-%20Time%20to%20upgrade%21" title="Facebook"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F08%2F13%2Fdjango-facebook-3-0-oauth-migration-time-to-upgrade%2F&amp;title=Django%20Facebook%203.0%20-%20OAuth%20migration%20-%20Time%20to%20upgrade%21" title="Mixx"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F08%2F13%2Fdjango-facebook-3-0-oauth-migration-time-to-upgrade%2F&amp;title=Django%20Facebook%203.0%20-%20OAuth%20migration%20-%20Time%20to%20upgrade%21" title="Google"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google" alt="Google" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.mellowmorning.com/2011/08/13/django-facebook-3-0-oauth-migration-time-to-upgrade/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Django Facebook 2.0 &#8211; Integrating Facebook</title>
		<link>http://www.mellowmorning.com/2011/06/23/django-facebook-2-0-integrating-facebook/</link>
		<comments>http://www.mellowmorning.com/2011/06/23/django-facebook-2-0-integrating-facebook/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 15:18:40 +0000</pubDate>
		<dc:creator>tschellenbach</dc:creator>
				<category><![CDATA[Css]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Fashiolista]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[django facebook]]></category>
		<category><![CDATA[Facebook connect]]></category>
		<category><![CDATA[Facebook login]]></category>
		<category><![CDATA[Facebook registration]]></category>
		<category><![CDATA[facebook sdk]]></category>
		<category><![CDATA[open graph]]></category>
		<category><![CDATA[Social authentication]]></category>

		<guid isPermaLink="false">http://www.mellowmorning.com/?p=350</guid>
		<description><![CDATA[It&#8217;s been a year since Facebook changed the web with the open graph API and their like button. Unfortunately Facebook didn&#8217;t have much developer love for the python/django platform. Django Facebook aims to make it easy to build facebook apps and integrate facebook with your website.
Key functionality
One of the strong points of Django Facebook is [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a year since Facebook changed the web with the open graph API and their like button. Unfortunately Facebook didn&#8217;t have much <a href="http://developers.facebook.com/blog/post/417/">developer love</a> for the python/django platform. <a href="https://github.com/tschellenbach/Django-facebook">Django Facebook</a> aims to make it easy to build facebook apps and integrate facebook with your website.</p>
<h3>Key functionality</h3>
<p>One of the strong points of Django Facebook is the ability to register users using Facebook. It ports all of Facebook&#8217;s user data to the Django user and profile models. This allows you to have a secure register/connect/login flow using Facebook, greatly reducing the barriers to start using your application. Below an example of me registering for Fashiolista using the <a href="http://www.fashiolista.com/intro_wide/">Facebook register flow</a>. </p>
<p style="text-align: center;"><b>Me on Facebook</b><br /><img class="size-full wp-image-366 aligncenter" title="thierry_facebook" src="http://www.mellowmorning.com/wp-content/uploads/2011/05/thierry_facebook.png" alt="" width="569" height="196" /></p>
<p style="text-align: center;"><b>Me on Fashiolista</b><br /><img class="size-full wp-image-367 aligncenter" title="thierry_fashiolista" src="http://www.mellowmorning.com/wp-content/uploads/2011/05/thierry_fashiolista.png" alt="" width="499" height="284" /></p>
<p>In this blog post I will explain how to get started implementing a Facebook connect flow. Django Facebook can however do quite a bit more, as you can see in the feature list below. Development over at the <a href="https://github.com/tschellenbach/Django-facebook">github repo</a> is very active. I strongly appreciate help on improving the functionality so please fork and contribute.</p>
<p><b>Features</b></p>
<ul>
<li>Register users using the Facebook open graph API
<ul>
<li>Full profile data birthday, gender, website, about me, username, email and picture</li>
<li>Support for mobile authentication</li>
<li>Fallback to registration form for entering additional data when required</li>
</ul>
</li>
<li>Build Facebook Canvas applications</li>
<li>Mobile registration using Facebook</li>
<li>Execute Facebook FQL queries</li>
<li>Upload pictures to Facebook</li>
<li>Find your Facebook friends</li>
</ul>
<h3>Getting Started</h3>
<p>Now let&#8217;s get started with building a Facebook login/connect/register flow. This post will guide you through it step by step.</p>
<h4>Prerequisites</h4>
<p><a href="http://www.facebook.com/developers/createapp.php" target="_blank">Create a Facebook app</a></p>
<p><a href="https://bitbucket.org/ubernostrum/django-registration/" target="_blank">Have django registration installed</a> (other registration systems will require some small code changes)</p>
<p>pip install django_facebook :)</p>
<h4>A.) Settings and more</h4>
<p>Define these settings in your settings file.<br />
FACEBOOK_API_KEY<br />
FACEBOOK_APP_ID<br />
FACEBOOK_APP_SECRET</p>
<p>add django facebook to your installed apps<br />
&#8216;django_facebook&#8217;,<br />
add this line to your url config<br />
(r&#8217;^facebook/&#8217;, include(&#8216;django_facebook.urls&#8217;)),<br />
add this line to your context processors<br />
&#8216;django_facebook.context_processors.facebook&#8217;,<br />
add this to your AUTHENTICATION_BACKENDS<br />
&#8216;django_facebook.auth_backends.FacebookBackend&#8217;,</p>
<h4>B.) Adjust your user Profile model</h4>
<p>Secondly we need to be able to store the Facebook data on your user profile.<br />
The easiest way to do this is to add the abstract model in django_facebook/models.py called FacebookProfileModel to your profile model.<br />
After your profile is ready to store Facebook data you should have a working example at /facebook/connect/.<br />
Let me know in the comments if something went wrong up to this point :)</p>
<h4>C.) Design and integration</h4>
<p>You can style the facebook form and button anyway you see fit. <a href="http://www.fashiolista.com/intro_wide/">Over at Fashiolista</a> we added a nice facepile for example. The basic markup is located in the example file connect.html.<br />
We use the facebook javascript SDK for a smooth user integration. You can load the facebook JS like this:</p>
<pre class="javascript" name="code">&lt;script src="{{ MEDIA_URL }}js/original/facebook.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script&gt;
facebookAppId = '{{ FACEBOOK_APP_ID }}';
function facebookJSLoaded(){
FB.init({appId: facebookAppId, status: false, cookie: true, xfbml: true});
}
window.fbAsyncInit = facebookJSLoaded;
F = new facebookClass(facebookAppId);
F.load();
&lt;/script&gt;</pre>
<p>Subsequently implement a form which calls Facebook via javascript. Note that you can control which page to go to after connect using the next input field.</p>
<pre class="python" name="code">&lt;form action="{% url facebook_connect %}?facebook_login=1" method="post"&gt;
&lt;a href="javascript:void(0);" style="font-size: 20px;" onclick="F.connect(this.parentNode);"&gt;Register, login or connect with facebook&lt;/a&gt;
&lt;input type="hidden" value="{{ request.path }}" name="next" /&gt;
&lt;/form&gt;
&lt;div id="fb-root"&gt;&lt;/div&gt;</pre>
<p>That was all, you should now have a working registration flow using Facebook. Let me know in the comments if you encounter any difficulties.<br />
If you want to go one step further and understand the facebook API, you can find the <a href="http://developers.facebook.com/docs/">Facebook documentation here</a>.<br />
Django Facebook received tons of improvements from the python community. I&#8217;m certainly missing a few authors, but I would like to thank a few specifically:</p>
<p><strong>Many thanks to (amongst many others)</strong></p>
<ul>
<li><a href="http://gigantuan.net" target="_blank">Kenneth Love</a></li>
<li><a href="http://gc-taylor.com" target="_blank">Greg Taylor</a></li>
<li><a href="http://www.linkedin.com/pub/riccardo-magliocchetti/6/ba/105" target="_blank">Riccardo Magliocchetti</a></li>
<li><a href="http://djangopeople.net/kmike/" target="_blank">Mikhail Korobov</a></li>
<li>Simple Geebus</li>
<li><a href="http://twitter.com/jonrohan" target="_blank">Jon Rohan</a></li>
<li>Rick van Hattem</li>
<li><a href="http://www.stochastictechnologies.com" target="_blank">Stochastic Technologies</a></li>
<li><a href="https://simplegeo.com/" target="_blank">Simplegeo</a></li>
<li><a href="http://www.canb.net/" target="_blank">Can Burak Cilingir</a></li>
<li>zdexter</li>
<li><a href="http://apps.facebook.com/railroadempire" target="_blank">Michael Robellard</a></li>
<li><a href="https://github.com/ramiro" target="_blank">Ramiro Morales</a></li>
</ul>
<h3>More posts coming up</h3>
<ul>
<li>Building a facebook canvas app using Django Facebook</li>
<li>Find and invite friends using Django Facebook</li>
</ul>
<h3>We&#8217;re hiring!</h3>
<p>Do you also see the beauty in clean code? Are you experienced with high scalability web apps? Currently we&#8217;re looking for additional talent over at our Amsterdam office. Feel free to drop me a line at my personal email for more information: thierryschellenbach[at]gmail.com</p>



Share and Enjoy:


	<a rel="nofollow" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F06%2F23%2Fdjango-facebook-2-0-integrating-facebook%2F&amp;title=Django%20Facebook%202.0%20-%20Integrating%20Facebook" title="Digg"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://sphinn.com/submit.php?url=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F06%2F23%2Fdjango-facebook-2-0-integrating-facebook%2F&amp;title=Django%20Facebook%202.0%20-%20Integrating%20Facebook" title="Sphinn"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/sphinn.gif" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F06%2F23%2Fdjango-facebook-2-0-integrating-facebook%2F&amp;title=Django%20Facebook%202.0%20-%20Integrating%20Facebook" title="del.icio.us"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F06%2F23%2Fdjango-facebook-2-0-integrating-facebook%2F&amp;t=Django%20Facebook%202.0%20-%20Integrating%20Facebook" title="Facebook"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F06%2F23%2Fdjango-facebook-2-0-integrating-facebook%2F&amp;title=Django%20Facebook%202.0%20-%20Integrating%20Facebook" title="Mixx"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F06%2F23%2Fdjango-facebook-2-0-integrating-facebook%2F&amp;title=Django%20Facebook%202.0%20-%20Integrating%20Facebook" title="Google"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google" alt="Google" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.mellowmorning.com/2011/06/23/django-facebook-2-0-integrating-facebook/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Mock Django Request for testing</title>
		<link>http://www.mellowmorning.com/2011/04/18/mock-django-request-for-testing/</link>
		<comments>http://www.mellowmorning.com/2011/04/18/mock-django-request-for-testing/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 12:53:11 +0000</pubDate>
		<dc:creator>tschellenbach</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Fashiolista]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.mellowmorning.com/?p=343</guid>
		<description><![CDATA[When testing your applications I sometimes find myself needing to mock a request object. Unfortunately it is quite hard to find a good fake request factory which mimics a normal request.
Django has a class included for this purpose called RequestFactory. However it doesn&#8217;t fake the session object, breaking most of my test code. To fix [...]]]></description>
			<content:encoded><![CDATA[<p>When testing your applications I sometimes find myself needing to mock a request object. Unfortunately it is quite hard to find a good fake request factory which mimics a normal request.</p>
<p>Django has a class included for this purpose called RequestFactory. However it doesn&#8217;t fake the session object, breaking most of my test code. To fix this I wrote a tiny snippet implementing the RequestFactory with session and user support. Hope it helps :)</p>
<pre class="python" name="code">
from django.core.handlers.base import BaseHandler
from django.test.client import RequestFactory

class RequestMock(RequestFactory):
    def request(self, **request):
        "Construct a generic request object."
        request = RequestFactory.request(self, **request)
        handler = BaseHandler()
        handler.load_middleware()
        for middleware_method in handler._request_middleware:
            if middleware_method(request):
                raise Exception("Couldn't create request mock object - "
                                "request middleware returned a response")
        return request
</pre>
<p><a href="https://gist.github.com/925270">See the gist here.</a></p>



Share and Enjoy:


	<a rel="nofollow" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F04%2F18%2Fmock-django-request-for-testing%2F&amp;title=Mock%20Django%20Request%20for%20testing" title="Digg"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://sphinn.com/submit.php?url=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F04%2F18%2Fmock-django-request-for-testing%2F&amp;title=Mock%20Django%20Request%20for%20testing" title="Sphinn"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/sphinn.gif" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F04%2F18%2Fmock-django-request-for-testing%2F&amp;title=Mock%20Django%20Request%20for%20testing" title="del.icio.us"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F04%2F18%2Fmock-django-request-for-testing%2F&amp;t=Mock%20Django%20Request%20for%20testing" title="Facebook"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F04%2F18%2Fmock-django-request-for-testing%2F&amp;title=Mock%20Django%20Request%20for%20testing" title="Mixx"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F04%2F18%2Fmock-django-request-for-testing%2F&amp;title=Mock%20Django%20Request%20for%20testing" title="Google"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google" alt="Google" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.mellowmorning.com/2011/04/18/mock-django-request-for-testing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mixing Django with Jinja2 without losing template debugging</title>
		<link>http://www.mellowmorning.com/2010/08/24/mixing-django-with-jinja2-without-losing-template-debugging/</link>
		<comments>http://www.mellowmorning.com/2010/08/24/mixing-django-with-jinja2-without-losing-template-debugging/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 01:26:39 +0000</pubDate>
		<dc:creator>Rick van Hattem</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Jinja2]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.mellowmorning.com/?p=321</guid>
		<description><![CDATA[At Fashiolista we&#8217;ve build nearly the entire site with Jinja instead of the Django template engine.
There are a lot of reasons for choosing Jinja2 over Django for us. Better performance (atleast&#8230; it was a lot better with previous Django versions), way more options (named arguments, multiple arguments for filters, etc), macros and simply easier to [...]]]></description>
			<content:encoded><![CDATA[<p>At Fashiolista we&#8217;ve build nearly the entire site with Jinja instead of the Django template engine.</p>
<p>There are a lot of reasons for choosing Jinja2 over Django for us. Better performance (atleast&#8230; it was a lot better with previous Django versions), way more options (named arguments, multiple arguments for filters, etc), macros and simply easier to extend. Writing custom tags is simply not needed anymore since you can just make any function callable from the templates.</p>
<p>But&#8230; during the conversion there are always moments when you need  a Django function in a Jinja template or vice versa. So&#8230; I created a few template tags to allow for Jinja code in Django templates (I&#8217;ve also created code to run Django code from Jinja, but I haven&#8217;t seen the need for it so I omitted it here).</p>
<p>A Jinja Include tag to include a template and let it be parsed by Jinja from a Django template:</p>
<pre class="python" name="code">from django import template
from coffin import shortcuts as jinja_shortcuts                                                                                                                                                      

register = template.Library()                                                                                                                                                                        

class JinjaInclude(template.Node):
    def __init__(self, filename):
        self.filename = filename                                                                                                                                                                     

    def render(self, context):
        return jinja_shortcuts.render_to_string(self.filename, context)                                                                                                                              

@register.tag
def jinja_include(parser, token):
    bits = token.contents.split()                                                                                                                                                                    

    '''Check if a filename was given'''
    if len(bits) != 2:
        raise template.TemplateSyntaxError('%r tag requires the name of the '
            'template to be included included ' % bits[0])
    filename = bits[1]                                                                                                                                                                               

    '''Remove quotes if used'''
    if filename[0] in ('"', "'") and filename[-1] == filename[0]:
        filename = bits[1:-1]                                                                                                                                                                        

    return JinjaInclude(filename)</pre>
<p>Usage:</p>
<pre class="javascript" name="code">{% jinja_include "some_template.html" %}</pre>
<p>A couple of noop nodes to make sure that when you convert your Jinja templates to be executed from Django, they won&#8217;t break because of the missing Django tag.</p>
<pre class="python" name="code">from django import template

class Empty(template.Node):
    def render(self, context):
        return ''                                                                                                                                                                                    

@register.tag
def django(parser, token):
    return Empty()                                                                                                                                                                                   

@register.tag
def end_django(parser, token):
    return Empty()</pre>
<p>And the Jinja tag to allow Jinja blocks in Django templates.</p>
<pre class="python" name="code">from django import template
from coffin.template import Template

register = template.Library()

class Jinja(template.Node):
    def __init__(self, template):
        self.template = template                                                                                                                                                                     

    def render(self, context):
        return self.template.render(context)                                                                                                                                                         

@register.tag
def jinja(parser, token):
    '''Create a Jinja template block                                                                                                                                                                 

    Usage:
    {% jinja %}
    Although you're in a Django template, code here will be executed by Jinja
    {% end_jinja %}
    '''                                                                                                                                                                                              

    '''Generate the end tag from the currently used tag name'''
    end_tag = 'end_%s' % token.contents.split()[0]                                                                                                                                                   

    tokens = []
    '''Convert all tokens to the string representation of them
    That way we can keep Django template debugging with Jinja and feed the
    entire string to Jinja'''
    while parser.tokens:
        token = parser.next_token()
        if token.token_type == template.TOKEN_TEXT:
            tokens.append(token.contents)                                                                                                                                                            

        elif token.token_type == template.TOKEN_VAR:
            tokens.append(' '.join((
                template.VARIABLE_TAG_START,
                token.contents,
                template.VARIABLE_TAG_END,
            )))                                                                                                                                                                                      

        elif token.token_type == template.TOKEN_BLOCK:
            if token.contents == end_tag:
                break                                                                                                                                                                                

            tokens.append(' '.join((
                template.BLOCK_TAG_START,
                token.contents,
                template.BLOCK_TAG_END,
            )))                                                                                                                                                                                      

        elif token.token_type == template.TOKEN_COMMENT:
            pass                                                                                                                                                                                     

        else:
            raise template.TemplateSyntaxError('Unknown token type: "%s"' % token.token_type)                                                                                                        

    '''If our token has a `source` attribute than template_debugging is
    enabled. If it's enabled create a valid source attribute for the Django
    template debugger'''
    if hasattr(token, 'source'):
        source = token.source[0], (token.source[1][0], token.source[1][1])
    else:
        source = None                                                                                                                                                                                

    return Jinja(Template(''.join(tokens), source=source))</pre>
<p>Do note that I have modified the &#8220;coffin.template.Template&#8221; to enable debugging completely. Just replace the &#8220;Template&#8221; class in &#8220;coffin/template/__init__.py&#8221; to make it work.</p>
<pre class="python" name="code">def _generate_django_exception(e, source=None):
    '''Generate a Django exception from a Jinja source'''
    from django.views.debug import linebreak_iter                                                                                                                                                    

    if source:
        exception = DjangoTemplateSyntaxError(e.message)
        exception_dict = e.__dict__
        del exception_dict['source']                                                                                                                                                                 

        '''Fetch the entire template in a string'''
        template_string = source[0].reload()                                                                                                                                                         

        '''Get the line number from the error message, if available'''
        match = re.match('.* at (\d+)$', e.message)                                                                                                                                                  

        start_index = 0
        stop_index = 0
        if match:
            '''Convert the position found in the stacktrace to a position
            the Django template debug system can use'''
            position = int(match.group(1)) + source[1][0] + 1                                                                                                                                        

            for index in linebreak_iter(template_string):
                if index &gt;= position:
                    stop_index = min(index, position + 3)
                    start_index = min(index, position - 2)
                    break
                start_index = index                                                                                                                                                                  

        else:
            '''So there wasn't a matching error message, in that case we
            simply have to highlight the entire line instead of the specific
            words'''
            ignore_lines = 0
            for i, index in enumerate(linebreak_iter(template_string)):
                if source[1][0] &gt; index:
                    ignore_lines += 1                                                                                                                                                                

                if i - ignore_lines == e.lineno:
                    stop_index = index
                    break                                                                                                                                                                            

                start_index = index                                                                                                                                                                  

        '''Convert the positions to a source that is compatible with the
        Django template debugger'''
        source = source[0], (
            start_index,
            stop_index,
        )
    else:
        '''No source available so we let Django fetch it for us'''
        lineno = e.lineno - 1
        template_string, source = django_loader.find_template_source(e.name)
        exception = DjangoTemplateSyntaxError(e.message)                                                                                                                                             

        '''Find the positions by the line number given in the exception'''
        start_index = 0
        for i in range(lineno):
            start_index = template_string.index('\n', start_index + 1)                                                                                                                               

        source = source, (
            start_index + 1,
            template_string.index('\n', start_index + 1) + 1,
        )                                                                                                                                                                                            

    exception.source = source
    return exception          

class Template(_Jinja2Template):
    """Fixes the incompabilites between Jinja2's template class and
    Django's.                                                                                                                                                                                        

    The end result should be a class that renders Jinja2 templates but
    is compatible with the interface specfied by Django.                                                                                                                                             

    This includes flattening a ``Context`` instance passed to render
    and making sure that this class will automatically use the global
    coffin environment.
    """                                                                                                                                                                                              

    def __new__(cls, template_string, origin=None, name=None, source=None):
        # We accept the "origin" and "name" arguments, but discard them
        # right away - Jinja's Template class (apparently) stores no
        # equivalent information.
        from coffin.common import env                                                                                                                                                                

        try:
            return env.from_string(template_string, template_class=cls)
        except JinjaTemplateSyntaxError, e:
            raise _generate_django_exception(e, source)                                                                                                                                              

    def __iter__(self):
        # TODO: Django allows iterating over the templates nodes. Should
        # be parse ourself and iterate over the AST?
        raise NotImplementedError()                                                                                                                                                                  

    def render(self, context=None):
        """Differs from Django's own render() slightly in that makes the
        ``context`` parameter optional. We try to strike a middle ground
        here between implementing Django's interface while still supporting
        Jinja's own call syntax as well.
        """
        if not context:
            context = {}
        else:
            context = dict_from_django_context(context)                                                                                                                                              

        try:
            return super(Template, self).render(context)
        except JinjaTemplateSyntaxError, e:
            raise _generate_django_exception(e)                                                                                                                                                      

def dict_from_django_context(context):
    """Flattens a Django :class:`django.template.context.Context` object.
    """
    if isinstance(context, DjangoContext):
        dict_ = {}
        # Newest dicts are up front, so update from oldest to newest.
        for subcontext in reversed(list(context)):
            dict_.update(dict_from_django_context(subcontext))
        return dict_
    else:
        return context</pre>
<p>And you&#8217;re done, now you can just mix your Django and Jinja templates like this:</p>
<pre class="javascript" name="code">{% ifequal foo bar %}
Django style if...
{% endif %}

{% jinja %}
{% if foo == bar %}
Jinja style if...
{% endif %}
{% end_jinja %}
</pre>



Share and Enjoy:


	<a rel="nofollow" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F08%2F24%2Fmixing-django-with-jinja2-without-losing-template-debugging%2F&amp;title=Mixing%20Django%20with%20Jinja2%20without%20losing%20template%20debugging" title="Digg"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://sphinn.com/submit.php?url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F08%2F24%2Fmixing-django-with-jinja2-without-losing-template-debugging%2F&amp;title=Mixing%20Django%20with%20Jinja2%20without%20losing%20template%20debugging" title="Sphinn"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/sphinn.gif" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F08%2F24%2Fmixing-django-with-jinja2-without-losing-template-debugging%2F&amp;title=Mixing%20Django%20with%20Jinja2%20without%20losing%20template%20debugging" title="del.icio.us"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F08%2F24%2Fmixing-django-with-jinja2-without-losing-template-debugging%2F&amp;t=Mixing%20Django%20with%20Jinja2%20without%20losing%20template%20debugging" title="Facebook"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F08%2F24%2Fmixing-django-with-jinja2-without-losing-template-debugging%2F&amp;title=Mixing%20Django%20with%20Jinja2%20without%20losing%20template%20debugging" title="Mixx"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F08%2F24%2Fmixing-django-with-jinja2-without-losing-template-debugging%2F&amp;title=Mixing%20Django%20with%20Jinja2%20without%20losing%20template%20debugging" title="Google"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google" alt="Google" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.mellowmorning.com/2010/08/24/mixing-django-with-jinja2-without-losing-template-debugging/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Django open inviter &#8211; contact importer &#8211; python</title>
		<link>http://www.mellowmorning.com/2010/08/09/django-open-inviter-contact-importer-python/</link>
		<comments>http://www.mellowmorning.com/2010/08/09/django-open-inviter-contact-importer-python/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 22:41:11 +0000</pubDate>
		<dc:creator>tschellenbach</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Fashiolista]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[YouTellMe]]></category>

		<guid isPermaLink="false">http://www.mellowmorning.com/?p=295</guid>
		<description><![CDATA[Django open inviter is a python port of the PHP api client for openinviter.com&#8217;s contact importer to work with Django. I build it for our fashion community, Fashiolista.com, where it is currently in production usage and fully functional. If you are a member of Fashiolista (which I highly doubt given the different audiences) you can [...]]]></description>
			<content:encoded><![CDATA[<p><a target="_blank" href="http://github.com/tschellenbach/DjangoOpenInviter">Django open inviter</a> is a python port of the PHP api client for <a href="http://openinviter.com" target="_blank">openinviter.com</a>&#8217;s contact importer to work with Django. I build it for our fashion community, <a target="_blank" href="http://www.fashiolista.com/">Fashiolista.com</a>, where it is currently in production usage and fully functional. If you are a member of Fashiolista (which I highly doubt given the different audiences) you can test it by clicking find friends in your profile. </p>
<p>Usage is extremly straight forward:</p>
<pre name="code" class="python">
from django_open_inviter.open_inviter import OpenInviter
o = OpenInviter()
contacts = o.contacts('example@example.com', 'test')
</pre>
<p>Get the code <a target="_blank" href="http://github.com/tschellenbach/DjangoOpenInviter">here</a>.</p>



Share and Enjoy:


	<a rel="nofollow" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F08%2F09%2Fdjango-open-inviter-contact-importer-python%2F&amp;title=Django%20open%20inviter%20-%20contact%20importer%20-%20python" title="Digg"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://sphinn.com/submit.php?url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F08%2F09%2Fdjango-open-inviter-contact-importer-python%2F&amp;title=Django%20open%20inviter%20-%20contact%20importer%20-%20python" title="Sphinn"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/sphinn.gif" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F08%2F09%2Fdjango-open-inviter-contact-importer-python%2F&amp;title=Django%20open%20inviter%20-%20contact%20importer%20-%20python" title="del.icio.us"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F08%2F09%2Fdjango-open-inviter-contact-importer-python%2F&amp;t=Django%20open%20inviter%20-%20contact%20importer%20-%20python" title="Facebook"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F08%2F09%2Fdjango-open-inviter-contact-importer-python%2F&amp;title=Django%20open%20inviter%20-%20contact%20importer%20-%20python" title="Mixx"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F08%2F09%2Fdjango-open-inviter-contact-importer-python%2F&amp;title=Django%20open%20inviter%20-%20contact%20importer%20-%20python" title="Google"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google" alt="Google" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.mellowmorning.com/2010/08/09/django-open-inviter-contact-importer-python/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Creating your own Digg/Facebook/Tweetmeme button</title>
		<link>http://www.mellowmorning.com/2010/08/03/creating-your-own-diggfacebook-liketweetmeme-button/</link>
		<comments>http://www.mellowmorning.com/2010/08/03/creating-your-own-diggfacebook-liketweetmeme-button/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 17:58:36 +0000</pubDate>
		<dc:creator>tschellenbach</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Fashiolista]]></category>
		<category><![CDATA[Google app engine]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[YouTellMe]]></category>
		<category><![CDATA[Social bookmarking]]></category>

		<guid isPermaLink="false">http://www.mellowmorning.com/?p=174</guid>
		<description><![CDATA[This quick walkthrough is going to bring you up to speed on how to create your own social bookmarking button. The three prime examples are the famous Digg button, Facebook&#8217;s like functionality and the tweetmeme button. For an implementation look slightly above this paragraph or check out mashable&#8217;s version on the left of their post.
Our [...]]]></description>
			<content:encoded><![CDATA[<p>This quick walkthrough is going to bring you up to speed on how to create your own social bookmarking button. The three prime examples are the famous <a title="digg button" href="http://about.digg.com/button" target="_blank">Digg button</a>, <a target="_blank" href="http://developers.facebook.com/docs/reference/plugins/like">Facebook&#8217;s like</a> functionality and the <a title="tweetmeme button" href="http://tweetmeme.com/about/retweet_button" target="_blank">tweetmeme button</a>. For an implementation look slightly above this paragraph or check out <a title="mashable social bookmarking implementation" href="http://mashable.com/2010/07/24/facebook-like-script/" target="_blank">mashable&#8217;s version</a> on the left of their post.</p>
<p>Our button will be focusing on <a title="fashiolista fashion social bookmarking" href="http://www.fashiolista.com/" target="_blank">Fashiolista.com</a>. Fashiolista is a social bookmarking site for fashion, which has seen <a href="http://thenextweb.com/socialmedia/2010/06/29/fashiolista-celebrates-1-million-love-button-clicks-after-launching-at-the-next-web-conference/" target="_blank">rapid growth after launching at the next web</a>. This tutorial explains the javascript (client side) aspects of the button. Feedback and improvements on the code would be greatly appreciated. You can find the full 450 lines of js on <a href="http://github.com/tschellenbach/Fashiolista-Button/blob/master/buttons.js" target="_blank">github</a>.</p>
<p>This is what the end result looks like:</p>
<p><script type="text/javascript">
  (function() {
   var s = document.createElement('SCRIPT');
   var c = document.getElementsByTagName('script')[0];
   s.type = 'text/javascript';
   s.async = true;
   s.src = 'http://button.www.fashiolista.com/button/script/';
   c.parentNode.insertBefore(s, c);
  })();
</script></p>
<table width="100%">
<tbody>
<tr align="center">
<th>Compact</th>
<th>Medium</th>
<th>Large</th>
</tr>
<tr align="center">
<td width="100px"><a class="fashiolista_button fashiolista_compact" href="http://www.fashiolista.com/add_item_oe/?url=http%3A%2F%2Fwww.tillys.com%2Ftillys%2Fvariants.aspx%3Fprod%3D159872100%26ctlg%3D020_Girls%26cid%3D1090%26source%3D1%26size%3D"><br />
Love it!<br />
</a></td>
<td width="160px"><a class="fashiolista_button fashiolista_medium" href="http://www.fashiolista.com/add_item_oe/?url=http%3A%2F%2Fwww.tillys.com%2Ftillys%2Fvariants.aspx%3Fprod%3D159872100%26ctlg%3D020_Girls%26cid%3D1090%26source%3D1%26size%3D"><br />
Love it!<br />
</a></td>
<td width="100px"><a class="fashiolista_button fashiolista_large" href="http://www.fashiolista.com/add_item_oe/?url=http%3A%2F%2Fwww.tillys.com%2Ftillys%2Fvariants.aspx%3Fprod%3D159872100%26ctlg%3D020_Girls%26cid%3D1090%26source%3D1%26size%3D"><br />
Love it!<br />
</a></td>
</tr>
</tbody>
</table>
<p>(If you are working on a shop in the fashion industry have a look at our <a title="Fashiolista button installation instructions" href="http://www.fashiolista.com/content/fashiolista-button/" target="_blank">installation instuctions</a>.)</p>
<h3>Step 1 &#8211; The markup</h3>
<p>Its important to get the client side markup of the button right. Since other sites will be implementing this there is no way you can change it later on. The three major players each have their own way.</p>
<p>Facebook XFBML: Async script with XFBML or Iframe<br />
Digg button: Async script with A elements<br />
Tweetmeme: Normal script</p>
<pre class="javascript" name="code">&lt;script type="text/javascript"&gt;
  //async script, fashiolista.com version
  (function() {
   var s = document.createElement('SCRIPT');
   var c = document.getElementsByTagName('script')[0];
   s.type = 'text/javascript';
   s.async = true;
   s.src = 'http://button.www.fashiolista.com/button/script/';
   c.parentNode.insertBefore(s, c);
  })();
&lt;/script&gt;
&lt;a class="fashiolista_button fashiolista_compact"
href="http://www.fashiolista.com/item_add_oe/"&gt;Love it!&lt;/a&gt;</pre>
<p>For Fashiolista we have chosen an async script approach with A elements. Normally loading a script element is a blocking operation for the browser. Loading the script async ensures faster page load times and a better experience if your site would ever go down. (Note that not all browsers support this option so it is still <a target="_blank" href="http://developer.yahoo.com/performance/rules.html#js_bottom">recommended to include the script tag at the bottom of the page</a>). The function wrapped around the code ensures we don&#8217;t pollute the global scope. Furthermore the insertBefore in combination with a script tag technique is <a href="http://code.google.com/apis/analytics/docs/tracking/asyncTracking.html#Snippet" target="_blank">used by GA</a> so should work in any scenario.</p>
<h3>Step 2 &#8211; Creating the buttons, Iframe vs Script</h3>
<p>The next step is to convert our A elements into actual buttons. We can choose to replace these A elements by our button&#8217;s html (digg, delicious approach) or load an iframe in their place (facebook, tweetmeme). The difference between these two approaches is actually pretty large. For Fashiolista you can see both an <a href="http://static1.fashiolista.com/other/button_test_iframe.html" target="_blank">iframe</a> and <a href="http://static1.fashiolista.com/other/button_test.html" target="_blank">script</a> approach. These are the most important differences I encountered.</p>
<p><strong>Iframe vs Script</strong></p>
<ul>
<li><strong>+ Popup communication possible</strong><br />
The script approach cannot communicate with popups it creates due to the <a href="https://developer.mozilla.org/en/Same_origin_policy_for_JavaScript" target="_blank">same origin restrictions</a>. The iframe however can be of the same domain as the popup and freely communicate. This gives a better user experience when for instance logging in.</li>
<li><strong>+ Easier to develop</strong><br />
The iframe approach is easier to develop and requires less code.</li>
<li><strong>+ Parallel download in IE</strong><br />
IE doesn&#8217;t download the count scripts in parallel, but it does do so for the IFRAMEs. Making this approach somewhat faster.</li>
<li><strong>Independent CSS</strong><br />
External sites don&#8217;t interfere with your button&#8217;s css if you use an iframe technique. The disadvantage is that it makes things likes hovers impossible to integrate with the other site. (For example Fashiolista&#8217;s compact button).</li>
<li><strong>Independent</strong><br />
The iframe approach makes it very hard for other sites to game the users like/love action. With a script approach a foreign site can simply call your javascript to fake someone loving the product. This freedom can be abused but also allows for mashups.</li>
<li><strong>- Slower dom load</strong><br />
Creating iframes takes <a href="http://www.stevesouders.com/blog/2009/06/03/using-iframes-sparingly/" target="_blank">a lot more time</a> for the browser.</li>
<li><strong>- Slower perceived load</strong><br />
The script approach allows you to format the buttons before the data is loaded. Vastly increasing the perceived load speed.</li>
<li><strong>- No shared functionality</strong><br />
Buttons can&#8217;t share functionality. So when someone logs in for one button its is not possible to update the others.</li>
</ul>
<p>The best choice differs for each project. For Fashiolista the more open script approach is currently the default.</p>
<h3>Step 3 &#8211; Cross site scripting using JSONP</h3>
<p>Essential to the bookmarking button is requesting the count for the given url. Cross site policies prevent us from using Ajax so we will do so by creating a script element.</p>
<pre class="javascript" name="code">_makeRequest: function (url) {
	//Simple create script element functionality
        var s = document.createElement('script');
        var b = document.body;

        s.setAttribute('type', 'text/javascript');
        s.setAttribute('async', 'true');
        s.setAttribute('src', url);

        b.appendChild(s);
}</pre>
<p>The trouble with the script element is that you lack the nice APIs Ajax offers you. We work around this by using an url with a callback paramater, for example <a href="http://button.www.fashiolista.com/button/love_count/?ajax=1&amp;url=http%3A%2F%2Fwww.tillys.com%2Ftillys%2Fvariants.aspx%3Fprod%3D159872100%26ctlg%3D020_Girls%26cid%3D1090%26source%3D1%26size%3D&amp;callback=button_loaded_3" target="_blank">callback=button_loaded_3</a><br />
The server side code then responds with something like this, executing the callback when the script is loaded.</p>
<pre class="javascript" name="code">button_loaded_3({"item_id": 26545, "url": "/item/26545/", "loves": 853})</pre>
<p>This technique is often referred to as <a href="http://en.wikipedia.org/wiki/JSON#JSONP" target="_blank">JSONP</a>. We bind the response function to the global button_loaded_3 using the following code:</p>
<pre class="javascript" name="code">loadButtonInformation: function (buttonId) {
		//make a request to the script with the given callback
		var buttonInstance = this.buttonDict[buttonId];
		var buttonUrl = buttonInstance.lookupUrl;
		var path = '&amp;url=' + encodeURIComponent(buttonUrl);
		var callbackFunctionName = 'button_loaded_' + buttonId;
		var scope = this;
		var callbackFunction = function(data) {
			//bind the scope and button id
			scope.buttonLoaded.call(scope, buttonId, data);
		};
		window[callbackFunctionName] = callbackFunction;
		this.makeRequest(this.countApi + path, callbackFunctionName, true);
}</pre>
<h3>Step 4 &#8211; Object oriented design</h3>
<p>Since we are loading our code into someone else&#8217;s website we should be careful not to use similar variable names. We therefore hide as much code as possible in classes.</p>
<pre class="javascript" name="code">var fashiolistaClass = function(){ this.initialize.apply(this, arguments); };
fashiolistaClass.prototype = {
	//
	//Base class implementing the fashiolista button
	//
	initialize: function () {
		//load the buttons
		this.initializeCss();
		var fashiolistaButtons = this.findButtons();
		this.initializeButtons(fashiolistaButtons);
	}
}</pre>
<p>Note that we are not simulating inheritance for these classes. Using them as simple namespaces is more than sufficient in this case.<br />
The code is organized into 3 classes:</p>
<ul>
<li>fashiolistaClass</li>
<li>fashiolistaUtilsClass</li>
<li>fashiolistaButtonClass</li>
</ul>
<p>The first one acts as a manager (finding the buttons, instantiating fashiolistaButtonClasses and retrieving counts). Fashiolista button contains the logic for individual buttons and fashiolista utils contains some string parsing and dom load functionality.</p>
<h3>Step 5 &#8211; Caching requests in the google app engine</h3>
<p><img style="float: left; padding: 5px;" title="appengine" src="http://img.brothersoft.com/icon/softimage/g/google_app_engine_sdk-314909-1260390748.jpeg" alt="appengine" />To prevent our servers from getting flooded we are routing all traffic through google servers using the google app engine. button.www.fashiolista.com is connected to a google app engine account which forwards and caches requests to fashiolista.com. This setup enables your button to withstand great amounts of traffic without killing your servers. Furthermore it immediately also acts as a cdn for our web requests, speeding up load times for our international visitors. Setting up caching in the google app engine would require another blog post though. Let us know in the comments if you would like to know more about it.</p>
<h3>Conclusion</h3>
<p>The full client side code can be found <a href="http://github.com/tschellenbach/Fashiolista-Button/blob/master/buttons.js" target="_blank">here</a>. This blog post covered the most essential parts. Code review and questions are more than welcome. Be sure to let us know in the comments. Furthermore if you are running a webshop in the fashion industry consider <a href="http://www.fashiolista.com/content/fashiolista-button/" target="_blank">implementing the button</a>.</p>
<h3>More information</h3>
<ul>
<li><a href="http://www.oexchange.org/" target="_blank">Server side standards &#8211; OExchange</a></li>
<li><a href="http://www.fashiolista.com/content/fashiolista-button/" target="_blank">Installing the fashiolista button (for shops)</a></li>
<li>Subscribe to this blog&#8217;s <a href="http://feeds.feedburner.com/MellowMorning" target="_blank">rss feed</a></li>
</ul>
<h3>Improvements/ Request for code review</h3>
<ul>
<li>The domload technique is rather verbose, does anyone know a better method?</li>
<li>The popup communication or lack thereof is not ideal for users, is there a better method?</li>
<li>Script or Iframe what do you prefer?</li>
<li>Suggestions to make it faster?</li>
</ul>



Share and Enjoy:


	<a rel="nofollow" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F08%2F03%2Fcreating-your-own-diggfacebook-liketweetmeme-button%2F&amp;title=Creating%20your%20own%20Digg%2FFacebook%2FTweetmeme%20button" title="Digg"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://sphinn.com/submit.php?url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F08%2F03%2Fcreating-your-own-diggfacebook-liketweetmeme-button%2F&amp;title=Creating%20your%20own%20Digg%2FFacebook%2FTweetmeme%20button" title="Sphinn"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/sphinn.gif" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F08%2F03%2Fcreating-your-own-diggfacebook-liketweetmeme-button%2F&amp;title=Creating%20your%20own%20Digg%2FFacebook%2FTweetmeme%20button" title="del.icio.us"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F08%2F03%2Fcreating-your-own-diggfacebook-liketweetmeme-button%2F&amp;t=Creating%20your%20own%20Digg%2FFacebook%2FTweetmeme%20button" title="Facebook"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F08%2F03%2Fcreating-your-own-diggfacebook-liketweetmeme-button%2F&amp;title=Creating%20your%20own%20Digg%2FFacebook%2FTweetmeme%20button" title="Mixx"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F08%2F03%2Fcreating-your-own-diggfacebook-liketweetmeme-button%2F&amp;title=Creating%20your%20own%20Digg%2FFacebook%2FTweetmeme%20button" title="Google"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google" alt="Google" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.mellowmorning.com/2010/08/03/creating-your-own-diggfacebook-liketweetmeme-button/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Django Facebook &#8211; Open graph API implementation</title>
		<link>http://www.mellowmorning.com/2010/05/17/django-facebook-open-graph-api-implementation/</link>
		<comments>http://www.mellowmorning.com/2010/05/17/django-facebook-open-graph-api-implementation/#comments</comments>
		<pubDate>Mon, 17 May 2010 10:40:54 +0000</pubDate>
		<dc:creator>tschellenbach</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Fashiolista]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[open graph]]></category>
		<category><![CDATA[social]]></category>

		<guid isPermaLink="false">http://www.mellowmorning.com/?p=166</guid>
		<description><![CDATA[Update:
This blog post is outdated, a new and vastly upgraded version of Django Facebook is now available. Read more about it here.
For Fashiolista.com  we needed to integrate with the Facebook Open Graph API. The open graph API is a very exciting facebook project, which you can read about more here and here. The code at fashiolista.com [...]]]></description>
			<content:encoded><![CDATA[<p><b>Update</b>:<br />
This blog post is outdated, a new and vastly upgraded version of Django Facebook is <a href="http://www.mellowmorning.com/2011/06/23/django-facebook-2-0-integrating-facebook/">now available</a>. Read more about it <a href="http://www.mellowmorning.com/2011/06/23/django-facebook-2-0-integrating-facebook/">here</a>.</p>
<p>For <a href="http://www.fashiolista.com/" target="_blank">Fashiolista.com <img style="float:left;" class="alignleft size-full wp-image-159" title="logo_dark_bg" src="http://www.mellowmorning.com/wp-content/uploads/2010/04/logo_dark_bg.png" alt="Fashiolista" width="220" height="100" /></a> we needed to integrate with the Facebook Open Graph API. The open graph API is a very exciting facebook project, which you can read about more <a href="http://mashable.com/2010/04/21/facebook-open-graph/" target="_blank">here </a>and <a href="http://developers.facebook.com/docs/" target="_blank">here</a>. The code at fashiolista.com allows you to register/login via facebook using the Open Graph API (similar to the old Facebook connect, but registration, instead of only logging in). Before you go try it out, fashiolista.com is aimed primarily at females so your girl friends facebook account is probably a better fit.</p>
<p>Im releasing the source code for <a href="http://github.com/tschellenbach/Django-facebook" target="_blank">Django Facebook on github</a>. Its a very early release, but it might help other developers trying to implement a facebook register/loging flow using the new open graph api. See Github for requirements and installation instructions.</p>
<p><b>Update</b>:<br />
<del datetime="2010-05-18T10:56:52+00:00">Birthday formats are currently giving some troubles for some users.</del><br />
Fixed and tests added to prevent future problems. (note Fashiolista.com may still give errors, will be resolved during our next release).</p>



Share and Enjoy:


	<a rel="nofollow" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F05%2F17%2Fdjango-facebook-open-graph-api-implementation%2F&amp;title=Django%20Facebook%20-%20Open%20graph%20API%20implementation" title="Digg"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://sphinn.com/submit.php?url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F05%2F17%2Fdjango-facebook-open-graph-api-implementation%2F&amp;title=Django%20Facebook%20-%20Open%20graph%20API%20implementation" title="Sphinn"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/sphinn.gif" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F05%2F17%2Fdjango-facebook-open-graph-api-implementation%2F&amp;title=Django%20Facebook%20-%20Open%20graph%20API%20implementation" title="del.icio.us"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F05%2F17%2Fdjango-facebook-open-graph-api-implementation%2F&amp;t=Django%20Facebook%20-%20Open%20graph%20API%20implementation" title="Facebook"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F05%2F17%2Fdjango-facebook-open-graph-api-implementation%2F&amp;title=Django%20Facebook%20-%20Open%20graph%20API%20implementation" title="Mixx"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F05%2F17%2Fdjango-facebook-open-graph-api-implementation%2F&amp;title=Django%20Facebook%20-%20Open%20graph%20API%20implementation" title="Google"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google" alt="Google" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.mellowmorning.com/2010/05/17/django-facebook-open-graph-api-implementation/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Fashiolista.com &#8211; Django at The Next Web &#8211; part 1</title>
		<link>http://www.mellowmorning.com/2010/04/22/fashiolista-com-django-at-the-next-web-part-1/</link>
		<comments>http://www.mellowmorning.com/2010/04/22/fashiolista-com-django-at-the-next-web-part-1/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 09:12:50 +0000</pubDate>
		<dc:creator>tschellenbach</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Fashiolista]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[fashion]]></category>
		<category><![CDATA[social shopping]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[the next web]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.mellowmorning.com/?p=153</guid>
		<description><![CDATA[Fashiolista.com is launching in 7 days and has already been getting quite some attention. Techcrunch: 25 startups that will be shaping the next web. For Fashiolista we&#8217;ve been able to utilize a great deal of best practises learned in previous Django based sites. More on this topic later. For now I&#8217;m wondering if there are [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.fashiolista.com/">Fashiolista.com</a> is launching in 7 days and has already been getting quite some attention. Techcrunch: <a href="http://techcrunch.com/2010/04/12/25-startups-that-will-be-shaping-the-next-web/">25 startups that will be shaping the next web</a>. For Fashiolista we&#8217;ve been able to utilize a great deal of best practises learned in previous <a href="http://www.djangoproject.com/">Django </a>based sites. More on this topic later. For now I&#8217;m wondering if there are many other Django fans attending the next web conference.</p>
<p>The <a href="http://thenextweb.com/conference/">conference itself</a> should be very interesting. Definitely looking forward to <a href="http://www.allthingsdistributed.com/2010/04/amazon_cloudfront_the_streamin.html">Werner Vogels</a> and <a href="http://stu.mp/">Joe Stump</a>. The later seems to be running Django for <a href="http://blog.simplegeo.com/post/506890585/hiring-a-designer-and-front-end-engineer">SimpleGeo</a>.</p>
<p><a href="http://www.fashiolista.com"><img class="size-full wp-image-159 alignright" title="logo_dark_bg" src="http://www.mellowmorning.com/wp-content/uploads/2010/04/logo_dark_bg.png" alt="" width="220" height="100" /></a><a href="http://www.mellowmorning.com/wp-content/uploads/2010/04/magic-pony-django-wallpaper-blue11.png"></a><a href="http://www.mellowmorning.com/wp-content/uploads/2010/04/magic-pony-django-wallpaper-blue11-e1271927394617.png"><img class="size-full wp-image-161 alignleft" title="magic-pony-django-wallpaper-blue1[1]" src="http://www.mellowmorning.com/wp-content/uploads/2010/04/magic-pony-django-wallpaper-blue11-e1271927452284.png" alt="" width="160" height="100" /></a></p>



Share and Enjoy:


	<a rel="nofollow" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F04%2F22%2Ffashiolista-com-django-at-the-next-web-part-1%2F&amp;title=Fashiolista.com%20-%20Django%20at%20The%20Next%20Web%20-%20part%201" title="Digg"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://sphinn.com/submit.php?url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F04%2F22%2Ffashiolista-com-django-at-the-next-web-part-1%2F&amp;title=Fashiolista.com%20-%20Django%20at%20The%20Next%20Web%20-%20part%201" title="Sphinn"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/sphinn.gif" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F04%2F22%2Ffashiolista-com-django-at-the-next-web-part-1%2F&amp;title=Fashiolista.com%20-%20Django%20at%20The%20Next%20Web%20-%20part%201" title="del.icio.us"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F04%2F22%2Ffashiolista-com-django-at-the-next-web-part-1%2F&amp;t=Fashiolista.com%20-%20Django%20at%20The%20Next%20Web%20-%20part%201" title="Facebook"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F04%2F22%2Ffashiolista-com-django-at-the-next-web-part-1%2F&amp;title=Fashiolista.com%20-%20Django%20at%20The%20Next%20Web%20-%20part%201" title="Mixx"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F04%2F22%2Ffashiolista-com-django-at-the-next-web-part-1%2F&amp;title=Fashiolista.com%20-%20Django%20at%20The%20Next%20Web%20-%20part%201" title="Google"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google" alt="Google" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.mellowmorning.com/2010/04/22/fashiolista-com-django-at-the-next-web-part-1/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Django based startup &#8211; YouTellMe.nl</title>
		<link>http://www.mellowmorning.com/2010/03/19/django-based-startup-youtellme-nl/</link>
		<comments>http://www.mellowmorning.com/2010/03/19/django-based-startup-youtellme-nl/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 11:17:12 +0000</pubDate>
		<dc:creator>tschellenbach</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[YouTellMe]]></category>

		<guid isPermaLink="false">http://www.mellowmorning.com/?p=146</guid>
		<description><![CDATA[YouTellMe.nl is a completely Django based startup located in Amsterdam. We&#8217;re probably one of the largest Django projects in terms of codebase. Pretty soon the famous nextweb awards are coming up. (remember those guys which broke into Michael Arrington&#8217;s house?). And we need some love from the Django community. Lots of it.
Pretty please nominate youtellme.nl [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.youtellme.nl">YouTellMe.nl</a> is a completely Django based startup located in Amsterdam. We&#8217;re probably one of the largest Django projects in terms of codebase. Pretty soon the famous nextweb awards are coming up. (remember those guys which broke into Michael Arrington&#8217;s house?). And we need some love from the Django community. Lots of it.</p>
<p>Pretty please nominate youtellme.nl for the next web!<br />
<a href="http://dsa.thenextweb.com/?lang=nl">http://dsa.thenextweb.com/?lang=nl</a></p>
<p>Good articles coming soon to offset the bad karma for this shameless plug ;)</p>
<p><strong>Update:</strong></p>
<p>A couple of stats about the current codebase.</p>
<p>According to <a href="http://en.wikipedia.org/wiki/Wc_(Unix)">wc</a> (including whitespace and comments) we currently have:</p>
<ul>
<li>Python: 3,363,188 characters, 87926 lines, 655 files</li>
<li>Javascript: 940,536 characters, 24229 lines, 77 files</li>
</ul>



Share and Enjoy:


	<a rel="nofollow" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F03%2F19%2Fdjango-based-startup-youtellme-nl%2F&amp;title=Django%20based%20startup%20-%20YouTellMe.nl" title="Digg"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://sphinn.com/submit.php?url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F03%2F19%2Fdjango-based-startup-youtellme-nl%2F&amp;title=Django%20based%20startup%20-%20YouTellMe.nl" title="Sphinn"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/sphinn.gif" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F03%2F19%2Fdjango-based-startup-youtellme-nl%2F&amp;title=Django%20based%20startup%20-%20YouTellMe.nl" title="del.icio.us"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F03%2F19%2Fdjango-based-startup-youtellme-nl%2F&amp;t=Django%20based%20startup%20-%20YouTellMe.nl" title="Facebook"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F03%2F19%2Fdjango-based-startup-youtellme-nl%2F&amp;title=Django%20based%20startup%20-%20YouTellMe.nl" title="Mixx"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F03%2F19%2Fdjango-based-startup-youtellme-nl%2F&amp;title=Django%20based%20startup%20-%20YouTellMe.nl" title="Google"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google" alt="Google" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.mellowmorning.com/2010/03/19/django-based-startup-youtellme-nl/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Django query set iterator &#8211; for really large, querysets</title>
		<link>http://www.mellowmorning.com/2010/03/03/django-query-set-iterator-for-really-large-querysets/</link>
		<comments>http://www.mellowmorning.com/2010/03/03/django-query-set-iterator-for-really-large-querysets/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 19:15:36 +0000</pubDate>
		<dc:creator>tschellenbach</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[YouTellMe]]></category>

		<guid isPermaLink="false">http://www.mellowmorning.com/?p=135</guid>
		<description><![CDATA[When you try to iterate over a query set with about 0.5 million items (a few hundred megs of db storage), the memory usage can become somewhat problematic. Adding .iterator to your query set helps somewhat, but still loads the entire query result into memory. Cronjobs at YouTellMe.nl where unfortunately starting to fail. My colleague [...]]]></description>
			<content:encoded><![CDATA[<p>When you try to iterate over a query set with about 0.5 million items (a few hundred megs of db storage), the memory usage can become somewhat problematic. Adding <a href="http://www.djangoproject.com/documentation/0.96/models/lookup/">.iterator</a> to your query set helps somewhat, but still loads the entire query result into memory. Cronjobs at <a href="http://www.youtellme.nl/">YouTellMe.nl</a> where unfortunately starting to fail. My colleague Rick came up with the following fix.</p>
<p>This solution chunks up the querying in bits of 1000 (by default). While this is somewhat heavier on your database (multiple queries) it seriously reduces the memory usage. Curious to hear how other django developers have worked around this problem.</p>
<pre class="python">import gc

def queryset_iterator(queryset, chunksize=1000):
    '''
    Iterate over a Django Queryset ordered by the primary key

    This method loads a maximum of chunksize (default: 1000) rows in it's
    memory at the same time while django normally would load all rows in it's
    memory. Using the iterator() method only causes it to not preload all the
    classes.

    Note that the implementation of the iterator does not support ordered query sets.
    '''
    pk = 0
    last_pk = queryset.order_by('-pk')[0].pk
    queryset = queryset.order_by('pk')
    while pk &lt; last_pk:
        for row in queryset.filter(pk__gt=pk)[:chunksize]:
            pk = row.pk
            yield row
        gc.collect()

#Some Examples:
#old
MyItem.objects.all()

#better
MyItem.objects.all().iterator()

#even better
queryset_iterator(MyItem.objects.all())</pre>
<p><a href="http://www.djangosnippets.org/snippets/1949/">Django snippet here.</a></p>



Share and Enjoy:


	<a rel="nofollow" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F03%2F03%2Fdjango-query-set-iterator-for-really-large-querysets%2F&amp;title=Django%20query%20set%20iterator%20-%20for%20really%20large%2C%20querysets" title="Digg"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://sphinn.com/submit.php?url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F03%2F03%2Fdjango-query-set-iterator-for-really-large-querysets%2F&amp;title=Django%20query%20set%20iterator%20-%20for%20really%20large%2C%20querysets" title="Sphinn"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/sphinn.gif" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F03%2F03%2Fdjango-query-set-iterator-for-really-large-querysets%2F&amp;title=Django%20query%20set%20iterator%20-%20for%20really%20large%2C%20querysets" title="del.icio.us"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F03%2F03%2Fdjango-query-set-iterator-for-really-large-querysets%2F&amp;t=Django%20query%20set%20iterator%20-%20for%20really%20large%2C%20querysets" title="Facebook"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F03%2F03%2Fdjango-query-set-iterator-for-really-large-querysets%2F&amp;title=Django%20query%20set%20iterator%20-%20for%20really%20large%2C%20querysets" title="Mixx"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.mellowmorning.com%2F2010%2F03%2F03%2Fdjango-query-set-iterator-for-really-large-querysets%2F&amp;title=Django%20query%20set%20iterator%20-%20for%20really%20large%2C%20querysets" title="Google"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google" alt="Google" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.mellowmorning.com/2010/03/03/django-query-set-iterator-for-really-large-querysets/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>YTM launch!!</title>
		<link>http://www.mellowmorning.com/2009/12/11/ytm-launch/</link>
		<comments>http://www.mellowmorning.com/2009/12/11/ytm-launch/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 16:49:51 +0000</pubDate>
		<dc:creator>tschellenbach</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Business]]></category>
		<category><![CDATA[Css]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Dutch]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[YouTellMe]]></category>

		<guid isPermaLink="false">http://www.mellowmorning.com/?p=126</guid>
		<description><![CDATA[No more beta for YouTellMe.nl
The website which is taking over the Dutch product comparison market is officially going out of beta @ 8 o clock.
Party in Amsterdam, Keizersgracht 182 :) Festivities starting right now!

Things are going well, looking very forward to international launch.
We&#8217;ve changed a lot since the first reviews!

Beter pictures coming after the event [...]]]></description>
			<content:encoded><![CDATA[<p>No more beta for <a href="http://www.youtellme.nl/">YouTellMe.nl</a><br />
The website which is taking over the Dutch product comparison market is officially going out of beta @ 8 o clock.<br />
Party in Amsterdam, Keizersgracht 182 :) Festivities starting right now!</p>
<p><a href="http://www.mellowmorning.com/wp-content/uploads/2009/12/13342_350348980430_784785430_9966158_5558110_n.jpg"><img class="alignnone size-full wp-image-127" title="13342_350348980430_784785430_9966158_5558110_n" src="http://www.mellowmorning.com/wp-content/uploads/2009/12/13342_350348980430_784785430_9966158_5558110_n.jpg" alt="13342_350348980430_784785430_9966158_5558110_n" width="604" height="453" /></a></p>
<p>Things are going well, looking very forward to international launch.<br />
We&#8217;ve changed a lot since the <a href="http://www.nicolasleroy.fr/wp/2008/09/innovative-product-selection-on-youtellme/">first </a>reviews!</p>
<p><a href="http://www.mellowmorning.com/wp-content/uploads/2009/12/13342_350352790430_784785430_9966172_7726367_n1.jpg"><img class="alignnone size-full wp-image-129" title="13342_350352790430_784785430_9966172_7726367_n" src="http://www.mellowmorning.com/wp-content/uploads/2009/12/13342_350352790430_784785430_9966172_7726367_n1.jpg" alt="13342_350352790430_784785430_9966172_7726367_n" width="453" height="604" /></a></p>
<p>Beter pictures coming after the event :P</p>
<p>PS. Thanks to Python and Django, for enabling us to beat the competition :)</p>
<p>PSS.<a href="http://www.singel146.nl/2009/10/singel-office-warming-de-balans/" target="_blank"> Next2News, eduhub, come and join :)</a></p>



Share and Enjoy:


	<a rel="nofollow" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.mellowmorning.com%2F2009%2F12%2F11%2Fytm-launch%2F&amp;title=YTM%20launch%21%21" title="Digg"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://sphinn.com/submit.php?url=http%3A%2F%2Fwww.mellowmorning.com%2F2009%2F12%2F11%2Fytm-launch%2F&amp;title=YTM%20launch%21%21" title="Sphinn"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/sphinn.gif" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.mellowmorning.com%2F2009%2F12%2F11%2Fytm-launch%2F&amp;title=YTM%20launch%21%21" title="del.icio.us"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.mellowmorning.com%2F2009%2F12%2F11%2Fytm-launch%2F&amp;t=YTM%20launch%21%21" title="Facebook"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.mellowmorning.com%2F2009%2F12%2F11%2Fytm-launch%2F&amp;title=YTM%20launch%21%21" title="Mixx"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.mellowmorning.com%2F2009%2F12%2F11%2Fytm-launch%2F&amp;title=YTM%20launch%21%21" title="Google"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google" alt="Google" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.mellowmorning.com/2009/12/11/ytm-launch/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Django template tags &#8211; Google chart &#8211; python 2.4 port</title>
		<link>http://www.mellowmorning.com/2009/01/02/django-template-tags-google-chart-python-24-port/</link>
		<comments>http://www.mellowmorning.com/2009/01/02/django-template-tags-google-chart-python-24-port/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 22:53:28 +0000</pubDate>
		<dc:creator>tschellenbach</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.mellowmorning.com/?p=75</guid>
		<description><![CDATA[I just tried the django template tags for the google charting api by Jacob. Unfortunately they were python 2.5 only and I happen to still be stuck to 2.4. The changes to move it to 2.4 were minimal though. Still to save some of you googlers out there the hassle:
charts
I was just browsing the code [...]]]></description>
			<content:encoded><![CDATA[<p>I just tried the django template tags for the <a href="http://jeffcroft.com/links/2008/feb/19/google-charts-template-tags-for-django/" target="_blank">google charting api by Jacob</a>. Unfortunately they were python 2.5 only and I happen to still be stuck to 2.4. The changes to move it to 2.4 were minimal though. Still to save some of you googlers out there the hassle:</p>
<p><a href="http://www.mellowmorning.com/wp-content/uploads/2009/01/charts.py">charts</a></p>
<p>I was just browsing the code a bit. There is something peculiar there:</p>
<p>args, varargs, varkw, defaults = inspect.getargspec(func)</p>
<p>I don&#8217;t get the point of using the inspect functionality. Anyone care to explain?</p>



Share and Enjoy:


	<a rel="nofollow" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.mellowmorning.com%2F2009%2F01%2F02%2Fdjango-template-tags-google-chart-python-24-port%2F&amp;title=Django%20template%20tags%20-%20Google%20chart%20-%20python%202.4%20port" title="Digg"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://sphinn.com/submit.php?url=http%3A%2F%2Fwww.mellowmorning.com%2F2009%2F01%2F02%2Fdjango-template-tags-google-chart-python-24-port%2F&amp;title=Django%20template%20tags%20-%20Google%20chart%20-%20python%202.4%20port" title="Sphinn"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/sphinn.gif" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.mellowmorning.com%2F2009%2F01%2F02%2Fdjango-template-tags-google-chart-python-24-port%2F&amp;title=Django%20template%20tags%20-%20Google%20chart%20-%20python%202.4%20port" title="del.icio.us"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.mellowmorning.com%2F2009%2F01%2F02%2Fdjango-template-tags-google-chart-python-24-port%2F&amp;t=Django%20template%20tags%20-%20Google%20chart%20-%20python%202.4%20port" title="Facebook"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.mellowmorning.com%2F2009%2F01%2F02%2Fdjango-template-tags-google-chart-python-24-port%2F&amp;title=Django%20template%20tags%20-%20Google%20chart%20-%20python%202.4%20port" title="Mixx"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.mellowmorning.com%2F2009%2F01%2F02%2Fdjango-template-tags-google-chart-python-24-port%2F&amp;title=Django%20template%20tags%20-%20Google%20chart%20-%20python%202.4%20port" title="Google"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google" alt="Google" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.mellowmorning.com/2009/01/02/django-template-tags-google-chart-python-24-port/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

