<?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; django auth decorator</title>
	<atom:link href="http://www.ninjacipher.com/tag/django-auth-decorator/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>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>
	</channel>
</rss>
