Sophie

Sophie

distrib > Fedora > 18 > i386 > by-pkgid > 6f61f4fc58119d17ef9d99939eb417b3 > files > 159

python-django-horizon-doc-2012.2.3-1.fc18.noarch.rpm


<!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.loaders &mdash; 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="up" title="horizon" href="../horizon.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">
            
  <h1>Source code for horizon.loaders</h1><div class="highlight"><pre>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Wrapper for loading templates from &quot;templates&quot; directories in panel modules.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">os</span>

<span class="kn">from</span> <span class="nn">django.conf</span> <span class="kn">import</span> <span class="n">settings</span>
<span class="kn">from</span> <span class="nn">django.template.base</span> <span class="kn">import</span> <span class="n">TemplateDoesNotExist</span>
<span class="kn">from</span> <span class="nn">django.template.loader</span> <span class="kn">import</span> <span class="n">BaseLoader</span>
<span class="kn">from</span> <span class="nn">django.utils._os</span> <span class="kn">import</span> <span class="n">safe_join</span>

<span class="c"># Set up a cache of the panel directories to search.</span>
<span class="n">panel_template_dirs</span> <span class="o">=</span> <span class="p">{}</span>


<div class="viewcode-block" id="TemplateLoader"><a class="viewcode-back" href="../../sourcecode/horizon/horizon.loaders.html#horizon.loaders.TemplateLoader">[docs]</a><span class="k">class</span> <span class="nc">TemplateLoader</span><span class="p">(</span><span class="n">BaseLoader</span><span class="p">):</span>
    <span class="n">is_usable</span> <span class="o">=</span> <span class="bp">True</span>

<div class="viewcode-block" id="TemplateLoader.get_template_sources"><a class="viewcode-back" href="../../sourcecode/horizon/horizon.loaders.html#horizon.loaders.TemplateLoader.get_template_sources">[docs]</a>    <span class="k">def</span> <span class="nf">get_template_sources</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">template_name</span><span class="p">):</span>
        <span class="n">bits</span> <span class="o">=</span> <span class="n">template_name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">sep</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">bits</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
            <span class="n">dash_name</span><span class="p">,</span> <span class="n">panel_name</span><span class="p">,</span> <span class="n">remainder</span> <span class="o">=</span> <span class="n">bits</span>
            <span class="n">key</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">dash_name</span><span class="p">,</span> <span class="n">panel_name</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">panel_template_dirs</span><span class="p">:</span>
                <span class="n">template_dir</span> <span class="o">=</span> <span class="n">panel_template_dirs</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
                <span class="k">try</span><span class="p">:</span>
                    <span class="k">yield</span> <span class="n">safe_join</span><span class="p">(</span><span class="n">template_dir</span><span class="p">,</span> <span class="n">panel_name</span><span class="p">,</span> <span class="n">remainder</span><span class="p">)</span>
                <span class="k">except</span> <span class="ne">UnicodeDecodeError</span><span class="p">:</span>
                    <span class="c"># The template dir name wasn&#39;t valid UTF-8.</span>
                    <span class="k">raise</span>
                <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
                    <span class="c"># The joined path was located outside of template_dir.</span>
                    <span class="k">pass</span>
</div>
<div class="viewcode-block" id="TemplateLoader.load_template_source"><a class="viewcode-back" href="../../sourcecode/horizon/horizon.loaders.html#horizon.loaders.TemplateLoader.load_template_source">[docs]</a>    <span class="k">def</span> <span class="nf">load_template_source</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">template_name</span><span class="p">,</span> <span class="n">template_dirs</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">path</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_template_sources</span><span class="p">(</span><span class="n">template_name</span><span class="p">):</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="nb">file</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
                <span class="k">try</span><span class="p">:</span>
                    <span class="k">return</span> <span class="p">(</span><span class="nb">file</span><span class="o">.</span><span class="n">read</span><span class="p">()</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="n">settings</span><span class="o">.</span><span class="n">FILE_CHARSET</span><span class="p">),</span> <span class="n">path</span><span class="p">)</span>
                <span class="k">finally</span><span class="p">:</span>
                    <span class="nb">file</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
            <span class="k">except</span> <span class="ne">IOError</span><span class="p">:</span>
                <span class="k">pass</span>
        <span class="k">raise</span> <span class="n">TemplateDoesNotExist</span><span class="p">(</span><span class="n">template_name</span><span class="p">)</span>

</div></div>
<span class="n">_loader</span> <span class="o">=</span> <span class="n">TemplateLoader</span><span class="p">()</span>
</pre></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
          <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><a href="../../index.html">Horizon 2012.2.3 documentation</a> &raquo;</li>
          <li><a href="../index.html" >Module code</a> &raquo;</li>
          <li><a href="../horizon.html" accesskey="U">horizon</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; 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>