<?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>NinjaCipher &#187; python</title>
	<atom:link href="http://www.ninjacipher.com/category/development/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ninjacipher.com</link>
	<description>kungpow programming</description>
	<lastBuildDate>Thu, 25 Mar 2010 14:39:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='www.ninjacipher.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>Using Mako with Tornado Web Server</title>
		<link>http://www.ninjacipher.com/2010/01/01/using-mako-with-tornado-web-server/</link>
		<comments>http://www.ninjacipher.com/2010/01/01/using-mako-with-tornado-web-server/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 19:42:54 +0000</pubDate>
		<dc:creator>mattd</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[real time]]></category>
		<category><![CDATA[tornado]]></category>

		<guid isPermaLink="false">http://www.ninjacipher.com/?p=191</guid>
		<description><![CDATA[So at work we have been focusing on real time web services a lot lately. Due to this I&#8217;ve been getting a chance to play with some awesome new technologies that really lend themselves to the real time web. One of these new technologies is the Tornado Web Server.
&#8220;Tornado is an open source version of [...]]]></description>
			<content:encoded><![CDATA[<p>So <a href="http://wiredset.com" target="wiredset">at work</a> we have been focusing on real time web services a lot lately. Due to this I&#8217;ve been getting a chance to play with some awesome new technologies that really lend themselves to the real time web. One of these new technologies is the <a href="http://www.tornadoweb.org/" target="tornado">Tornado Web Server</a>.</p>
<blockquote><p>&#8220;Tornado is an open source version of the scalable, non-blocking web server and tools that power FriendFeed&#8221;</p></blockquote>
<p>We&#8217;re using <a href="http://www.makotemplates.org/" target="mako">Mako</a> to handle our templates (vs the template module that comes with Tornado). It&#8217;s super fast and feature rich and has good documentation. Bellow is a base class I wrote that illustrates how to render Mako templates from a Tornado RequestHandler class. It takes care of setting your template directory, template cache directory and your output encoding (utf-8). </p>
<p><strong>Note: This example assumes that you have your template settings defined as tornado options but they could be very easily just hard coded in. </strong></p>
<pre name="code" class="python">from tornado.web import RequestHandler
from mako.template import Template
from mako.lookup import TemplateLookup
from tornado.options import options

class BaseRequest(RequestHandler):
    def __init__(self, application, request, transforms=None):
        RequestHandler.__init__(self, application, request, transforms)
        self.lookup = TemplateLookup(directories=[options.template_dir], module_directory=options.mako_modules_dir, output_encoding='utf-8', encoding_errors='replace')

    def render_template(self,template_name, **kwargs):
        new_template = self.lookup.get_template(template_name)
        self.write(new_template.render(**kwargs))</pre>
<p>Basically you would just derive your handlers from BaseRequest vs from RequestHandler and you will then be able to render your Mako templates via the render_template method.</p>
<p>Here is an example:</p>
<pre name="code" class="python">class ExampleHandler(BaseRequest):
    def get(self):
        self.render_template('example.html')</pre>
<p>Shoot me a comment and let me know if you have any questions. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.ninjacipher.com/2010/01/01/using-mako-with-tornado-web-server/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Selling clients on Django</title>
		<link>http://www.ninjacipher.com/2009/05/06/selling-clients-on-django/</link>
		<comments>http://www.ninjacipher.com/2009/05/06/selling-clients-on-django/#comments</comments>
		<pubDate>Thu, 07 May 2009 01:39:23 +0000</pubDate>
		<dc:creator>mattd</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[rant]]></category>

		<guid isPermaLink="false">http://www.ninjacipher.com/?p=143</guid>
		<description><![CDATA[So right up front let me just say that I love Django. This should come as no surprise to anyone who has been to my site. I think its a great framework and I really enjoy working with it. That being said all too often my clients look like a deer in headlights when I [...]]]></description>
			<content:encoded><![CDATA[<p>So right up front let me just say that I love Django. This should come as no surprise to anyone who has been to my site. I think its a great framework and I really enjoy working with it. That being said all too often my clients look like a deer in headlights when I suggest using it for their projects. Unfortunately that usually means that they want to use&#8230; PHP ::dies::</p>
<p>Now not that there aren&#8217;t some decent PHP frameworks out there but lets be honest if I had my druthers the clear winner would ALWAYS be Python/Django. Once in awhile I will get someone who is a little bit more open minded and they will suggest Rails. Which again is fine&#8230; I would rather write Ruby then PHP any day but it still is a far cry from Django IMHO. </p>
<p>So my question is this&#8230; how do you sell a client on the idea of using Django?! I would love to hear your thoughts about it. To preface my client base is normally entertainment industry based (Record labels, TV networks and Movie Studios). They tend to have overly bloated IT departments that take 7 months to handle an app we can crank out in a matter of weeks. The usual roadblocks I hear are &#8220;we don&#8217;t support python&#8221; or &#8220;we have no python resources to maintain the app after your done&#8221;. Basically I think my clients tend to think that I&#8217;m suggesting they build in Django not out of trying to use the best tool for the job but more as a job security language (jsl).   </p>
<p>Anyway as you can prob tell this is a constant source of frustration and any advice would be very much appreciated. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.ninjacipher.com/2009/05/06/selling-clients-on-django/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Top 5 Django IDEs</title>
		<link>http://www.ninjacipher.com/2009/05/01/top-5-django-ides/</link>
		<comments>http://www.ninjacipher.com/2009/05/01/top-5-django-ides/#comments</comments>
		<pubDate>Sat, 02 May 2009 03:22:24 +0000</pubDate>
		<dc:creator>mattd</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[random thoughts]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ide]]></category>

		<guid isPermaLink="false">http://www.ninjacipher.com/?p=108</guid>
		<description><![CDATA[I&#8217;ve seen a lot of people out there looking for a good IDE for doing Django work. Personally I&#8217;m a pydev guy. I have been using Eclipse for so long for everything else it&#8217;s very natural to keep on that path. However there are definitely other alternatives out there. Here is a list of other [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve seen a lot of people out there looking for a good IDE for doing Django work. Personally I&#8217;m a pydev guy. I have been using Eclipse for so long for everything else it&#8217;s very natural to keep on that path. However there are definitely other alternatives out there. Here is a list of other IDEs and editors that have Django support.</p>
<ol>
<li><a href="http://pydev.blogspot.com/2006/09/configuring-pydev-to-work-with-django.html" target="_blank">Eclipse with PyDev</a> (part of <a href="http://www.aptana.com/python" target="_blank">Aptana</a> now)</li>
<li><a href="http://macromates.com/blog/archives/2006/08/21/getting-more-bundles/" target="_blank">TextMate with Django Bundle</a> (technically not an IDE but allot of people love it)</li>
<li><a href="http://code.google.com/p/netbeans-django/" target="_blank">Netbeans with Django Plugin</a></li>
<li><a href="http://www.wingware.com/doc/howtos/django" target="_blank">Wing</a></li>
<li><a href="http://code.google.com/p/django-komodo-kit/" target="_blank">Komodo with Django Komodo Kit</a></li>
</ol>
<p>So I&#8217;m sure some of you people out there will say man up&#8230; use VIM or Emacs&#8230; be a real programmer! To that I say have at it. If that&#8217;s your preference then do what works best for you. By all means, leave me a comment and tell my how wrong I am and/or glow about how good your IDE/editor is. Long story short Django is an awesome framework and whatever you choose to work in I hope you enjoy it as much as I have.</p>
<div id="stb-container" class="stb-container"><div id='caption' class='stb-alert-caption_box' >Reality Check!</div><div id='body' class='stb-alert-body_box' >Of course there are other options out there. And top 5 doesn&#8217;t mean these are the best. But from my research these are the editors most people seem to be using.<br />
</div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.ninjacipher.com/2009/05/01/top-5-django-ides/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Oh BirdyPy</title>
		<link>http://www.ninjacipher.com/2009/04/12/oh-birdypy/</link>
		<comments>http://www.ninjacipher.com/2009/04/12/oh-birdypy/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 01:47:27 +0000</pubDate>
		<dc:creator>mattd</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.ninjacipher.com/?p=80</guid>
		<description><![CDATA[Just started a new open source python wrapper for the twitter rest and search apis. I&#8217;m trying to stay as 1 to 1 as I can with the names and function arguments so its pretty much an exact match to the twitter api docs. Also adding a django test app that includes models for serializing [...]]]></description>
			<content:encoded><![CDATA[<p>Just started a new open source python wrapper for the twitter rest and search apis. I&#8217;m trying to stay as 1 to 1 as I can with the names and function arguments so its pretty much an exact match to the twitter api docs. Also adding a django test app that includes models for serializing all of the return object types to the db. You can check it out <a href="http://code.google.com/p/birdypy/">here</a>. If you have some time and want to help shoot me an email and I will add you to the project. The codes is still a very unfinished work in progress. Definitely not ready for prime time at this point, but hell sharing is caring and who knows&#8230; someone out there may want to help. LOL </p>
]]></content:encoded>
			<wfw:commentRss>http://www.ninjacipher.com/2009/04/12/oh-birdypy/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>django active_login_required decorator</title>
		<link>http://www.ninjacipher.com/2008/11/29/django-active_login_required-decorator/</link>
		<comments>http://www.ninjacipher.com/2008/11/29/django-active_login_required-decorator/#comments</comments>
		<pubDate>Sat, 29 Nov 2008 22:13:29 +0000</pubDate>
		<dc:creator>mattd</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[django auth decorator]]></category>

		<guid isPermaLink="false">http://www.ninjacipher.com/?p=54</guid>
		<description><![CDATA[Here is a little hack I made to the auth.login_required decorator that checks to see if the user account has the is_active flag set as well as being logged in. Nothing earth shattering here but I find it useful. If you look at the original login_required decorator you will see its exactly the same except [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a little hack I made to the auth.login_required decorator that checks to see if the user account has the is_active flag set as well as being logged in. Nothing earth shattering here but I find it useful. If you look at the original login_required decorator you will see its exactly the same except for the extra is_active flag check. </p>
<pre name="code" class="python">
#A decorator that checks to makes sure a user is active and logged in

from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.decorators import user_passes_test
def active_login_required(function=None, redirect_field_name=REDIRECT_FIELD_NAME):
    actual_decorator = user_passes_test(
        lambda u: u.is_authenticated() and u.is_active,
        redirect_field_name=redirect_field_name
    )
    if function:
        return actual_decorator(function)
    return actual_decorator</pre>
<p>You use it in the exact same way you use the normal login_required decorator.</p>
<p><strong>In your view</strong></p>
<pre name="code" class="python">@active_login_required
def my_view(request):
    # ...</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ninjacipher.com/2008/11/29/django-active_login_required-decorator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Django Paginator Example</title>
		<link>http://www.ninjacipher.com/2008/08/04/new-django-paginator-example/</link>
		<comments>http://www.ninjacipher.com/2008/08/04/new-django-paginator-example/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 17:06:28 +0000</pubDate>
		<dc:creator>mattd</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.ninjacipher.com/?p=52</guid>
		<description><![CDATA[edit:
This example has since been added to the official Django Docs for pagination. Big thanks to Scot Hacker for taking the initiative to submit the doc patch and make this happen (IE I&#8217;m far to lazy to submit it on my own). 
So I pulled the latest Django codebase from svn today and I noticed [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: #999999;"><em>edit:</em></span><br />
<span style="color: #808080;"><strong>This example has since been added to the <a title="django docs" href="http://docs.djangoproject.com/en/dev/topics/pagination/#using-paginator-in-a-view" target="_blank">official Django Docs for pagination</a>. Big thanks to <a title="birdhouse.org" href="http://birdhouse.org/blog/" target="_blank">Scot Hacker</a> for taking the initiative to submit the doc patch and make this happen (IE I&#8217;m far to lazy to submit it on my own). </strong></span></p>
<p>So I pulled the latest Django codebase from svn today and I noticed that my old pagination setup no longer works. Not really surprising as a ton of stuff is being updated due to the coming release of 1.0. So I did a bit of digging into the new pagination code to see if I could rework my <a href="http://www.ninjacipher.com/2007/12/27/django-pagination-wrapper/" target="_blank">wrapper class</a> to work with the new release. It turns out that with the updates there really is no good reason to wrap the classes any more. They have done a good job of working out all the kinks in the pagination setup and it does everything I need it to do out of the box.</p>
<p>So here is a quick nutshell example of how I am using the new django.core.paginator classes to replace the old ObjectPaginator wrapper from my <a href="http://www.ninjacipher.com/2007/12/27/django-pagination-wrapper/" target="_blank">previous example</a>.<br />
<strong><br />
in your view:</strong></p>
<pre name="code" class="python">from django.core.paginator import Paginator

#create a new paginator instance by passing it a collection of objects and the per page count
paginator = Paginator(Contact.objects.all().order_by('last_name'), 10)

#get the page number from a get param
#if param is blank then set page to 1
page = int(request.GET.get('page', '1'))

#grab the current page from the paginator...
contacts = paginator.page(page)

#render the template and pass the contacts page into the template
return render_to_response('contacts.html',{'contacts':contacts})</code>

<strong>in your template:</strong>
<code lang="python">{% for contact in contacts.object_list %}
{{ contact.name }}
{% endfor %}</pre>
<p>I'd say that's pretty easy. </p>
<p>Here is a  simple snippet that you can use to create a paging footer.</p>
<pre name="code" class="python">
<div class="pagination">
	<span class="step-links">
	{% if contacts.has_previous %}<a href="?page={{ contacts.previous_page_number }}" class="util-link">previous</a>{% endif %}
	{% if contacts.has_next %}<a href="?page={{ contacts.next_page_number }}" class="util-link">next</a>{% endif %}
	</span>
	<span class="current">
		{{ contacts }}
	</span>
</div>
</pre>
<p>Notice to get the page of pages info all you have to do is output the page object like so... {{ contacts }} . Pretty cool.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ninjacipher.com/2008/08/04/new-django-paginator-example/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
