[Grok-dev] URL Construction

Tim Cook timothywayne.cook at gmail.com
Fri May 1 16:29:25 EDT 2009


Hi All,

(forgive the formatting that gets screwed up in email. some lines are
long)



I have an application:

class bptrack(grok.Application, grok.Container ):
    pass

bptrack has two containers created like this:

class Setup(grok.View):
    grok.context(bptrack)
    
    def render(self):
        try:
            self.context['demographics'] = grok.Container() 
            self.context['clinical'] = grok.Container() 
        except DuplicationError:
            pass


When I add an item (inherits from grok.Model) to the demographics
container I also create an item in the clinical container.  One of the
attributes (ehrid) of the model contains the id (becomes a key) for the
clinical item. I do this with reender() in a View. This creation step
looks like this:

    grok.context(bptrack)

    def render(self):

obj=Patient(self.request.form['surName'],self.request.form['givenName'],self.request.form['dob'])
        self.context['demographics'][obj.patid]=obj        
        self.context['clinical'][obj.ehrid]=Ehr() # a grok.Container
        self.context['clinical'][obj.ehrid]['created']=datetime.now()
        self.context['clinical'][obj.ehrid]['system']=u'OSHIP'

In my page templates I list all the entries in demographics down the
left side in a Viewlet.  

What I  want to do is (seems simple) construct a URL from the
demographics entry to the matching clinical entry and display it in a
different ViewletManager. I have tried several approaches such as
specifically naming the viewlet, setting the viewlet context to the Ehr
class, using grok.name('index') on the viewlet and not appending
anything to the end of the Ehr object (thinking it would look for an
index in it's context).  My URLs all LOOK good to me.  But each time I
get the ZMI page "The page that you are trying to access is not
available" with the Navigation box expanded and the correct item
highlighted. 

Here is how I construct the URLs from the Listiing viewlet of the
demographics container.  

names=[]
retstr='<ul>'
keylist=self.context['demographics'].keys()
 for x in keylist: # create a tuple to append to the names list that
also includes the ehrurl.

   sname=self.context['demographics'][x].surName
   gname=self.context['demographics'][x].givenName
   dob=self.context['demographics'][x].dob
   fname=gname+" "+sname

# To get the url we have to use the parent view, then strip off that
#name and add the clinical container
# and each patient's record number (ehrid). Send the full name so we can
#display it in the ehrview (or index or whatever will finally work).

ehrurl=self.view.url().strip('bpmain')+'clinical/'+self.context['demographics'][x].ehrid
            
names.append((sname,gname,dob,ehrurl))
            
# create the display string to return to the interface.    
for y in names:
   retstr+= '<li><a href="'+y[3]+'">'+y[0]+','+y[1]+'</a> '+y[2]+'</li>'
            
retstr+='</ul>'   
        
if retstr == '<ul></ul>':
   retstr = "You haven't added any patients to this system.
Please use the Add patient Form."
            
return retstr
            
The source code and templates are available on Launchpad:
http://tinyurl.com/cvwwj9

or the full URL:

http://bazaar.launchpad.net/~timothywayne-cook/oship/adl2py/files/head%
3A/oship/src/oship/

The subject code is in bptrack.py with the templates in
bptrack_templates.

Thanks for any and all hints or tips.

Cheers,
Tim




-- 
Timothy Cook, MSc
Health Informatics Research & Development Services
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook 
Skype ID == timothy.cook 
**************************************************************
*You may get my Public GPG key from  popular keyservers or   *
*from this link http://timothywayne.cook.googlepages.com/home*
**************************************************************
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://mail.zope.org/pipermail/grok-dev/attachments/20090501/708bf995/attachment.bin 


More information about the Grok-dev mailing list