|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- <!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>doc — Document (ORM) — Documentation</title>
- <link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" />
- <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
- <script type="text/javascript">
- var DOCUMENTATION_OPTIONS = {
- URL_ROOT: '',
- VERSION: '',
- 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="Documentation" href="index.html" />
- <link rel="up" title="3. Server Side API" href="server_side_api.html" />
- <link rel="next" title="utils — Utilities Module" href="utils_server.html" />
- <link rel="prev" title="Database API Functions" href="database_api.html" />
- </head>
- <body>
- <div style="background-color: #FFF; text-align: left; padding: 8px 0px"><img src="_static/banner300910.gif"></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="modindex.html" title="Global Module Index"
- accesskey="M">modules</a> |</li>
- <li class="right" >
- <a href="utils_server.html" title="utils — Utilities Module"
- accesskey="N">next</a> |</li>
- <li class="right" >
- <a href="database_api.html" title="Database API Functions"
- accesskey="P">previous</a> |</li>
- <li><a href="index.html">Documentation</a> »</li>
- <li><a href="server_side_api.html" accesskey="U">3. Server Side API</a> »</li>
- </ul>
- </div>
- <div class="sphinxsidebar">
- <div class="sphinxsidebarwrapper">
- <h3><a href="index.html">Table Of Contents</a></h3>
- <ul>
- <li><a class="reference external" href=""><tt class="docutils literal"><span class="pre">doc</span></tt> — Document (ORM)</a><ul>
- <li><a class="reference external" href="#document-object">Document object</a></li>
- <li><a class="reference external" href="#standard-methods-for-api">Standard methods for API</a></li>
- <li><a class="reference external" href="#naming">Naming</a></li>
- <li><a class="reference external" href="#inheritance">Inheritance</a></li>
- <li><a class="reference external" href="#example">Example</a></li>
- </ul>
- </li>
- </ul>
-
- <h4>Previous topic</h4>
- <p class="topless"><a href="database_api.html"
- title="previous chapter">Database API Functions</a></p>
- <h4>Next topic</h4>
- <p class="topless"><a href="utils_server.html"
- title="next chapter"><tt class="docutils literal"><span class="pre">utils</span></tt> — Utilities Module</a></p>
- <h3>This Page</h3>
- <ul class="this-page-menu">
- <li><a href="_sources/doc.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="document">
- <div class="documentwrapper">
- <div class="bodywrapper">
- <div class="body">
-
- <div class="section" id="module-doc">
- <h1><tt class="xref docutils literal"><span class="pre">doc</span></tt> — Document (ORM)<a class="headerlink" href="#module-doc" title="Permalink to this headline">¶</a></h1>
- <dl class="function">
- <dt>
- <tt class="descname">get(dt, dn=''):</tt></dt>
- <dd>Returns a doclist containing the main record and all child records</dd></dl>
-
- <div class="section" id="document-object">
- <h2>Document object<a class="headerlink" href="#document-object" title="Permalink to this headline">¶</a></h2>
- <dl class="class">
- <dt id="doc.Document">
- <em class="property">class </em><tt class="descclassname">doc.</tt><tt class="descname">Document</tt><big>(</big><em>doctype = ''</em>, <em>name = ''</em>, <em>fielddata = {}</em><big>)</big><a class="headerlink" href="#doc.Document" title="Permalink to this definition">¶</a></dt>
- <dd><p>The <cite>Document</cite> class represents the basic Object-Relational Mapper (ORM). The object type is defined by
- <cite>DocType</cite> and the object ID is represented by <cite>name</cite>:</p>
- <div class="highlight-python"><pre>Please note the anamoly in the Web Notes Framework that `ID` is always called as `name`</pre>
- </div>
- <p>If both <cite>doctype</cite> and <cite>name</cite> are specified in the constructor, then the object is loaded from the database.
- If only <cite>doctype</cite> is given, then the object is not loaded
- If <cite>fielddata</cite> is specfied, then the object is created from the given dictionary.</p>
- <blockquote>
- <p><strong>Note 1:</strong></p>
- <blockquote>
- <p>The getter and setter of the object are overloaded to map to the fields of the object that
- are loaded when it is instantiated.</p>
- <p>For example: doc.name will be the <cite>name</cite> field and doc.owner will be the <cite>owner</cite> field</p>
- </blockquote>
- <p><strong>Note 2 - Standard Fields:</strong></p>
- <blockquote>
- <ul class="simple">
- <li><cite>name</cite>: ID / primary key</li>
- <li><cite>owner</cite>: creator of the record</li>
- <li><cite>creation</cite>: datetime of creation</li>
- <li><cite>modified</cite>: datetime of last modification</li>
- <li><cite>modified_by</cite> : last updating user</li>
- <li><cite>docstatus</cite> : Status 0 - Saved, 1 - Submitted, 2- Cancelled</li>
- <li><cite>parent</cite> : if child (table) record, this represents the parent record</li>
- <li><cite>parenttype</cite> : type of parent record (if any)</li>
- <li><cite>parentfield</cite> : table fieldname of parent record (if any)</li>
- <li><cite>idx</cite> : Index (sequence) of the child record</li>
- </ul>
- </blockquote>
- </blockquote>
- <dl class="attribute">
- <dt id="doc.Document.fields">
- <tt class="descname">fields</tt><a class="headerlink" href="#doc.Document.fields" title="Permalink to this definition">¶</a></dt>
- <dd>Dictionary containing the properties of the record. This dictionary is mapped to the getter and setter</dd></dl>
-
- <dl class="method">
- <dt id="doc.Document.save">
- <tt class="descname">save</tt><big>(</big><em>new=0</em>, <em>check_links=1</em>, <em>ignore_fields=0</em><big>)</big><a class="headerlink" href="#doc.Document.save" title="Permalink to this definition">¶</a></dt>
- <dd><p>Saves the current record in the database. If new = 1, creates a new instance of the record.
- Also clears temperory fields starting with <cite>__</cite></p>
- <ul class="simple">
- <li>if check_links is set, it validates all <cite>Link</cite> fields</li>
- <li>if ignore_fields is sets, it does not throw an exception for any field that does not exist in the
- database table</li>
- </ul>
- </dd></dl>
-
- <dl class="method">
- <dt id="doc.Document.clear_table">
- <tt class="descname">clear_table</tt><big>(</big><em>doclist</em>, <em>tablefield</em>, <em>save=0</em><big>)</big><a class="headerlink" href="#doc.Document.clear_table" title="Permalink to this definition">¶</a></dt>
- <dd>Clears the child records from the given <cite>doclist</cite> for a particular <cite>tablefield</cite></dd></dl>
-
- <dl class="method">
- <dt id="doc.Document.addchild">
- <tt class="descname">addchild</tt><big>(</big><em>self</em>, <em>fieldname</em>, <em>childtype = ''</em>, <em>local=0</em>, <em>doclist=None</em><big>)</big><a class="headerlink" href="#doc.Document.addchild" title="Permalink to this definition">¶</a></dt>
- <dd><p>Returns a child record of the give <cite>childtype</cite>.</p>
- <ul class="simple">
- <li>if local is set, it does not save the record</li>
- <li>if doclist is passed, it append the record to the doclist</li>
- </ul>
- </dd></dl>
-
- </dd></dl>
-
- </div>
- <div class="section" id="standard-methods-for-api">
- <h2>Standard methods for API<a class="headerlink" href="#standard-methods-for-api" title="Permalink to this headline">¶</a></h2>
- <dl class="function">
- <dt>
- <tt class="descname">addchild(parent, fieldname, childtype = '', local=0, doclist=None):</tt></dt>
- <dd><p>Create a child record to the parent doc.</p>
- <p>Example:</p>
- <div class="highlight-python"><div class="highlight"><pre><span class="n">c</span> <span class="o">=</span> <span class="n">Document</span><span class="p">(</span><span class="s">'Contact'</span><span class="p">,</span><span class="s">'ABC'</span><span class="p">)</span>
- <span class="n">d</span> <span class="o">=</span> <span class="n">addchild</span><span class="p">(</span><span class="n">c</span><span class="p">,</span> <span class="s">'contact_updates'</span><span class="p">,</span> <span class="s">'Contact Update'</span><span class="p">,</span> <span class="n">local</span> <span class="o">=</span> <span class="mi">1</span><span class="p">)</span>
- <span class="n">d</span><span class="o">.</span><span class="n">last_updated</span> <span class="o">=</span> <span class="s">'Phone call'</span>
- <span class="n">d</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
- </pre></div>
- </div>
- </dd></dl>
-
- <dl class="function">
- <dt id="doc.removechild">
- <tt class="descclassname">doc.</tt><tt class="descname">removechild</tt><big>(</big><em>d</em>, <em>is_local = 0</em><big>)</big><a class="headerlink" href="#doc.removechild" title="Permalink to this definition">¶</a></dt>
- <dd>Sets the docstatus of the object d to 2 (deleted) and appends an ‘old_parent:’ to the parent name</dd></dl>
-
- </div>
- <div class="section" id="naming">
- <h2>Naming<a class="headerlink" href="#naming" title="Permalink to this headline">¶</a></h2>
- <dl class="function">
- <dt id="doc.make_autoname">
- <tt class="descclassname">doc.</tt><tt class="descname">make_autoname</tt><big>(</big><em>key</em>, <em>doctype=''</em><big>)</big><a class="headerlink" href="#doc.make_autoname" title="Permalink to this definition">¶</a></dt>
- <dd><p>Creates an autoname from the given key:</p>
- <p><strong>Autoname rules:</strong></p>
- <blockquote>
- <ul>
- <li><p class="first">The key is separated by ‘.’</p>
- </li>
- <li><dl class="first docutils">
- <dt>‘####’ represents a series. The string before this part becomes the prefix:</dt>
- <dd><p class="first last">Example: ABC.#### creates a series ABC0001, ABC0002 etc</p>
- </dd>
- </dl>
- </li>
- <li><p class="first">‘MM’ represents the current month</p>
- </li>
- <li><p class="first">‘YY’ and ‘YYYY’ represent the current year</p>
- </li>
- </ul>
- </blockquote>
- <p><em>Example:</em></p>
- <blockquote>
- <ul class="simple">
- <li>DE/./.YY./.MM./.##### will create a series like
- DE/09/01/0001 where 09 is the year, 01 is the month and 0001 is the series</li>
- </ul>
- </blockquote>
- </dd></dl>
-
- </div>
- <div class="section" id="inheritance">
- <h2>Inheritance<a class="headerlink" href="#inheritance" title="Permalink to this headline">¶</a></h2>
- <dl class="class">
- <dt>
- <tt class="descname">BaseDocType:</tt></dt>
- <dd>The framework supports simple inheritance using the BaseDocType class.
- It creates the base object and saves it in the property <cite>super</cite>. The getter then tries to retrive the
- property from the <cite>super</cite> object if it exsits before retrieving it from the current record.</dd></dl>
-
- </div>
- <div class="section" id="example">
- <h2>Example<a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h2>
- <p>Open an existing Contact:</p>
- <div class="highlight-python"><div class="highlight"><pre><span class="n">c</span> <span class="o">=</span> <span class="n">Document</span><span class="p">(</span><span class="s">'Contact'</span><span class="p">,</span> <span class="s">'ABC'</span><span class="p">)</span>
- <span class="n">c</span><span class="o">.</span><span class="n">phone_number</span> <span class="o">=</span> <span class="s">'233-3432'</span>
- <span class="n">c</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
- </pre></div>
- </div>
- <p>Create a new Contact:</p>
- <div class="highlight-python"><div class="highlight"><pre><span class="n">c</span> <span class="o">=</span> <span class="n">Document</span><span class="p">(</span><span class="s">'Contact'</span><span class="p">)</span>
- <span class="n">c</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s">'XYZ'</span>
- <span class="n">c</span><span class="o">.</span><span class="n">phone_number</span> <span class="o">=</span> <span class="s">'342-3423'</span>
- <span class="n">c</span><span class="o">.</span><span class="n">email_id</span> <span class="o">=</span> <span class="s">'xyz@foo.com'</span>
- <span class="n">c</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="n">new</span> <span class="o">=</span> <span class="mi">1</span><span class="p">)</span>
- </pre></div>
- </div>
- </div>
- </div>
-
-
- </div>
- </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="modindex.html" title="Global Module Index"
- >modules</a> |</li>
- <li class="right" >
- <a href="utils_server.html" title="utils — Utilities Module"
- >next</a> |</li>
- <li class="right" >
- <a href="database_api.html" title="Database API Functions"
- >previous</a> |</li>
- <li><a href="index.html">Documentation</a> »</li>
- <li><a href="server_side_api.html" >3. Server Side API</a> »</li>
- </ul>
- </div>
- <div class="footer">
- © Copyright 2010, Rushabh Mehta.
- Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
- </div>
- </body>
- </html>
|