[Grok-dev] REPOST Re: Add Form URLS

Sebastian Ware sebastian at urbantalk.se
Sat Jan 24 14:28:02 EST 2009


24 jan 2009 kl. 20.05 skrev Tim Cook:

> On Sat, 2009-01-24 at 18:58 +0100, Sebastian Ware wrote:
>> 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
>
> So are you saying that "somewhere" (app.py???) I could setup my  
> database
> with:
>
> app["Oship"]=grok.application()
> Oship["clinical"]=grok.Container()
> Oship["demographics"]=grok.Container()
> Oship["ar"]=grok.Container()
> Oship["termserver"]=grok.Container()
>
> automagically?
>

Kind of. The application is added by you manually in the admin  
interface. The __init__ method is run when the application is added  
and you can do your setup there.


class Oship(grok.Application):

    def __init__(self):
        self.context['clinical'] = grok.Container()
        # etc... "automagically"
        # Note, this only runs when you create the application

Another way to add that stuff is through a view:

class Setup(grok.View):
    grok.context(Oship)

    def render(self):
        self.context['clinical'] = grok.Container()
        # etc.
        return "Done!"

You access the setup view with an url like this:

    http://localhost:8080/app_name/setup

You will need to change the context of your add class since you adding  
objects to grok.Container.

class AddEhr(grok.AddForm):
    grok.context(grok.Container)
    form_fields = grok.AutoFields(Ehr)

    def add(self, **data):
       new_obj = Ehr()
       self.applyData(new_obj, **data)
       self.context[key] = new_obj

You access the add view with an url like this:

    http://localhost:8080/app_name/clinical/addehr

Mvh Sebastian


More information about the Grok-dev mailing list