<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Horizon Decorators — Horizon 2012.2.3 documentation</title> <link rel="stylesheet" href="../_static/nature.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <link rel="stylesheet" href="../_static/tweaks.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '2012.2.3', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/jquery.tweet.js"></script> <link rel="top" title="Horizon 2012.2.3 documentation" href="../index.html" /> <link rel="next" title="Horizon Exceptions" href="exceptions.html" /> <link rel="prev" title="Horizon Context Processors" href="context_processors.html" /> </head> <body> <div id="header"> <h1 id="logo"><a href="http://www.openstack.org/">OpenStack</a></h1> <ul id="navigation"> <li><a href="http://www.openstack.org/" title="Go to the Home page" class="link">Home</a></li> <li><a href="http://www.openstack.org/projects/" title="Go to the OpenStack Projects page">Projects</a></li> <li><a href="http://www.openstack.org/user-stories/" title="Go to the User Stories page" class="link">User Stories</a></li> <li><a href="http://www.openstack.org/community/" title="Go to the Community page" class="link">Community</a></li> <li><a href="http://www.openstack.org/blog/" title="Go to the OpenStack Blog">Blog</a></li> <li><a href="http://wiki.openstack.org/" title="Go to the OpenStack Wiki">Wiki</a></li> <li><a href="http://docs.openstack.org/" title="Go to OpenStack Documentation" class="current">Documentation</a></li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="module-horizon.decorators"> <span id="horizon-decorators"></span><h1>Horizon Decorators<a class="headerlink" href="#module-horizon.decorators" title="Permalink to this headline">¶</a></h1> <p>General-purpose decorators for use with Horizon.</p> <dl class="function"> <dt id="horizon.decorators.require_auth"> <tt class="descclassname">horizon.decorators.</tt><tt class="descname">require_auth</tt><big>(</big><em>view_func</em><big>)</big><a class="reference internal" href="../_modules/horizon/decorators.html#require_auth"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#horizon.decorators.require_auth" title="Permalink to this definition">¶</a></dt> <dd><p>Performs user authentication check.</p> <p>Similar to Django’s <cite>login_required</cite> decorator, except that this throws <a class="reference internal" href="exceptions.html#horizon.exceptions.NotAuthenticated" title="horizon.exceptions.NotAuthenticated"><tt class="xref py py-exc docutils literal"><span class="pre">NotAuthenticated</span></tt></a> exception if the user is not signed-in.</p> </dd></dl> <dl class="function"> <dt id="horizon.decorators.require_perms"> <tt class="descclassname">horizon.decorators.</tt><tt class="descname">require_perms</tt><big>(</big><em>view_func</em>, <em>required</em><big>)</big><a class="reference internal" href="../_modules/horizon/decorators.html#require_perms"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#horizon.decorators.require_perms" title="Permalink to this definition">¶</a></dt> <dd><p>Enforces permission-based access controls.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>required</strong> (<em>list</em>) – A tuple of permission names, all of which the request user must possess in order access the decorated view.</td> </tr> </tbody> </table> <p>Example usage:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">horizon.decorators</span> <span class="kn">import</span> <span class="n">require_perms</span> <span class="nd">@require_perms</span><span class="p">([</span><span class="s">'foo.admin'</span><span class="p">,</span> <span class="s">'foo.member'</span><span class="p">])</span> <span class="k">def</span> <span class="nf">my_view</span><span class="p">(</span><span class="n">request</span><span class="p">):</span> <span class="o">...</span> </pre></div> </div> <p>Raises a <a class="reference internal" href="exceptions.html#horizon.exceptions.NotAuthorized" title="horizon.exceptions.NotAuthorized"><tt class="xref py py-exc docutils literal"><span class="pre">NotAuthorized</span></tt></a> exception if the requirements are not met.</p> </dd></dl> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h4>Previous topic</h4> <p class="topless"><a href="context_processors.html" title="previous chapter">Horizon Context Processors</a></p> <h4>Next topic</h4> <p class="topless"><a href="exceptions.html" title="next chapter">Horizon Exceptions</a></p> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../_sources/ref/decorators.txt" rel="nofollow">Show Source</a></li> </ul> <div id="searchbox" style="display: none"> <h3>Quick search</h3> <form class="search" action="../search.html" method="get"> <input type="text" name="q" size="18" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> Enter search terms or a module, class or function name. </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="exceptions.html" title="Horizon Exceptions" accesskey="N">next</a> |</li> <li class="right" > <a href="context_processors.html" title="Horizon Context Processors" accesskey="P">previous</a> |</li> <li><a href="../index.html">Horizon 2012.2.3 documentation</a> »</li> </ul> </div> <div class="footer"> © Copyright 2012, OpenStack, LLC. Last updated on Feb 08, 2013. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3. </div> </body> </html>