Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > 559fd8619bc261880f698d14b5b853f0 > files > 293

glom-devel-1.15.1-1.fc14.x86_64.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>Glom Python Documentation &mdash; glom_1.14 v1.14.2 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:     '1.14.2',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="glom_1.14 v1.14.2 documentation" href="" /> 
  </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><a href="">glom_1.14 v1.14.2 documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-glom_1_14">
<h1>Glom Python Documentation<a class="headerlink" href="#module-glom_1_14" title="Permalink to this headline">¶</a></h1>
<p>This API may be used in Glom field calculations or button scripts. Field
calculations have a <a title="glom_1_14.Record" class="reference internal" href="#glom_1_14.Record"><tt class="xref docutils literal"><span class="pre">glom_1_14.Record</span></tt></a> parameter. Button scripts have a
<a title="glom_1_14.Record" class="reference internal" href="#glom_1_14.Record"><tt class="xref docutils literal"><span class="pre">glom_1_14.Record</span></tt></a> parameter and a <a title="glom_1_14.UI" class="reference internal" href="#glom_1_14.UI"><tt class="xref docutils literal"><span class="pre">glom_1_14.UI</span></tt></a> parameter.</p>
<ul class="simple">
</ul>
<dl class="class">
<dt id="glom_1_14.Record">
<em class="property">
class </em><tt class="descclassname">glom_1_14.</tt><tt class="descname">Record</tt><a class="headerlink" href="#glom_1_14.Record" title="Permalink to this definition">¶</a></dt>
<dd><p>This is the  current record of the current table. A <a title="glom_1_14.Record" class="reference internal" href="#glom_1_14.Record"><tt class="xref docutils literal"><span class="pre">Record</span></tt></a> object is passed to field calculations and button scripts, providing access to the values of the fields in that record. The <a title="glom_1_14.Record" class="reference internal" href="#glom_1_14.Record"><tt class="xref docutils literal"><span class="pre">Record</span></tt></a> object passed to field calculations is read-only.</p>
<dl class="docutils">
<dt>Field values</dt>
<dd><p class="first">Use record[&#8216;field_name&#8217;] to get the value of a specified field in the current record. For instance, this concatenates the values of the name_first and name_last fields in the current record.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">record</span><span class="p">[</span><span class="s">&#39;name_first&#39;</span><span class="p">]</span> <span class="o">+</span> <span class="s">&#39; &#39;</span> <span class="o">+</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;name_last&#39;</span><span class="p">]</span>
</pre></div>
</div>
<p>You may also use this syntax to set the value of a field in the current record. This is possible in a button script, but not in a field calculation. For instance, this sets the value of the name_first field in the current record.</p>
<div class="last highlight-python"><div class="highlight"><pre><span class="n">record</span><span class="p">[</span><span class="s">&#39;name_first&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">&#39;Bob&#39;</span>
</pre></div>
</div>
</dd>
<dt>Related Records</dt>
<dd>Use the <a title="glom_1_14.Record.related" class="reference internal" href="#glom_1_14.Record.related"><tt class="xref docutils literal"><span class="pre">related</span></tt></a> attribute to access related records via a relationship.</dd>
<dt>Testing for Empty Values</dt>
<dd><p class="first">How you test for empty values depends on the type of field.</p>
<dl class="last docutils">
<dt>Non-Text Fields</dt>
<dd><p class="first">Non-text fields may be empty, indicating that the user has not entered any value in the field. For instance, Glom does not assume that an empty value in a numeric field should mean 0. You can test whether a field is empty by using Python&#8217;s None. For instance.</p>
<div class="last highlight-python"><div class="highlight"><pre><span class="k">if</span><span class="p">(</span><span class="n">record</span><span class="p">[</span><span class="s">&#39;contact_id&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="bp">None</span><span class="p">):</span>
    <span class="k">return</span> <span class="s">&#39;No Contact&#39;</span>
<span class="k">else</span><span class="p">:</span>
    <span class="k">return</span> <span class="n">record</span><span class="o">.</span><span class="n">related</span><span class="p">[</span><span class="s">&#39;contacts&#39;</span><span class="p">][</span><span class="s">&#39;name_full&#39;</span><span class="p">]</span>
</pre></div>
</div>
</dd>
<dt>Text Fields</dt>
<dd><p class="first">For text fields, you should check for zero-length strings. It is not possible in Glom to distinguish between zero-length strings and the absence of any string, because there is no advantage to doing so. For instance:</p>
<div class="last highlight-python"><div class="highlight"><pre><span class="k">if</span><span class="p">(</span><span class="n">record</span><span class="p">[</span><span class="s">&#39;name_full&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;&#39;</span><span class="p">):</span>
    <span class="k">return</span> <span class="s">&#39;No Name&#39;</span>
<span class="k">else</span><span class="p">:</span>
    <span class="k">return</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;name_full&#39;</span><span class="p">]</span>
</pre></div>
</div>
</dd>
</dl>
</dd>
</dl>
<dl class="attribute">
<dt id="glom_1_14.Record.connection">
<tt class="descname">connection</tt><a class="headerlink" href="#glom_1_14.Record.connection" title="Permalink to this definition">¶</a></dt>
<dd>The current database connection for use with the pygda API. This is a <tt class="xref docutils literal"><span class="pre">Gda.Connection</span></tt> object.</dd></dl>

<dl class="attribute">
<dt id="glom_1_14.Record.related">
<tt class="descname">related</tt><a class="headerlink" href="#glom_1_14.Record.related" title="Permalink to this definition">¶</a></dt>
<dd><a title="glom_1_14.Related" class="reference internal" href="#glom_1_14.Related"><tt class="xref docutils literal"><span class="pre">Related</span></tt></a> records. Use the [&#8216;relationship_name&#8217;] notation with this object.</dd></dl>

<dl class="attribute">
<dt id="glom_1_14.Record.table_name">
<tt class="descname">table_name</tt><a class="headerlink" href="#glom_1_14.Record.table_name" title="Permalink to this definition">¶</a></dt>
<dd>The name of the current table as a string.</dd></dl>

</dd></dl>

<dl class="class">
<dt id="glom_1_14.Related">
<em class="property">
class </em><tt class="descclassname">glom_1_14.</tt><tt class="descname">Related</tt><a class="headerlink" href="#glom_1_14.Related" title="Permalink to this definition">¶</a></dt>
<dd><p>This object provides access to related records via its [] syntax, which takes a relationship name and returns a <a title="glom_1_14.RelatedRecord" class="reference internal" href="#glom_1_14.RelatedRecord"><tt class="xref docutils literal"><span class="pre">RelatedRecord</span></tt></a>. For instance, this provides the related records for the current record, via the <a title="glom_1_14.Record.related" class="reference internal" href="#glom_1_14.Record.related"><tt class="xref docutils literal"><span class="pre">Record.related</span></tt></a> attribute</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">record</span><span class="o">.</span><span class="n">related</span><span class="p">[</span><span class="s">&#39;location&#39;</span><span class="p">]</span>
</pre></div>
</div>
</dd></dl>

<dl class="class">
<dt id="glom_1_14.RelatedRecord">
<em class="property">
class </em><tt class="descclassname">glom_1_14.</tt><tt class="descname">RelatedRecord</tt><a class="headerlink" href="#glom_1_14.RelatedRecord" title="Permalink to this definition">¶</a></dt>
<dd><p>One or more related records, returned by the [] syntax on a <a title="glom_1_14.Related" class="reference internal" href="#glom_1_14.Related"><tt class="xref docutils literal"><span class="pre">Related</span></tt></a> object, such as the <a title="glom_1_14.Record.related" class="reference internal" href="#glom_1_14.Record.related"><tt class="xref docutils literal"><span class="pre">Record.related</span></tt></a> attribute.</p>
<dl class="docutils">
<dt>Single Related Records</dt>
<dd><p class="first">For relationships that specify a single record, you can get the value of a field in that record by using the [] synax, providing a field name. For instance, this is the value of the name field in the table indicated by the location relationship (often called location::name).</p>
<div class="last highlight-python"><div class="highlight"><pre><span class="n">record</span><span class="o">.</span><span class="n">related</span><span class="p">[</span><span class="s">&#39;location&#39;</span><span class="p">][</span><span class="s">&#39;name&#39;</span><span class="p">]</span>
</pre></div>
</div>
</dd>
<dt>Multiple Related Records</dt>
<dd><p class="first">For relationships that specify multiple records, you can use the aggregate functions to get overall values. For instance, this provides the sum of all total_price values from all of the lines of the current invoice record. See the <a title="glom_1_14.RelatedRecord" class="reference internal" href="#glom_1_14.RelatedRecord"><tt class="xref docutils literal"><span class="pre">RelatedRecord</span></tt></a> class for more aggregate functions.</p>
<div class="last highlight-python"><div class="highlight"><pre><span class="n">record</span><span class="o">.</span><span class="n">related</span><span class="p">[</span><span class="s">&#39;invoice_lines&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="s">&#39;total_price&#39;</span><span class="p">)</span>
</pre></div>
</div>
</dd>
</dl>
<dl class="method">
<dt id="glom_1_14.RelatedRecord.count">
<tt class="descname">count</tt><big>(</big><big>)</big><a class="headerlink" href="#glom_1_14.RelatedRecord.count" title="Permalink to this definition">¶</a></dt>
<dd><p>Count all values in the field in the related records.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>field_name</em> (string) &#8211; The name of the field.</td>
</tr>
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">The summarized value.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="glom_1_14.RelatedRecord.max">
<tt class="descname">max</tt><big>(</big><big>)</big><a class="headerlink" href="#glom_1_14.RelatedRecord.max" title="Permalink to this definition">¶</a></dt>
<dd><p>Maximum of all values of the field in the related records.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>field_name</em> (string) &#8211; The name of the field.</td>
</tr>
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">The summarized value.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="glom_1_14.RelatedRecord.min">
<tt class="descname">min</tt><big>(</big><big>)</big><a class="headerlink" href="#glom_1_14.RelatedRecord.min" title="Permalink to this definition">¶</a></dt>
<dd><p>Minimum of all values of the field in the related records.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>field_name</em> (string) &#8211; The name of the field.</td>
</tr>
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">The summarized value.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="glom_1_14.RelatedRecord.sum">
<tt class="descname">sum</tt><big>(</big><big>)</big><a class="headerlink" href="#glom_1_14.RelatedRecord.sum" title="Permalink to this definition">¶</a></dt>
<dd><p>Add all values of the field in the related records.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>field_name</em> (string) &#8211; The name of the field.</td>
</tr>
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">The summarized value.</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="glom_1_14.UI">
<em class="property">
class </em><tt class="descclassname">glom_1_14.</tt><tt class="descname">UI</tt><a class="headerlink" href="#glom_1_14.UI" title="Permalink to this definition">¶</a></dt>
<dd><p>A collection of methods to programatically change the Glom UI, performing some tasks that might otherwise be done by the user via the mouse and keyboard.  A <a title="glom_1_14.UI" class="reference internal" href="#glom_1_14.UI"><tt class="xref docutils literal"><span class="pre">UI</span></tt></a> object is passed to button scripts, allowing them to control the user interface.</p>
<dl class="method">
<dt id="glom_1_14.UI.print_layout">
<tt class="descname">print_layout</tt><big>(</big><big>)</big><a class="headerlink" href="#glom_1_14.UI.print_layout" title="Permalink to this definition">¶</a></dt>
<dd>Print the current layout for the current table.</dd></dl>

<dl class="method">
<dt id="glom_1_14.UI.print_report">
<tt class="descname">print_report</tt><big>(</big><big>)</big><a class="headerlink" href="#glom_1_14.UI.print_report" title="Permalink to this definition">¶</a></dt>
<dd><p>Print the specified report for the current table.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>report_name</em> (string) &#8211; The name of the report to print.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="glom_1_14.UI.show_table_details">
<tt class="descname">show_table_details</tt><big>(</big><big>)</big><a class="headerlink" href="#glom_1_14.UI.show_table_details" title="Permalink to this definition">¶</a></dt>
<dd><p>Navigate to the specified table, showing its details view for the specified record.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><em>table_name</em> (string) &#8211; The name of the table to navigate to.</li>
<li><em>primary_key_value</em> &#8211; The value of the primary key field in the record to navigate to.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="glom_1_14.UI.show_table_list">
<tt class="descname">show_table_list</tt><big>(</big><big>)</big><a class="headerlink" href="#glom_1_14.UI.show_table_list" title="Permalink to this definition">¶</a></dt>
<dd><p>Navigate to the specified table, showing its list view.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>table_name</em> &#8211; The name of the table to navigate to.  :type table_name: string</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="glom_1_14.UI.start_new_record">
<tt class="descname">start_new_record</tt><big>(</big><big>)</big><a class="headerlink" href="#glom_1_14.UI.start_new_record" title="Permalink to this definition">¶</a></dt>
<dd>Start a new empty record for the current table, offering the empty record in the UI.</dd></dl>

</dd></dl>

</div>
<div class="section" id="indices-and-tables">
<h1>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline">¶</a></h1>
<ul class="simple">
<li><a class="reference external" href="genindex.html"><em>Index</em></a></li>
<li><a class="reference external" href="search.html"><em>Search Page</em></a></li>
</ul>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">Glom Python Documentation</a><ul>
</ul>
</li>
<li><a class="reference external" href="#indices-and-tables">Indices and tables</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"
             >index</a></li>
        <li><a href="">glom_1.14 v1.14.2 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2010, Murray Cumming.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.2.
    </div>
  </body>
</html>