[Grok-dev] REPOST Re: Add Form URLS
Sebastian Ware
sebastian at urbantalk.se
Sat Jan 24 14:17:46 EST 2009
24 jan 2009 kl. 19.26 skrev Tim Cook:
> On Sat, 2009-01-24 at 18:58 +0100, Sebastian Ware wrote:
>
>>
>> def add(self, **data):
>> new_obj = Ehr() # Create a new object
>> self.applyData(new_obj, **data) # Apply the changes (unless they
>> were supplied in the line above)
>> self.context[key] = new_obj # Store the object with a key of your
>> choice (think ordinary dictionary)
>>
>
> I haven't tried this yet because I'd like to clarify your comments
> below.
>
>> Are you aware that you need a root container subclassing
>> grok.Application in order to be able to add an application to your
>> Grok instance?
>
> Well, yes I think. I created Oship manually through the application
> interface. I assume that is why: from app import Oship works okay.
Now I saw the import. Did you add your first instance of Ehr to the
application container manually?
The application class is your root container. You need to add your
root Ehr object to the application container. Then to access your add
form you use
http://localhost:8080/app_name/root_ehr_name/addehr
"root_ehr_name" is the name/key that you specified when adding your
root Ehr object to the application container (I am guessing you called
it "clinical"). "addehr" is the name of your add form which is
associated (grok.context) to the Ehr object. A default add form will
appear and when you submit this form, the code in the "Add Event"
action will execute.
>
>
>> This is also behaves like a dictionary, but
>> grok.Application, unlike grok.Container, kan be populated during
>> __init__. In other words, you can add your root Ehr object when you
>> are creating your app.
>
> I'm attempting baby steps here. I'll eventually want MANY EHR objects
> inside Oship.clinical (with clinical be a single container within
> Oship).
>
> But I am getting the impression from your comments (in the code above)
> that I need to create an HTML form to submit the data. Whereas I
> thought that subclassing grok.AddForm would (at some URL) give me a
> basic add form based on the schema.
A really good idea is to setup some kind of debugging environment
(search the mailing list for discussions on the topic). That way you
can examine various objects to learn more about what you can do at
certain points in the code. I experiment a lot like this and it saves
both time and frustration. Highly recomended. I drop into a debugging
session probably every five minutes. Personally I use Komodo IDE which
allows me to have an interactive python session at the breakpoint, but
I am guessing pdbg works fine too, I haven't used it myself.
Mvh Sebastian
More information about the Grok-dev
mailing list