Changes

Jump to: navigation, search

GEPS 013: Gramps Webapp

1,974 bytes added, 08:04, 2 August 2009
Prototype
</pre>
Under the hood, the names "db" and "dbstate" are collected, sent over the socket to the server as the string "self.dbstate.db" which is evaluated, and the representation is sent back. Notice that the server cannot return an entire dbstate or db object to the client, but it merely returns the repr string.
You can interactively explore the remote objects, too:
<pre>
</pre>
Notice that you can't wrap a "dir()" around a property, but you can tack a ".dir()" on the end to provide the same functionality. You can't wrap a dir() around the self.dbstate.db because that would get applied on the client side, and by the time self.dbstate.db is evaluated, it is just the repr string. But, you can also get back some full GRAMPS objects: <pre>>>> self.dbstate.db.get_default_person()<gen.lib.person.Person object at 0xb7d7ac6c></pre> This isn't just the repr string returned this time, but a real object. You can test that by: <pre>>>> p = self.dbstate.db.get_default_person()>>> p.get_primary_name().get_surname()u'Blank'</pre> Because you can't get back generators nor database objects, sometimes you need to do some processing on the server. To do this, you can use self.remote:  >>> self.remote("person = self.sdb.name(self.dbstate.db.get_default_person())") self.remote takes a string and sends it to the server to be evaluated (or executed). self contains: <pre>>>> self.dir()['__doc__', '__init__', '__module__', 'arghandler', 'climanager', 'dbstate', 'env', 'eval', 'reset', 'sdb']</pre> * arghandler - the object that handles the CLI operations* climanager - * dbstate - holds the state of the database* dbstate.db - the database* sdb - simple database access Finally, here is an example for listing out the surnames of a family tree on the web: <pre>#!/usr/bin/python import sys, ossys.path.append("/home/dblank/gramps/trunk/src")os.environ["HOME"] = "/home/dblank/html/gramps" from cli.client import * self = RemoteObject("localhost", 50000) print "Content-type: text/html"printprint "<html>"print "<body>"print "First Demo of GRAMPS --server" surnames = self.dbstate.db.surname_list[:] for name in surnames: print "<li><a href=\"?surname=%s\">%s</a></li>" % (name, name) print "<hr>"print "</body>"print "</html>"</pre> and the resulting screen shot: [[Image:GRAMPS-server.png]] == Discussion ==
[[Category:GEPS|S]]

Navigation menu