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

Joel Moxley jfmoxley at gmail.com
Mon Feb 27 20:39:11 EST 2006


On 2/27/06, Gary Poster <gary at zope.com> wrote:
>
> 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
____________________________________________

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.

>From my edit.html...

[clip]
  <div>
   <input type="hidden" name="HTTP_REFERER"
          value="http://localhost:8070/day1/atl-chc/@@overview.html" />
  </div>

  <table class="form-fields">
[...]

>From a pdb trace once I click "apply"...

(Pdb) self.request.form
{u'form.First': u'Jorge', u'form.ERA': u'5.08', u'form.Last': u'Sosa',
u'form.actions.apply': u'Apply'}

... there's no HTTP_REFERER even though we can see that I have the
hidden form in the source!

Does anyone know what I am doing wrong?  I copied Jürgen and Gary's
advice to the letter.

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.

For posterity, here's my exact code

[form class]

class PitcherEditForm(form.EditForm):
    form_fields = form.Fields(interfaces.IPitcher).select('Last',
'First', 'ERA')

    base_template = form.EditForm.template
    template = ViewPageTemplateFile('editTemplate.pt')

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

    def render(self):
        if self.errors is None or self.errors:
            return super(PitcherEditForm, self).render()
        import pdb; pdb.set_trace()
        redirectTo=self.request.form.get('HTTP_REFERER', '..')
        self.request.response.redirect(redirectTo)

[editTemplate.pt]

<div metal:use-macro="view/base_template/macros/main" >
  <div metal:fill-slot="extra_info">
   <input type="hidden" name="HTTP_REFERER" value=""
        tal:attributes="value view/referer" />
  </div>
</div>

Thanks again for everyone's help.

Joel


More information about the Zope3-users mailing list