Roundup Tracker - Issues

Issue 994957

classification
ZRoundup FormWrapper class too wimpy
Type: Severity: normal
Components: Web interface Versions:
process
Status: closed fixed
:
: richard : njs, richard
Priority: normal :

Created on 2004-07-21 02:24 by njs, last changed 2004-07-21 02:24 by njs.

Files
File name Uploaded Description Edit Remove
ZRoundup.py richard, 2004-07-21 04:49
Messages
msg1390 Author: [hidden] (njs) Date: 2004-07-21 02:24
The ZRoundup frontend defines a class 'FormWrapper',
that takes a Zope form object and attempts to present
an interface that looks like a cgi.py form object. 
Understandably, it doesn't attempt to implement the
full multitude of FieldStorage methods.  However, the
'getvalue()' method -- which is extremely useful, used
by the 'classic' page.html template, and has no simple
replacement in TAL -- is not implemented.  This means,
for instance, that on a classic tracker under ZRoundup,
the 'issue search' page displays a traceback.

Suggested fix:
 - add to the FormWrapper class a method:
  def getvalue(self, key, default=None):
      if self.form.has_key(key):
          return self.form[key]
      else:
          return default
msg1391 Author: [hidden] (njs) Date: 2004-07-21 04:11
Logged In: YES 
user_id=765

If the above problem is fixed, it turns out that there is a
worse one lurking.  In actions.py,
SearchAction.fakeFilterVars attempts in several places to
modify self.form.value.  However, when self.form is a
ZRoundup FormWrapper, there is no attribute self.form.value.
 This means that searching doesn't work with ZRoundup at
all, no matter what template one is using.

The ideal solution is not obvious to me.
msg1392 Author: [hidden] (richard) Date: 2004-07-21 04:32
Logged In: YES 
user_id=6405

Try the following (untested) replacement for FormWrapper: 
 
class FormWrapper: 
    '''Make a Zope form dict look like a cgi.py one 
    ''' 
    def __init__(self, form): 
        self.form = form 
        self.additional = [] 
    def __getitem__(self, item): 
        for entry in self.additional: 
            if entry.name == item: 
                return entry 
        return FormItem(self.form[item]) 
    def has_key(self, item): 
        for entry in self.additional: 
            if entry.name == item: 
                return 1 
        return self.form.has_key(item) 
    def keys(self): 
        l = [e.name for e in self.additional] 
        for name in self.form.keys(): 
            if name not in l: 
                l.append(name) 
        return l 
    def append(self, item): 
        self.additional = [] 
 
msg1393 Author: [hidden] (richard) Date: 2004-07-21 04:33
Logged In: YES 
user_id=6405

(oops, my code didn't include the additional getvalue() method 
you defined) 
msg1394 Author: [hidden] (richard) Date: 2004-07-21 04:34
Logged In: YES 
user_id=6405

gawd. just noticed another problem with it. if I could delete 
comments from this tracker, I would. The following is a better 
(but still untested) version: 
 
class FormWrapper: 
    '''Make a Zope form dict look like a cgi.py one 
    ''' 
    def __init__(self, form): 
        self.form = form 
        self.additional = [] 
    def __getitem__(self, item): 
        for entry in self.additional: 
            if entry.name == item: 
                return entry 
        return FormItem(self.form[item]) 
    def getvalue(self, key, default=None): 
        if self.form.has_key(key): 
            return self.form[key] 
        else: 
            return default 
    def has_key(self, item): 
        for entry in self.additional: 
            if entry.name == item: 
                return 1 
        return self.form.has_key(item) 
    def keys(self): 
        l = [e.name for e in self.additional] 
        for name in self.form.keys(): 
            if name not in l: 
                l.append(name) 
        return l 
    def append(self, item): 
        self.additional.append(item) 
 
msg1395 Author: [hidden] (richard) Date: 2004-07-21 04:40
Logged In: YES 
user_id=6405

OK, enough of this half-arsed blathering away on my part. I'm 
working on the interface right now to make a patch that works. 
msg1396 Author: [hidden] (richard) Date: 2004-07-21 04:49
Logged In: YES 
user_id=6405

Right. The attached file has been verified to work. It's a drop-in 
replacement for ZRoundup.py. The fix is also in CVS and will 
appear in the 0.7.7 release. 
History
Date User Action Args
2004-07-21 02:24:32njscreate