Re: Persistent python object and the Web



On 21 Apr 2005 11:15:02 -0700, ramon.aragues@xxxxxxxxx wrote:

>Hi,
>
>I'd like to know if I am trying to do something impossible or I am just
>being unable to find how to do it. In the latter case, please... help
>me...
>
>I=B4ve implemented a python class Graph, which handles graphs (with its
>nodes, edges, finding paths, etc). In my text-menu interface, I can add
>nodes, delete nodes, add edges, find shortest routes, etc. I simply
>create a graph_object before presenting the text menu and then, when a
>user choses a command (eg. add-node) I call the method of this object
>with the appropiate parameters.
>
How much total data is involved in the state of the Graph object?
If it's typed in, it can't be that much? Or do you automatically generate
huge subtrees etc.? Anyway, the amount will influence your options.

Then the question is where you want the state to persist. A small amount
can be carried right in the url. Or in preset values in forms, which can
have hidden elements, or in javascript variables that are set from script
parts that represent the state, or cookies that can contain references to
data stored one way or another on the server.

>Now... I need to "translate" this text-menu interface to a web
>interface. The same as the text-menu interface, but letting the user do
>it through the web. I have created an HTML that lets the user enter the
>parameters and chose which command to execute by pushing different
>buttons. But...
You could conceivably implement the whole thing via javascript in an html
page that runs entirely in the client browser, but that probably wouldn't
be as much fun as python ;-)

>
>My problem is that I don't know how to create a graph_object that
>remains persistent through time (it has to be the same graph_object for
>the first command as for the last one "pushed" by the user). I want to
>be able to create the object when the user enters the web page (by
>calling graph_object =3D Graph(id=3D"graph1")) and then make calls to
>graph_object methods when the user pushes a button.
>
>I'm using python2.3, mod_python and Apache.
>
>Any help will be greatly appreaciated.
>
If the state is not too huge, I think I might first create
Graph dump and load methods that would output a nice text
representation of the graph state, and then use a textarea
form element to carry that info, which would get submitted
along with the visible form data. (You could make it all visible
for debugging). You could roll your own format suitable for
textarea transfer. Or you might consider using pickle.Pickler
to create string representations of state info (even a whole tree
if you want to save everything) and maybe do something simple
to make the resulting string ok for a textarea (I don't know
if it can be used as is with protocol 0).
Then you could use pickle.Unpickler to reconstitute what you pickled
when it comes back to the server from the submittal of the textarea
(whose default content you set up each time you serve a web page)
when it comes back again.

Then on the server you can just create an empty Graph instance
an use the submitted textarea state for the load method, and then
go on with the indiviual command data, which would update the Graph
instance state and then you return a web page with the textarea
preset to whatever you get from your graph instance .dump method.

This would be just cgi with no server data base and no cookies or
any of that stuff. Everything persists in the page form data that
is handed back and forth. The client should be able to save the page
to disk and bring it up again, and if your actions and hrefs are
absolute, they should go back to your server.

Anyway, you should be able to test this theory with a simple page
with a simple form. I may have forgotten some gotcha ;-)

If you have really big data, you might want to have it persist
on the server one way or another.

Regards,
Bengt Richter
.



Relevant Pages

  • Re: How to build an application in Django which will handle Multiple servers accross network
    ... Here I am not managing any network devices, what i am doing is getting ... line interface too which gets certain info about server. ... ZenOSS - It is for managing some IP based devices on network.. ... (you have to write a graph def) ...
    (comp.lang.python)
  • Re: ntp documentation
    ... Recently my graph shows lots of blue ... A couple of times an hour the pool system checks the time from your server and compares it to the local time. ... Points are deducted if the server can't be reached or if the time offset is more than 100ms. ... The monitoring system works roughly like an SNTP client, so it is more susceptible by random network latencies between the server and the monitoring system than a regular ntpd client would be. ...
    (comp.protocols.time.ntp)
  • Re: Heatmaps and gnuplot
    ... I am working on a project that requires me to graph a lot of server ... on the latency. ... I have made an attempt to graph the data using the same format as the ...
    (comp.graphics.apps.gnuplot)
  • Re: [PHP] Stupid question of the day (Editing text file in $HOME via web)
    ... Textarea and then write it back (simple enough, ... code to handle the race condition for the DB in a web environment. ... having a web interface that webhosts provide to edit what is ... essentially a simple text file, which configures the web server, mail ...
    (php.general)
  • Re: Dual NICs w failover
    ... Graph 1 and Graph 2 compare the peak performance numbers of Fast Ethernet ... The enterprise server ... the Gigabit Ethernet equipment eliminated the ... >>> even Microsoft recommends using a dedicated hardware firewall with ISA. ...
    (microsoft.public.windows.server.sbs)