djangosnippets.org: Latest snippets tagged with 'class-decorator'http://djangosnippets.org/tags/class-decorator/2011-07-25T02:25:15.007512-05:00LoginRequired class-based view decorator
2011-07-25T02:25:15.007512-05:00mjumbehttp://djangosnippets.org/snippets/2495/<p>Apply the <code>login_required</code> decorator to all the handlers in a class-based view that delegate to <code>cls.dispatch</code>.</p>
<p>Optional arguments:</p>
<ul>
<li>redirect_field_name = <code>REDIRECT_FIELD_NAME</code></li>
<li>login_url = <code>None</code></li>
</ul>
<p>See the documentation for the <a href="https://docs.djangoproject.com/en/dev/topics/auth/#the-login-required-decorator"><code>login_required</code></a> method for more information about the keyword arguments.</p>
<p>Usage:</p>
<pre><code>@LoginRequired
class MyListView (ListView):
...
</code></pre>
Freely redistributableregister.tag as a class decorator
2010-01-27T19:24:22.605147-06:00gsakkishttp://djangosnippets.org/snippets/1894/<p>Defining a custom template tag consists of three parts: a compiling function, a rendering <code>Node</code> subclass and a tag registration with <code>register.tag()</code>. The latter can be used as a (function) decorator on the compiling function, simplifying things into two parts.</p>
<p>A neat fact is that <code>register.tag()</code> can actually be …</p>
Freely redistributable