[Zope3-Users] Re: redirects in a formlib EditForm

2006-02-27 Thread jürgen Kartnaller
Gary Poster wrote:
 
 On Feb 26, 2006, at 4:17 PM, jürgen Kartnaller wrote:
 
 Joel Moxley wrote:
 ** What is the best way to use a formlib EditForm to redirect a user
 after applying changes without fully cloning a handle_edit_action
 method? **

 I'm doing it this way :

 def render(self):
 if self.errors is None or self.errors:
 return super(EditPerson, self).render()
 self.request.response.redirect('..')

 Jürgen

 Thanks Jürgen!  That works perfectly for me.

 Looking one step forward, I would like to redirect the user back to
 the previous page from whence they came (without using sessions).  I
 figure I am going to need to stash that value on my EditForm class and
 then pull it up during the redirect in my render method.  I've done my
 best to explore this, but I can't figure out where the previous page
 information will be available on my EditForm.

 ** Where should I stash previous page information for future redirects
 on my EditForm? **

 That's also an unsolved use case I have.

 The 'default' template of 'FormBase' contains the slot 'extra_info'
 which could be filled with some hidden input fields.

 I defined a new template for my own EditForm.

 But now I would like to use the existing template in formlib
 'pageform.pt' and fill the slot but don't know how.

 Is this a possible way and the right way ?

 How can I use the existing template ?
   It must be useable with metal:use-macro somehow.
 
 Yes, we write custom templates that use hidden input fields.  We reuse
 the existing template by putting the default template on another
 attribute of the view class, and then saying 'metal:use-macro=view/...'
 
 For instance
 
 class MyForm(zope.formlib.form.EditForm):
 base_template = zope.formlib.form.EditForm.template
 template = (...a named template if you want, or just a page template
 directly...)
 
 Then in your template, you can refer to macros in the original like this:
 
 'metal:use-macro=view/base_template/macros/extra_info'

Thanks a lot for this.

The above metal statement doesn't work, I do it this way :
  metal:use-macro=view/base_template/macros/main
and then
  metal:fill-slot=extra_info

Jürgen


-- 

---
Jürgen Kartnaller   mailto:juergen_at_kartnaller.at
http://www.kartnaller.at
http://www.mcb-bregenz.at
---

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Re: redirects in a formlib EditForm

2006-02-27 Thread Gary Poster


On Feb 27, 2006, at 6:52 AM, jürgen Kartnaller wrote:


Gary Poster wrote:

[...]
Yes, we write custom templates that use hidden input fields.  We  
reuse

the existing template by putting the default template on another
attribute of the view class, and then saying 'metal:use- 
macro=view/...'


For instance

class MyForm(zope.formlib.form.EditForm):
base_template = zope.formlib.form.EditForm.template
template = (...a named template if you want, or just a page  
template

directly...)

Then in your template, you can refer to macros in the original  
like this:


'metal:use-macro=view/base_template/macros/extra_info'


Thanks a lot for this.

The above metal statement doesn't work, I do it this way :
  metal:use-macro=view/base_template/macros/main
and then
  metal:fill-slot=extra_info


Heh, yeah.  Thanks for clarifying.

Gary___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Re: redirects in a formlib EditForm

2006-02-27 Thread Gary Poster


On Feb 27, 2006, at 8:39 PM, Joel Moxley wrote:


Damn, I still can't get this working right after following all of the
instructions here.  I can successfully stash the refering url in a
hidden form, but it's not showing up in my request.


I can think of two possible things.

One is that you are maybe getting a form validation error and then  
pressing Apply, or that you are using a widget that redraws the screen.


Another is that we might have a bug that makes form variables be  
stomped on by header names. :-(


First try changing


def referer(self):
return self.request.getHeader('HTTP_REFERER')


to

def referer(self):
return self.request.form.get('HTTP_REFERER') or  
self.request.getHeader('HTTP_REFERER')


Then if that doesn't work, try changing it to

def referer(self):
return self.request.form.get('referrer') or  
self.request.getHeader('HTTP_REFERER')


and changing your template to have

   input type=hidden name=referrer value=
tal:attributes=value view/referer /


(Sadly, the spec made a spelling error with referer. :-) )


By the way, my svn update had a conflict at
src/zope/interface/common/.  I deleted the old one and it worked fine,
but I guess I'll note it here.


Yeah, they are rearranging things at PyCon.

Gary
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Re: redirects in a formlib EditForm

2006-02-26 Thread Joel Moxley
  ** What is the best way to use a formlib EditForm to redirect a user
  after applying changes without fully cloning a handle_edit_action
  method? **
 

 I'm doing it this way :

 def render(self):
 if self.errors is None or self.errors:
 return super(EditPerson, self).render()
 self.request.response.redirect('..')

 Jürgen

Thanks Jürgen!  That works perfectly for me.

Looking one step forward, I would like to redirect the user back to
the previous page from whence they came (without using sessions).  I
figure I am going to need to stash that value on my EditForm class and
then pull it up during the redirect in my render method.  I've done my
best to explore this, but I can't figure out where the previous page
information will be available on my EditForm.

** Where should I stash previous page information for future redirects
on my EditForm? **

Thanks,
Joel
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Re: redirects in a formlib EditForm

2006-02-26 Thread Joel Moxley
On 2/26/06, Gary Poster [EMAIL PROTECTED] wrote:

 On Feb 26, 2006, at 4:17 PM, jürgen Kartnaller wrote:

  Joel Moxley wrote:
  ** What is the best way to use a formlib EditForm to redirect a
  user
  after applying changes without fully cloning a handle_edit_action
  method? **
 
  I'm doing it this way :
 
  def render(self):
  if self.errors is None or self.errors:
  return super(EditPerson, self).render()
  self.request.response.redirect('..')
 
  Jürgen
 
  Thanks Jürgen!  That works perfectly for me.
 
  Looking one step forward, I would like to redirect the user back to
  the previous page from whence they came (without using sessions).  I
  figure I am going to need to stash that value on my EditForm class
  and
  then pull it up during the redirect in my render method.  I've
  done my
  best to explore this, but I can't figure out where the previous page
  information will be available on my EditForm.
 
  ** Where should I stash previous page information for future
  redirects
  on my EditForm? **
 
  That's also an unsolved use case I have.
 
  The 'default' template of 'FormBase' contains the slot 'extra_info'
  which could be filled with some hidden input fields.
 
  I defined a new template for my own EditForm.
 
  But now I would like to use the existing template in formlib
  'pageform.pt' and fill the slot but don't know how.
 
  Is this a possible way and the right way ?
 
  How can I use the existing template ?
It must be useable with metal:use-macro somehow.

 Yes, we write custom templates that use hidden input fields.  We
 reuse the existing template by putting the default template on
 another attribute of the view class, and then saying 'metal:use-
 macro=view/...'

 For instance

 class MyForm(zope.formlib.form.EditForm):
  base_template = zope.formlib.form.EditForm.template
  template = (...a named template if you want, or just a page
 template directly...)

 Then in your template, you can refer to macros in the original like
 this:

  'metal:use-macro=view/base_template/macros/extra_info'

 Notice that the pageform.pt *extends* the context/@@standard_macros/
 view macro, so you can customize slots from your main template too.

 There are lots of other solutions, but that's the one I know of that
 I consider to be best ATM.

 Gary___
 Zope3-users mailing list
 Zope3-users@zope.org
 http://mail.zope.org/mailman/listinfo/zope3-users

Thanks.  Ok, so now that I know the location on which to stash
previous page information, _how_ do I get the previous page
information?

**
Ie, at what method in the edit form do I pull out the page from whence
the user came?  And most importantly, how do I get the page from
whence the user came?  Is it in the incoming request?  I've been
looking at the request object, but I did not see that information in
there.
**

So the idea is...

page X - edit.html - apply - page X

... where page X can change.

Thanks,
J
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users