[Zope-dev] Re: [Zope] Please test this Zope 2.2 beta 1 ZSQLMethods fix...
T.J. Mannos
wmannotj@WWW.SLCC.edu
Fri, 23 Jun 2000 08:28:32 -0600
This is a multi-part message in MIME format.
------=_NextPart_000_0070_01BFDCED.044F50D0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
That did it! But... :)
I ended up having to re-create all my ZSQL methods, which was funny because
they all worked in the beta 1 but not in beta 2. I kept getting len() of
unsized object errors. Anyway, re-creating them all from scratch (ugh..)
solved that problem.
BUT, the BIG problem I'm having is still with the external method in
courseList.py. I'll attach the file here. It returns a list that can be
traversed with the <dtml-in> tag. I'm still getting Unauthorized errors
when trying to access properties of the objects this function returns. For
instance, when I run this function on a query sorted by 'term', the first
object in the list contains a property called 'open-term'. When I try to
access this property within a <dtml-in> tag, even as Superuser, it gives me
an Unauthorized error. I tried everything, even giving anonymous users all
privileges to that external method. Nothing worked. Here's my traceback:
Unauthorized
Sorry, a Zope error occurred.
Traceback (innermost last):
File /usr/Zope-2.2.0b2-solaris-2.6-sparc/lib/python/ZPublisher/Publish.py,
line 222, in publish_module
File /usr/Zope-2.2.0b2-solaris-2.6-sparc/lib/python/ZPublisher/Publish.py,
line 187, in publish
File /usr/Zope-2.2.0b2-solaris-2.6-sparc/lib/python/ZPublisher/Publish.py,
line 171, in publish
File /usr/Zope-2.2.0b2-solaris-2.6-sparc/lib/python/ZPublisher/mapply.py,
line 160, in mapply
(Object: list_courses)
File /usr/Zope-2.2.0b2-solaris-2.6-sparc/lib/python/ZPublisher/Publish.py,
line 112, in call_object
(Object: list_courses)
File /usr/Zope-2.2.0b2-solaris-2.6-sparc/lib/python/OFS/DTMLDocument.py,
line 168, in __call__
(Object: list_courses)
File
/usr/Zope-2.2.0b2-solaris-2.6-sparc/lib/python/DocumentTemplate/DT_String.py
, line 503, in __call__
(Object: list_courses)
File
/usr/Zope-2.2.0b2-solaris-2.6-sparc/lib/python/DocumentTemplate/DT_Let.py,
line 145, in render
(Object: page=id)
File /usr/Zope-2.2.0b2-solaris-2.6-sparc/lib/python/OFS/DTMLMethod.py,
line 163, in __call__
(Object: course_list)
File
/usr/Zope-2.2.0b2-solaris-2.6-sparc/lib/python/DocumentTemplate/DT_String.py
, line 503, in __call__
(Object: course_list)
File
/usr/Zope-2.2.0b2-solaris-2.6-sparc/lib/python/DocumentTemplate/DT_Let.py,
line 145, in render
(Object: groupby="['term','type','category']"
query="db.listCourses(type=type,term=term,keyword=keyword,category=category,
inactive=inactive,show_new=PARENTS[0].id=='admin')")
File
/usr/Zope-2.2.0b2-solaris-2.6-sparc/lib/python/DocumentTemplate/DT_In.py,
line 691, in renderwob
(Object: extern.courseList(_, groupby=groupby, query=query))
File /usr/Zope-2.2.0b2-solaris-2.6-sparc/lib/python/OFS/DTMLMethod.py,
line 189, in validate
(Object: list_courses)
File
/usr/Zope-2.2.0b2-solaris-2.6-sparc/lib/python/AccessControl/SecurityManager
.py, line 139, in validate
File
/usr/Zope-2.2.0b2-solaris-2.6-sparc/lib/python/AccessControl/ZopeSecurityPol
icy.py, line 158, in validate
Unauthorized: open_term
Any ideas? Now, it could just be my programming. With the new 2.2 version
I may need to add security information to each object (which I don't know
how to do). Right now I'm just starting with a blank class and adding a few
properties to it. Zope may be looking at it and thinking, "What the heck is
this thing?" The idea was to trick Zope into thinking it was a Z SQL query;
perhaps 2.2 isn't so easily fooled...?
At any rate, we're getting closer... :)
- T.J.
----- Original Message -----
From: Brian Lloyd <Brian@digicool.com>
To: <MannosTJ@slcc.edu>; Brian Lloyd <Brian@digicool.com>; <zope@zope.org>;
<zope-dev@zope.org>
Sent: Wednesday, June 21, 2000 9:25 AM
Subject: [Zope] Please test this Zope 2.2 beta 1 ZSQLMethods fix...
> Hi all,
>
> Several folks have reported problems in beta 1 with SQLMethods
> having authentication problems when trying to call other SQL
> Methods. I'd like a few intrepid volunteers to try something
> for me to see if it fixes the problem. I'd like to make a 2.2
> beta 2 release tomorrow but I want to make sure this issue is
> resolved first.
>
> Make a backup of the file:
>
> lib/python/Shared/DC/ZRDB/DA.py
>
> in your current (beta 1) installation and replace it with the
> DA.py attached to this email, restart and let me know if the
> problem goes away.
>
> Thanks!
>
> Brian Lloyd brian@digicool.com
> Software Engineer 540.371.6909
> Digital Creations http://www.digicool.com
>
>
>
>
>
------=_NextPart_000_0070_01BFDCED.044F50D0
Content-Type: application/octet-stream;
name="courseList.py"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="courseList.py"
""" courseList.py:=0A=
=0A=
This external Zope method allows us to easily group queries visually=0A=
by certain fields. For instance, the course_list method groups=0A=
all E-Campus courses first by semester, they by type, then by=0A=
category.=0A=
=0A=
The courseList method inserts "pseudo-records" into the query that=0A=
tell us when an old group is "closed" and a new group is "open".=0A=
This makes the HTML coding a breeze. Upon seeing an "open" record,=0A=
we can render <TABLE> tags and create headings; when we reach a=0A=
"close" record, we can render the accompanying </TABLE> tags.=0A=
=0A=
The 'groupby' argument specifies a list of field names to group by,=0A=
ordered by priority. The 'query' object must be pre-sorted by the=0A=
fields to group by, in the same order of priority.=0A=
=0A=
Example input from SELECT candy,color FROM candies ORDER BY candy:=0A=
candy color=0A=
----------------------=0A=
Life Savers red=0A=
Life Savers orange=0A=
Life Savers yellow=0A=
Life Savers ...=0A=
M&M's blue=0A=
M&M's brown=0A=
M&M's green=0A=
M&M's ...=0A=
=0A=
Example (formatted) query object output from courseList(query, =
['candy']):=0A=
open-candy: Life Savers=0A=
color: red=0A=
color: orange=0A=
color: yellow=0A=
...=0A=
close-candy: Life Savers=0A=
open-candy: M&M's=0A=
color: blue=0A=
color: brown=0A=
color: green=0A=
...=0A=
close-candy: M&M's=0A=
=0A=
(Note: if more groupby fields had been entered, open and close tags=0A=
would be nested)=0A=
=0A=
For the best example of this method at work, see course_list =0A=
"""=0A=
=0A=
class SimpleClass:=0A=
pass=0A=
=0A=
def courseList(self, query, groupby):=0A=
""" Augments the given query object with pseudo-records that indicate=0A=
when a group has been opened or closed. Given query object must be=0A=
pre-sorted by the specified groupby list items """=0A=
=0A=
# Set default to '' for each group. This will be the "remembered" value=0A=
mem=3D[]=0A=
for i in groupby:=0A=
mem.append('')=0A=
=0A=
list=3D[]=0A=
stack=3D[]=0A=
=0A=
for i in query:=0A=
# For each group-by field, if a new group begins,=0A=
# pop the old group off the stack and add the=0A=
# appropriate closing tags to the list.=0A=
for x in range(len(groupby)):=0A=
if i[groupby[x]] !=3D mem[x]:=0A=
# Pop old group (and subgroups) off the stack=0A=
popper(i, stack, list, groupby, x)=0A=
# Push new group on the stack=0A=
pusher(i, stack, list, groupby)=0A=
=0A=
# Set "memory" to reflect current group=0A=
# and erase all "memories" beneath this group=0A=
mem[x] =3D i[groupby[x]]=0A=
for y in range(x+1,len(groupby)):=0A=
mem[y]=3D''=0A=
=0A=
# Append the course record to the list.=0A=
list.append(i)=0A=
=0A=
# Insert the rest of the closing tags=0A=
# and bring the stack down to level 0.=0A=
popper(i, stack, list, groupby, 0)=0A=
=0A=
return list=0A=
=0A=
def popper(i, stack, list, groupby, level):=0A=
""" Pops groups off the stack until reacing 'level' """=0A=
# Bring the stack down beneath the level of the new group=0A=
while len(stack) > level:=0A=
val =3D stack.pop()=0A=
# Insert a "close" definition, ie. {close_term: 'Summer 2000'}=0A=
c =3D SimpleClass()=0A=
setattr(c, 'close_'+groupby[len(stack)], val)=0A=
list.append(c)=0A=
=0A=
def pusher(i, stack, list, groupby):=0A=
""" Pushes a new group onto the stack """=0A=
# Insert an "open" definition, i.e. {open_type: 'Internet Courses'}=0A=
c =3D SimpleClass()=0A=
setattr(c, 'open_'+groupby[len(stack)], i[groupby[len(stack)]])=0A=
list.append(c);=0A=
=0A=
# Push the new group onto the stack.=0A=
stack.append(i[groupby[len(stack)]])=0A=
------=_NextPart_000_0070_01BFDCED.044F50D0--