/usr/share/doc/python-appconf-doc/html/usage.html is in python-appconf-doc 0.5-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | <!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>Usage — django-appconf 0.5 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '0.5',
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>
<link rel="top" title="django-appconf 0.5 documentation" href="index.html" />
<link rel="next" title="Reference" href="reference.html" />
<link rel="prev" title="django-appconf" href="index.html" />
</head>
<body>
<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="reference.html" title="Reference"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="index.html" title="django-appconf"
accesskey="P">previous</a> |</li>
<li><a href="index.html">django-appconf 0.5 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="usage">
<h1>Usage<a class="headerlink" href="#usage" title="Permalink to this headline">¶</a></h1>
<p>It’s strongly recommended to use the usual <tt class="docutils literal"><span class="pre">from</span> <span class="pre">django.conf</span> <span class="pre">import</span> <span class="pre">settings</span></tt>
in your own code to access the configured settings.</p>
<p>But you can also <strong>OPTIONALLY</strong> use your app’s own settings object directly,
by instantiating it in place:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">myapp.models</span> <span class="kn">import</span> <span class="n">MyAppConf</span>
<span class="n">myapp_settings</span> <span class="o">=</span> <span class="n">MyAppConf</span><span class="p">()</span>
<span class="k">print</span> <span class="n">myapp_settings</span><span class="o">.</span><span class="n">SETTING_1</span>
</pre></div>
</div>
<p>Note that accessing the settings that way means they don’t have a prefix.</p>
<p><tt class="docutils literal"><span class="pre">AppConf</span></tt> instances don’t automatically work as proxies for the global
settings. But you can enable this if you want by setting the <tt class="docutils literal"><span class="pre">proxy</span></tt>
attribute of the inner <tt class="docutils literal"><span class="pre">Meta</span></tt> class to <tt class="docutils literal"><span class="pre">True</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">appconf</span> <span class="kn">import</span> <span class="n">AppConf</span>
<span class="k">class</span> <span class="nc">MyAppConf</span><span class="p">(</span><span class="n">AppConf</span><span class="p">):</span>
<span class="n">SETTING_1</span> <span class="o">=</span> <span class="s">"one"</span>
<span class="n">SETTING_2</span> <span class="o">=</span> <span class="p">(</span>
<span class="s">"two"</span><span class="p">,</span>
<span class="p">)</span>
<span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
<span class="n">proxy</span> <span class="o">=</span> <span class="bp">True</span>
<span class="n">myapp_settings</span> <span class="o">=</span> <span class="n">MyAppConf</span><span class="p">()</span>
<span class="k">if</span> <span class="s">"myapp"</span> <span class="ow">in</span> <span class="n">myapp_settings</span><span class="o">.</span><span class="n">INSTALLED_APPS</span><span class="p">:</span>
<span class="k">print</span> <span class="s">"yay, myapp is installed!"</span>
</pre></div>
</div>
<p>In case you want to override some settings programmatically, you can
simply pass the value when instantiating the <tt class="docutils literal"><span class="pre">AppConf</span></tt> class:</p>
<div class="highlight-python"><div class="highlight"><pre>from myapp.models import MyAppConf
myapp_settings = MyAppConf(SETTING_1='something completely different')
if 'different' in myapp_settings.SETTINGS_1:
print 'yay, I'm different!'
</pre></div>
</div>
<div class="section" id="custom-configuration">
<h2>Custom configuration<a class="headerlink" href="#custom-configuration" title="Permalink to this headline">¶</a></h2>
<p>Each of the settings can be individually configured with callbacks.
For example, in case a value of a setting depends on other settings
or other dependencies. The following example sets one setting to a
different value depending on a global setting:</p>
<div class="highlight-python"><div class="highlight"><pre><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">appconf</span> <span class="kn">import</span> <span class="n">AppConf</span>
<span class="k">class</span> <span class="nc">MyCustomAppConf</span><span class="p">(</span><span class="n">AppConf</span><span class="p">):</span>
<span class="n">ENABLED</span> <span class="o">=</span> <span class="bp">True</span>
<span class="k">def</span> <span class="nf">configure_enabled</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="k">return</span> <span class="n">value</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">settings</span><span class="o">.</span><span class="n">DEBUG</span>
</pre></div>
</div>
<p>The value of <tt class="docutils literal"><span class="pre">MYAPP_ENABLED</span></tt> will vary depending on the
value of the global <tt class="docutils literal"><span class="pre">DEBUG</span></tt> setting.</p>
<p>Each of the app settings can be customized by providing
a method <tt class="docutils literal"><span class="pre">configure_<lower_setting_name></span></tt> that takes the default
value as defined in the class attributes of the <tt class="docutils literal"><span class="pre">AppConf</span></tt> subclass
or the override value from the global settings as the only parameter.
The method <strong>must return</strong> the value to be use for the setting in
question.</p>
<p>After each of the <tt class="docutils literal"><span class="pre">*_configure</span></tt> methods have been called, the <tt class="docutils literal"><span class="pre">AppConf</span></tt>
class will additionally call a main <tt class="docutils literal"><span class="pre">configure</span></tt> method, which can
be used to do any further custom configuration handling, e.g. if multiple
settings depend on each other. For that a <tt class="docutils literal"><span class="pre">configured_data</span></tt> dictionary
is provided in the setting instance:</p>
<div class="highlight-python"><div class="highlight"><pre><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">appconf</span> <span class="kn">import</span> <span class="n">AppConf</span>
<span class="k">class</span> <span class="nc">MyCustomAppConf</span><span class="p">(</span><span class="n">AppConf</span><span class="p">):</span>
<span class="n">ENABLED</span> <span class="o">=</span> <span class="bp">True</span>
<span class="n">MODE</span> <span class="o">=</span> <span class="s">'development'</span>
<span class="k">def</span> <span class="nf">configure_enabled</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="k">return</span> <span class="n">value</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">settings</span><span class="o">.</span><span class="n">DEBUG</span>
<span class="k">def</span> <span class="nf">configure</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">mode</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">configured_data</span><span class="p">[</span><span class="s">'MODE'</span><span class="p">]</span>
<span class="n">enabled</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">configured_data</span><span class="p">[</span><span class="s">'ENABLED'</span><span class="p">]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">enabled</span> <span class="ow">and</span> <span class="n">mode</span> <span class="o">!=</span> <span class="s">'development'</span><span class="p">:</span>
<span class="k">print</span> <span class="s">"WARNING: app not enabled in </span><span class="si">%s</span><span class="s"> mode!"</span> <span class="o">%</span> <span class="n">mode</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Usage</a><ul>
<li><a class="reference internal" href="#custom-configuration">Custom configuration</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="index.html"
title="previous chapter">django-appconf</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="reference.html"
title="next chapter">Reference</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/usage.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" />
<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"
>index</a></li>
<li class="right" >
<a href="reference.html" title="Reference"
>next</a> |</li>
<li class="right" >
<a href="index.html" title="django-appconf"
>previous</a> |</li>
<li><a href="index.html">django-appconf 0.5 documentation</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2011-2012, Jannis Leidel and individual contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
</div>
</body>
</html>
|