[ZCM] [ZC] 1949/ 2 Resolve "Bug in Examples.zexp code"

"Collector: Zope Bugs, Features, and Patches ..." <[email protected]> Mon, 14 May 2007 14:04:19 -0400
Newsgroups gmane.comp.web.zope.devel.collector-monitor
Message-ID <[email protected]>
Issue #1949 Update (Resolve) "Bug in Examples.zexp code"
 Status Resolved, Zope/bug+solution low
To followup, visit:
  http://www.zope.org/Collectors/Zope/1949

==============================================================
= Resolve - Entry #2 by ajung on May 14, 2007 2:04 pm

 Status: Pending => Resolved

Fixed lately for Zope 2.9, Zope 2.10, trunk
________________________________________
= Request - Entry #1 by quiver on Nov 16, 2005 8:20 am

If you go to "File Library" directory and sort files by the same attribute twice in a row, it raises a ValueError, saying that :

  An integer was expected in the value 'False'

This happens because the variable, reverse,  is intended to be an integer type, but boolean operation(e.g., not reverse) is used and it changes into a boolean type. This happens when Zope is compiled against Python >= 2.3.

# How to fix it?

The quickest hack would be to cast the ``reverse'' variable to int :

# Examples/FileLibrary/getLink .

  if new_sort != sort:
      new_reverse=0
  else:
      #new_reverse=not reverse
      new_reverse=int(not reverse)    # <- fix


But given that ``reverse'' variable takes only 0 or 1, changing it into a boolean type makes more sense. However, this may cause trouble for old Python(2.2, 2.1, etc). In this case, following changes(2 files) are needed:

# Examples/FileLibrary/index_html
Line 50 & 54(2 places)

  tal:attributes="href string:${request/URL0}?start:int=${next/first}&sort=$sort&reverse:boolean=$reverse"


# Examples/FileLibrary/getLink

  if new_sort != sort:
      new_reverse=False      # fix
  else:
      new_reverse=not reverse
  return "%s?sort=%s&reverse:boolean=%s" % (url, new_sort, new_reverse)#  fix


==============================================================