[Checkins] SVN: grok/www/minitutorials/ Included xmlrpc tutorial

Darryl Cousins darryl at darrylcousins.net.nz
Wed Aug 8 22:20:09 EDT 2007


Log message for revision 78718:
  Included xmlrpc tutorial

Changed:
  U   grok/www/minitutorials/index.html
  A   grok/www/minitutorials/xmlrpc.html

-=-
Modified: grok/www/minitutorials/index.html
===================================================================
--- grok/www/minitutorials/index.html	2007-08-09 02:19:41 UTC (rev 78717)
+++ grok/www/minitutorials/index.html	2007-08-09 02:20:08 UTC (rev 78718)
@@ -55,6 +55,12 @@
 reflected in all templates, that use it.</p>
 <p>Author: Uli Fouquet</p>
 </li>
+<li><p class="first"><a class="reference" href="/minitutorials/xmlrpc.html">XMLRPC With Grok</a>:</p>
+<p>XMLRPC (<a class="reference" href="http://xmlrpc.com">http://xmlrpc.com</a>) is a spec and a set of implementations
+that allow software running on disparate operating systems, running in
+different environments to make procedure calls over the Internet.</p>
+<p>Author: Kushal Das</p>
+</li>
 </ul>
 <div class="section">
 <h2><a id="buildout" name="buildout">Buildout</a></h2>

Added: grok/www/minitutorials/xmlrpc.html
===================================================================
--- grok/www/minitutorials/xmlrpc.html	                        (rev 0)
+++ grok/www/minitutorials/xmlrpc.html	2007-08-09 02:20:08 UTC (rev 78718)
@@ -0,0 +1,203 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+  <title>XML-RPC using Grok</title><meta name="description" content="Grok - now even cavemen can use Zope3" />
+  <meta name="keywords" content="Grok, internet, zope, zope3, software, web apps, web applications, python" />
+	<style type="text/css"><!-- @import url(/resources/grok.css); --></style>
+</head>
+
+<body>
+<div class="header">
+	
+	<a href="http://grok.zope.org">
+	<img src="/resources/grok-header.jpg" alt="GROK" /></a>
+	<ul id="navigation">
+        <li>
+            <a href="/index.html" class="" title="Home">Home</a></li>
+        <li>
+            <a href="/about.html" class="" title="About">About</a></li>
+        <li>
+            <a href="/tutorial.html" class=""
+               title="Tutorial">Tutorial</a></li>
+        <li>
+            <a href="/minitutorials/index.html" class=""
+               title="How Tos">How Tos</a></li>
+  </ul>
+</div>
+
+
+<div class="roundcont">
+	
+  <div class="roundtop">
+    <img src="/resources/corner-topleft.jpg" alt="" width="45" height="45" class="corner" style="display: none" />
+  </div>
+
+  <div class="content">
+
+          <h1 class="title">XML-RPC using Grok</h1>
+<table class="docinfo" frame="void" rules="none">
+<col class="docinfo-name" />
+<col class="docinfo-content" />
+<tbody valign="top">
+<tr><th class="docinfo-name">Author:</th>
+<td>Kushal Das</td></tr>
+</tbody>
+</table>
+<div class="section">
+<h2><a id="what-is-xml-rpc" name="what-is-xml-rpc">What is XML-RPC ?</a></h2>
+<p>From the site (<a class="reference" href="http://xmlrpc.com">http://xmlrpc.com</a>): it's a spec and a set of implementations
+that allow software running on disparate operating systems, running in
+different environments to make procedure calls over the Internet.</p>
+</div>
+<div class="section">
+<h2><a id="so-what-is-grok" name="so-what-is-grok">So, What is Grok?</a></h2>
+<p>From the site: Grok is a web application framework for Python developers. It
+is aimed at both beginners and very experienced web developers. Grok has an
+emphasis on agile development. Grok is easy and powerful.</p>
+<p>Grok accomplishes this by being based on Zope 3, an advanced object-oriented
+web framework. While Grok is based on Zope 3, and benefits a lot from it, you
+do not need to know Zope at all in order to get productive with Grok.</p>
+<p>So, it is cool, isn't it? :)</p>
+</div>
+<div class="section">
+<h2><a id="installation" name="installation">Installation</a></h2>
+<p>To install the latest grok, give the following command:</p>
+<pre class="literal-block">
+$ sudo easy_install grokproject
+</pre>
+<p>This will download and install grok for you. After this we are ready to rock...</p>
+</div>
+<div class="section">
+<h2><a id="creating-our-first-project" name="creating-our-first-project">Creating our first project</a></h2>
+<p>Let's create the project named &quot;Foo&quot;. For that give the command:</p>
+<pre class="literal-block">
+$ grokproject Foo
+</pre>
+<p>This will create a subdirectory in the current directory named &quot;Foo&quot;, then it
+will download Zope3 and install Grok with that which you can start working
+with. It will ask you a few questions like:</p>
+<pre class="literal-block">
+Enter module (Name of a demo Python module placed into the package) ['app.py']:
+</pre>
+<p>Press Enter for the default value. Then:</p>
+<pre class="literal-block">
+Enter user (Name of an initial administrator user): grok
+Enter passwd (Password for the initial administrator user): grok
+</pre>
+<p>We typed &quot;grok&quot; for both the user and password.</p>
+</div>
+<div class="section">
+<h2><a id="starting-up-zope" name="starting-up-zope">Starting up Zope</a></h2>
+<p>Switch to the Foo directory, and give the command:</p>
+<pre class="literal-block">
+$ bin/zopectl fg
+</pre>
+<p>This will startup Zope for you, you can access it through a web browser
+pointing to <a class="reference" href="http://localhost:8080/">http://localhost:8080/</a> . Then add an application named <em>foo</em>.</p>
+<p>You can access it by <a class="reference" href="http://localhost:8080/foo">http://localhost:8080/foo</a>, it will show:</p>
+<pre class="literal-block">
+Congratulations!
+
+Your Grok application is up and running. Edit foo/app_templates/index.pt to
+change this page.
+</pre>
+<p>Now we are going to write our xmlrpc stuffs inside it.</p>
+</div>
+<div class="section">
+<h2><a id="xml-rpc-class" name="xml-rpc-class">XML-RPC class</a></h2>
+<p>Now you can open the file src/foo/app.py in a text editor. The default is
+shown below:</p>
+<pre class="literal-block">
+import grok
+
+class Foo(grok.Application, grok.Container):
+    pass
+
+class Index(grok.View):
+    pass # see app_templates/index.pt
+</pre>
+<p>We will another class which will be available through this application class,
+the new class should inherit <tt class="docutils literal"><span class="pre">grok.XMLRPC</span> <span class="pre">for</span> <span class="pre">this</span></tt>, and we will write a
+<tt class="docutils literal"><span class="pre">say()</span></tt> method. It will return &quot;Hello World!&quot;. So, the changed file:</p>
+<pre class="literal-block">
+import grok
+
+class Foo(grok.Application, grok.Container):
+    pass
+
+class Index(grok.View):
+    pass # see app_templates/index.pt
+
+class FooXMLRPC(grok.XMLRPC):
+    &quot;&quot;&quot;The methods in this class will be available as XMLRPC methods
+       on 'Foo' applications.&quot;&quot;&quot;
+
+    def say(self):
+        return 'Hello world!'
+</pre>
+<p>The name of the class doesn't matter, so you can give it any name.
+Restart the Zope in the console, and you can connect to it through any xmlrpc
+client. Below is an example (fooclient.py):</p>
+<pre class="literal-block">
+#!/usr/bin/env python
+import xmlrpclib
+
+s = xmlrpclib.Server('http://localhost:8080/foo')
+print s.say()
+</pre>
+<p>Run this and see !!</p>
+</div>
+<div class="section">
+<h2><a id="class-in-a-different-file" name="class-in-a-different-file">Class in a different file</a></h2>
+<p>What if you want to write the class in a different file in the src/foo
+directory and still want to have the methods to be available under Foo
+application. For that you need to tell grok explicitly that the new class to
+associate it to the Foo model by using the grok.context class annotation.</p>
+</div>
+<div class="section">
+<h2><a id="what-is-a-class-annotation" name="what-is-a-class-annotation">What is a class annotation?</a></h2>
+<p>A class annotation is a declarative way to tell grok something about a Python
+class. Let's see the example, we write a Boom.py with a Boom class:</p>
+<pre class="literal-block">
+import grok
+from app import Foo
+
+class Boom(grok.XMLRPC):
+    grok.context(Foo)
+
+    def dance(self):
+        return &quot;Boom is dancing!!&quot;
+</pre>
+<p>Look at the line where it says <tt class="docutils literal"><span class="pre">grok.context(Foo)</span></tt> this is doing all the
+magic. In the fooclient.py you just need to call <tt class="docutils literal"><span class="pre">s.dance()</span></tt> instead of
+<tt class="docutils literal"><span class="pre">s.say()</span></tt>.</p>
+<p>So, now write your dream system...</p>
+</div>
+
+  </div>
+
+  <div class="roundbottom">
+     <img src="/resources/corner-bottomleft.jpg" alt="" width="45" height="45" class="corner" style="display: none" />
+  </div>
+
+</div>
+
+<div class="footer">
+	
+	<table><tr><td>
+	Grok cooks around the campfire of <br />
+	<a href="http://wiki.zope.org/zope3/FrontPage"><img src="/resources/zopelogo.gif" alt="Zope" style="padding: 0.5em;" /></a>
+	</td><td>
+	 and roams free on the savannah of<br />
+	<a href="http://www.python.org"><img src="/resources/python-logo.gif" style="padding: 0.5em;" alt="Python" /></a>
+	</td></tr>
+	</table>
+
+	<p>Hosting provided by <a href="http://quintagroup.com/"><b>Quintagroup</b></a></p>
+</div>
+
+</body>
+</html>



More information about the Checkins mailing list