選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

284 行
15 KiB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>doc — Document (ORM) &mdash; Documentation</title>
  7. <link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" />
  8. <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  9. <script type="text/javascript">
  10. var DOCUMENTATION_OPTIONS = {
  11. URL_ROOT: '',
  12. VERSION: '',
  13. COLLAPSE_MODINDEX: false,
  14. FILE_SUFFIX: '.html',
  15. HAS_SOURCE: true
  16. };
  17. </script>
  18. <script type="text/javascript" src="_static/jquery.js"></script>
  19. <script type="text/javascript" src="_static/doctools.js"></script>
  20. <link rel="top" title="Documentation" href="index.html" />
  21. <link rel="up" title="3. Server Side API" href="server_side_api.html" />
  22. <link rel="next" title="utils — Utilities Module" href="utils_server.html" />
  23. <link rel="prev" title="Database API Functions" href="database_api.html" />
  24. </head>
  25. <body>
  26. <div style="background-color: #FFF; text-align: left; padding: 8px 0px"><img src="_static/banner300910.gif"></div>
  27. <div class="related">
  28. <h3>Navigation</h3>
  29. <ul>
  30. <li class="right" style="margin-right: 10px">
  31. <a href="genindex.html" title="General Index"
  32. accesskey="I">index</a></li>
  33. <li class="right" >
  34. <a href="modindex.html" title="Global Module Index"
  35. accesskey="M">modules</a> |</li>
  36. <li class="right" >
  37. <a href="utils_server.html" title="utils — Utilities Module"
  38. accesskey="N">next</a> |</li>
  39. <li class="right" >
  40. <a href="database_api.html" title="Database API Functions"
  41. accesskey="P">previous</a> |</li>
  42. <li><a href="index.html">Documentation</a> &raquo;</li>
  43. <li><a href="server_side_api.html" accesskey="U">3. Server Side API</a> &raquo;</li>
  44. </ul>
  45. </div>
  46. <div class="sphinxsidebar">
  47. <div class="sphinxsidebarwrapper">
  48. <h3><a href="index.html">Table Of Contents</a></h3>
  49. <ul>
  50. <li><a class="reference external" href=""><tt class="docutils literal"><span class="pre">doc</span></tt> &#8212; Document (ORM)</a><ul>
  51. <li><a class="reference external" href="#document-object">Document object</a></li>
  52. <li><a class="reference external" href="#standard-methods-for-api">Standard methods for API</a></li>
  53. <li><a class="reference external" href="#naming">Naming</a></li>
  54. <li><a class="reference external" href="#inheritance">Inheritance</a></li>
  55. <li><a class="reference external" href="#example">Example</a></li>
  56. </ul>
  57. </li>
  58. </ul>
  59. <h4>Previous topic</h4>
  60. <p class="topless"><a href="database_api.html"
  61. title="previous chapter">Database API Functions</a></p>
  62. <h4>Next topic</h4>
  63. <p class="topless"><a href="utils_server.html"
  64. title="next chapter"><tt class="docutils literal"><span class="pre">utils</span></tt> &#8212; Utilities Module</a></p>
  65. <h3>This Page</h3>
  66. <ul class="this-page-menu">
  67. <li><a href="_sources/doc.txt"
  68. rel="nofollow">Show Source</a></li>
  69. </ul>
  70. <div id="searchbox" style="display: none">
  71. <h3>Quick search</h3>
  72. <form class="search" action="search.html" method="get">
  73. <input type="text" name="q" size="18" />
  74. <input type="submit" value="Go" />
  75. <input type="hidden" name="check_keywords" value="yes" />
  76. <input type="hidden" name="area" value="default" />
  77. </form>
  78. <p class="searchtip" style="font-size: 90%">
  79. Enter search terms or a module, class or function name.
  80. </p>
  81. </div>
  82. <script type="text/javascript">$('#searchbox').show(0);</script>
  83. </div>
  84. </div>
  85. <div class="document">
  86. <div class="documentwrapper">
  87. <div class="bodywrapper">
  88. <div class="body">
  89. <div class="section" id="module-doc">
  90. <h1><tt class="xref docutils literal"><span class="pre">doc</span></tt> &#8212; Document (ORM)<a class="headerlink" href="#module-doc" title="Permalink to this headline">¶</a></h1>
  91. <dl class="function">
  92. <dt>
  93. <tt class="descname">get(dt, dn=''):</tt></dt>
  94. <dd>Returns a doclist containing the main record and all child records</dd></dl>
  95. <div class="section" id="document-object">
  96. <h2>Document object<a class="headerlink" href="#document-object" title="Permalink to this headline">¶</a></h2>
  97. <dl class="class">
  98. <dt id="doc.Document">
  99. <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>
  100. <dd><p>The <cite>Document</cite> class represents the basic Object-Relational Mapper (ORM). The object type is defined by
  101. <cite>DocType</cite> and the object ID is represented by <cite>name</cite>:</p>
  102. <div class="highlight-python"><pre>Please note the anamoly in the Web Notes Framework that `ID` is always called as `name`</pre>
  103. </div>
  104. <p>If both <cite>doctype</cite> and <cite>name</cite> are specified in the constructor, then the object is loaded from the database.
  105. If only <cite>doctype</cite> is given, then the object is not loaded
  106. If <cite>fielddata</cite> is specfied, then the object is created from the given dictionary.</p>
  107. <blockquote>
  108. <p><strong>Note 1:</strong></p>
  109. <blockquote>
  110. <p>The getter and setter of the object are overloaded to map to the fields of the object that
  111. are loaded when it is instantiated.</p>
  112. <p>For example: doc.name will be the <cite>name</cite> field and doc.owner will be the <cite>owner</cite> field</p>
  113. </blockquote>
  114. <p><strong>Note 2 - Standard Fields:</strong></p>
  115. <blockquote>
  116. <ul class="simple">
  117. <li><cite>name</cite>: ID / primary key</li>
  118. <li><cite>owner</cite>: creator of the record</li>
  119. <li><cite>creation</cite>: datetime of creation</li>
  120. <li><cite>modified</cite>: datetime of last modification</li>
  121. <li><cite>modified_by</cite> : last updating user</li>
  122. <li><cite>docstatus</cite> : Status 0 - Saved, 1 - Submitted, 2- Cancelled</li>
  123. <li><cite>parent</cite> : if child (table) record, this represents the parent record</li>
  124. <li><cite>parenttype</cite> : type of parent record (if any)</li>
  125. <li><cite>parentfield</cite> : table fieldname of parent record (if any)</li>
  126. <li><cite>idx</cite> : Index (sequence) of the child record</li>
  127. </ul>
  128. </blockquote>
  129. </blockquote>
  130. <dl class="attribute">
  131. <dt id="doc.Document.fields">
  132. <tt class="descname">fields</tt><a class="headerlink" href="#doc.Document.fields" title="Permalink to this definition">¶</a></dt>
  133. <dd>Dictionary containing the properties of the record. This dictionary is mapped to the getter and setter</dd></dl>
  134. <dl class="method">
  135. <dt id="doc.Document.save">
  136. <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>
  137. <dd><p>Saves the current record in the database. If new = 1, creates a new instance of the record.
  138. Also clears temperory fields starting with <cite>__</cite></p>
  139. <ul class="simple">
  140. <li>if check_links is set, it validates all <cite>Link</cite> fields</li>
  141. <li>if ignore_fields is sets, it does not throw an exception for any field that does not exist in the
  142. database table</li>
  143. </ul>
  144. </dd></dl>
  145. <dl class="method">
  146. <dt id="doc.Document.clear_table">
  147. <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>
  148. <dd>Clears the child records from the given <cite>doclist</cite> for a particular <cite>tablefield</cite></dd></dl>
  149. <dl class="method">
  150. <dt id="doc.Document.addchild">
  151. <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>
  152. <dd><p>Returns a child record of the give <cite>childtype</cite>.</p>
  153. <ul class="simple">
  154. <li>if local is set, it does not save the record</li>
  155. <li>if doclist is passed, it append the record to the doclist</li>
  156. </ul>
  157. </dd></dl>
  158. </dd></dl>
  159. </div>
  160. <div class="section" id="standard-methods-for-api">
  161. <h2>Standard methods for API<a class="headerlink" href="#standard-methods-for-api" title="Permalink to this headline">¶</a></h2>
  162. <dl class="function">
  163. <dt>
  164. <tt class="descname">addchild(parent, fieldname, childtype = '', local=0, doclist=None):</tt></dt>
  165. <dd><p>Create a child record to the parent doc.</p>
  166. <p>Example:</p>
  167. <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">&#39;Contact&#39;</span><span class="p">,</span><span class="s">&#39;ABC&#39;</span><span class="p">)</span>
  168. <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">&#39;contact_updates&#39;</span><span class="p">,</span> <span class="s">&#39;Contact Update&#39;</span><span class="p">,</span> <span class="n">local</span> <span class="o">=</span> <span class="mi">1</span><span class="p">)</span>
  169. <span class="n">d</span><span class="o">.</span><span class="n">last_updated</span> <span class="o">=</span> <span class="s">&#39;Phone call&#39;</span>
  170. <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>
  171. </pre></div>
  172. </div>
  173. </dd></dl>
  174. <dl class="function">
  175. <dt id="doc.removechild">
  176. <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>
  177. <dd>Sets the docstatus of the object d to 2 (deleted) and appends an &#8216;old_parent:&#8217; to the parent name</dd></dl>
  178. </div>
  179. <div class="section" id="naming">
  180. <h2>Naming<a class="headerlink" href="#naming" title="Permalink to this headline">¶</a></h2>
  181. <dl class="function">
  182. <dt id="doc.make_autoname">
  183. <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>
  184. <dd><p>Creates an autoname from the given key:</p>
  185. <p><strong>Autoname rules:</strong></p>
  186. <blockquote>
  187. <ul>
  188. <li><p class="first">The key is separated by &#8216;.&#8217;</p>
  189. </li>
  190. <li><dl class="first docutils">
  191. <dt>&#8216;####&#8217; represents a series. The string before this part becomes the prefix:</dt>
  192. <dd><p class="first last">Example: ABC.#### creates a series ABC0001, ABC0002 etc</p>
  193. </dd>
  194. </dl>
  195. </li>
  196. <li><p class="first">&#8216;MM&#8217; represents the current month</p>
  197. </li>
  198. <li><p class="first">&#8216;YY&#8217; and &#8216;YYYY&#8217; represent the current year</p>
  199. </li>
  200. </ul>
  201. </blockquote>
  202. <p><em>Example:</em></p>
  203. <blockquote>
  204. <ul class="simple">
  205. <li>DE/./.YY./.MM./.##### will create a series like
  206. DE/09/01/0001 where 09 is the year, 01 is the month and 0001 is the series</li>
  207. </ul>
  208. </blockquote>
  209. </dd></dl>
  210. </div>
  211. <div class="section" id="inheritance">
  212. <h2>Inheritance<a class="headerlink" href="#inheritance" title="Permalink to this headline">¶</a></h2>
  213. <dl class="class">
  214. <dt>
  215. <tt class="descname">BaseDocType:</tt></dt>
  216. <dd>The framework supports simple inheritance using the BaseDocType class.
  217. It creates the base object and saves it in the property <cite>super</cite>. The getter then tries to retrive the
  218. property from the <cite>super</cite> object if it exsits before retrieving it from the current record.</dd></dl>
  219. </div>
  220. <div class="section" id="example">
  221. <h2>Example<a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h2>
  222. <p>Open an existing Contact:</p>
  223. <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">&#39;Contact&#39;</span><span class="p">,</span> <span class="s">&#39;ABC&#39;</span><span class="p">)</span>
  224. <span class="n">c</span><span class="o">.</span><span class="n">phone_number</span> <span class="o">=</span> <span class="s">&#39;233-3432&#39;</span>
  225. <span class="n">c</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
  226. </pre></div>
  227. </div>
  228. <p>Create a new Contact:</p>
  229. <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">&#39;Contact&#39;</span><span class="p">)</span>
  230. <span class="n">c</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s">&#39;XYZ&#39;</span>
  231. <span class="n">c</span><span class="o">.</span><span class="n">phone_number</span> <span class="o">=</span> <span class="s">&#39;342-3423&#39;</span>
  232. <span class="n">c</span><span class="o">.</span><span class="n">email_id</span> <span class="o">=</span> <span class="s">&#39;xyz@foo.com&#39;</span>
  233. <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>
  234. </pre></div>
  235. </div>
  236. </div>
  237. </div>
  238. </div>
  239. </div>
  240. </div>
  241. <div class="clearer"></div>
  242. </div>
  243. <div class="related">
  244. <h3>Navigation</h3>
  245. <ul>
  246. <li class="right" style="margin-right: 10px">
  247. <a href="genindex.html" title="General Index"
  248. >index</a></li>
  249. <li class="right" >
  250. <a href="modindex.html" title="Global Module Index"
  251. >modules</a> |</li>
  252. <li class="right" >
  253. <a href="utils_server.html" title="utils — Utilities Module"
  254. >next</a> |</li>
  255. <li class="right" >
  256. <a href="database_api.html" title="Database API Functions"
  257. >previous</a> |</li>
  258. <li><a href="index.html">Documentation</a> &raquo;</li>
  259. <li><a href="server_side_api.html" >3. Server Side API</a> &raquo;</li>
  260. </ul>
  261. </div>
  262. <div class="footer">
  263. &copy; Copyright 2010, Rushabh Mehta.
  264. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
  265. </div>
  266. </body>
  267. </html>