I would avoid using the XML as much as possible since this code
introduces XSS vulnerabilities.
Technically you are not using the partial described above (your are
not calling the _department_view using ajax).

your way of using sub-templates is fine.

Massimo




On Apr 2, 10:45 am, Brian <br...@brianmaddy.com> wrote:
> Steve,
>
> I eventually ran into the problem of having one controller need to use
> the partial for another controller.  When this happens, you can move
> the partial function into a model file.  Then, as partials get more
> complex, you can abstract most of them out to a view with
> response.render(...).  For example, say you have a department manager
> page where you can manage many employees:
>
> # in controllers/employees.py
> # this lets you view a single employee on an employee page
> def show():
>     ...
>     # grab your employee record from the db
>     row=db(...).select(...)
>     if row: row=row[0]
>
>     return dict(content=_employee_view(row))
>
> # in controllers/departments.py
> # this lets you view many employees on a department page
> def show():
>     ...
>     # grab our employees from the db
>     employees=db(...).select(...)
>
>     return dict(content=_department_view(employees))
>
> # in models/partials.py
> # (note how the _department_view partial uses the _employee_view
> partial)
> def _department_view(records):
>     content=''
>     for record in records:
>         content=content+_employee_view(record).xml()
>     return XML(response.render('departments/_view.html', content=XML
> (content)))
>
> def _employee_view(record):
>     return XML(response.render('employees/_view.html', record=record))
>
> With this setup it would also be easy to make an entire company page
> that lists all departments and corresponding employees.
>
> I'm not sure if this is the best way to do it with web2py or not, but
> it's the one I could get to work.  I hope it is of help.
>
> Cheers,
> Brian
>
> On Apr 1, 10:06 pm, Steve Shepherd <sargs...@gmail.com> wrote:
>
> > Yarko
> > I meant the very first code example posted at the top.
> > He put class index():
> > Which when I changed to a def inside my controller worked fine.
> > Thanks for the file though
> > ________________________
> > Steve Shepherd
> > Mob:+64  (0) 27 4338154
> > Email: sargs...@gmail.com
> > Analyst
>
> > On Thu, Apr 2, 2009 at 3:37 PM, Yarko Tymciurak <yark...@gmail.com> wrote:
> > > On Wed, Apr 1, 2009 at 8:59 PM, Steve Shephed <sargs...@gmail.com> wrote:
>
> > >> Just a note about the code Massimo supplied below.
>
> > >> The class declaration should be changed to def if you are putting it
> > >> in a controller like default.py
>
> > > I don't know why you say that.  (I don't think it would work as a "def"
> > > actually)
>
> > > Just to remove the line-wrap issues, I've attached a working default.py
> > > controller - make a new app, and use this default.py to demo it.
>
> > >> Also the code has linewrapped so don't forget to append the 2 lines
> > >> after button1 so that it works properly.
>
> > >> mdipierro wrote:
>
> > >> > I think this does what you ask:
>
> > >> > class index():
> > >> >      button1=TAG.BUTTON(_onclick="$.ajax({url: '%s', success: function
> > >> > (value) { $('#target').html(value); } });" % URL
> > >> > (r=request,f='callback'))
> > >> >      div1=DIV(_id='target')
> > >> >      return dict(button1=button1, div1=div1)
>
> > >> > class callback():
> > >> >      return H1('Hello world').xml()
>
> > >> > On Apr 1, 3:18 pm, Steve Shephed <sargs...@gmail.com> wrote:
> > >> > > Hi Anyone
> > >> > > How do we implement (with a view type paradigm) a partial coding.
> > >> > > In RoR you can setup divs that then are given a partial setting so
> > >> > > that other divs in the view can update them.
> > >> > > Also if you create a list of items through an iteration you may want
> > >> > > to show() a div that loads content onclick()
> > >> > > Rather than loading the whole page with the view and just hiding the
> > >> > > bits you don't want.
> > >> > > The loading of content onclick is so much quicker.
> > >> > > Any ideas?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to