Ok I see what your doing, what I would do is break out the code that
gets the entry from the database into a separate function and then use
that to populate what ever you need.  So I would do this:

def _getdata(self, id):
    '''
    some appropriate database call to get the person you want
    '''
    person = mode.get_by(id)
    return person

def index(self):
    c.person = self._getdata(id)
    return render_responce('index.mako')

def edit(self):
    ....
    render your fomr

def save(self):
    do database stuff
    c.person = what ever is appropriate to make the object
    return render_response('save.mako')

templates
index.mako

<h1>Curriculum vitae</h1>
<div id="content">
I was born. Then I married. And now I'm programming Python.
[FANCY AJAX EDIT LINK]
</div>


edit.mako

<form ...>
<textarea name="cv">
${c.person.cv} #or some appropriate code t fill this in
</textarea>
</form>
[FANCY AJAX SAVE LINK]

save.mako
<div id="content">
${c.person.cv} #or some appropriate code t fill this in[FANCY AJAX EDIT
LINK]
</div>

Alternativly if you want to reduce the redundancy because essentially
same.mako is the "content" fragment you could just use the mako include
tag to have index.mako include save.mako so now your index.mako would
look like:
<h1> Curriculum vitae</h1>
<%include file="save.mako" />

How's that does that reduce the redundancy for you?
Jose


Christoph Haas wrote:
> On Tuesday 03 April 2007 20:13, Jose Galvez wrote:
>   
>> I'm not sure where your redundancy is:  in your first controller you
>> build a page using index.mako, which I'm assuming has a div tag in it
>> that you will replace the contents of using ajax.  Clicking the link
>> will replace the tagged content with the form defined in
>> ajax_edit.mako.  Processing the form using saveform does stuff with the
>> data and then replaces the same div tag again with what gets rendered
>> from ajax_save.mako.
>>     
>
> Correct. And ajax_save.mako prints the same string I already needed to 
> print in index.mako because the page needs to look like before - just with 
> the altered text.
>
>   
>> If I understand you correctly you are only 
>> updating a portion of the screen with each operation and only building
>> the entire page once with the index method.  Could you please explain
>> the issue a little better?
>>     
>
> Sure. It would be easier to explain it over a pizza but since most of you 
> are a few kilometers away I'll try here... :)
>
> def index() renders:
>
> ========================================
> <h1>Curriculum vitae</h1>
> <div id="content">
> I was born. Then I married. And now I'm programming Python.
> [FANCY AJAX EDIT LINK]
> </div>
> ========================================
>
> When the user clicks on the edit link the <div> is replaced (call to 
> editform()):
>
> ========================================
> <form ...>
> <textarea name="cv">
> I was born. Then I married. And now I'm programming Python.
> </textarea>
> </form>
> [FANCY AJAX SAVE LINK]
> ========================================
>
> The user can edit the text and then submit it again which again replaces 
> the <div> by (call to saveform()):
>
> ========================================
> I was born. Then I married. And now I'm programming Python.
> [FANCY AJAX EDIT LINK]
> ========================================
>
> So the redundancy is exactly the last block above. It would make sense to 
> somehow include the last block in the template called/rendered by index(). 
> I am rendering this block twice - first in the index() and then in the 
> saveform(). It's trivial in this example. But imagine that the output is a 
> bit more complicated so that writing the template's logic twice would be 
> unfortunate. One of the problems is that I need to pass the id of the 
> entry (there can be several <div>s on the page) to the template so just 
> including isn't enough. I considered using <%def> and <%namespace> but 
> hoped for an easier way.
>
> Does this make it clearer?
>
>  Christoph
>
> >
>
>   


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to