Submitted by : simon at: 2003-10-26T21:32:36+00:00 (14 years ago)
Name :
Category : Severity : Status :
Optional subject :  
Optional comment :

From current CVS version:

"backlinksFor" returns a list of CatalogBrains? if a Catalog is used for searching, otherwise a list of Page-Objects gets returned.

The functions that call backlinksFor always expect brain-like objects to be returned and will fail if a list of objects gets returned.

Patches:

  Return list of brain-like objects and fix PageBrain class::

    Index: ZWikiPage.py
    ===================================================================
    RCS file: /cvsroot/zwiki/zwiki/ZWikiPage.py,v
    retrieving revision 0.453
    diff -c -r0.453 ZWikiPage.py
    *** ZWikiPage.py        4 Sep 2003 05:53:04 -0000       0.453
    --- ZWikiPage.py        10 Sep 2003 12:51:01 -0000
    ***************
    *** 33,38 ****
    --- 33,39 ----
      from OFS.DTMLDocument import DTMLDocument
      from OFS.ObjectManager import BadRequestException
      import OFS.Image
    + from OFS.SimpleItem import SimpleItem
      #import Products.ZCatalog
      #from Products.ZCatalog.CatalogBrains import AbstractCatalogBrain
      from WWML import translate_WMML
    ***************
    *** 1043,1051 ****
              Optimisation: like pages(), this method used to return actual page
              objects but now returns metadata objects (catalog results if possible,
              or workalikes) to improve caching.
    -         XXX if we can't return catalog results, return page objects as before.
    -         I want to return work-a-like PageBrains here for consistency, but
    -         TAL in plone just won't access them.

              page may be a name or id, and need not exist in the wiki

    --- 1044,1049 ----
    ***************
    *** 1066,1073 ****
                  linkpat = re.compile(r'\b(%s|%s)\b'%(page,id))
                  for p in self.pageObjects():
                      if linkpat.search(p.read()):
    !                     #results.append(self.metadataFor(p))
    !                     results.append(p)
                  return results

          ######################################################################
    --- 1064,1071 ----
                  linkpat = re.compile(r'\b(%s|%s)\b'%(page,id))
                  for p in self.pageObjects():
                      if linkpat.search(p.read()):
    !                     results.append(self.metadataFor(p))
    !                     #results.append(p)
                  return results

          ######################################################################
    ***************
    *** 1994,2007 ****

              To be used as a substitute when there is no catalog.
              """
    !         class PageBrain:
    !             # XXX in plone, TAL complains it's unauthorized to access the
    !             # brains' attributes, no matter what we do
    !             #security = ClassSecurityInfo()
    !             #security.declareObjectProtected('View') # no good
                  def __init__(self,obj): self._obj = obj
                  def getObject(self): return self._obj
    -             def __getitem__(self,attr): return getattr(self,attr)
              b = PageBrain(page)
              for attr in [
                  'id',
    --- 1992,2000 ----

              To be used as a substitute when there is no catalog.
              """
    !         class PageBrain(SimpleItem):
                  def __init__(self,obj): self._obj = obj
                  def getObject(self): return self._obj
              b = PageBrain(page)
              for attr in [
                  'id',

  Fix backlinks templates (Part I)::

    Index: skins/default/backlinks.pt
    ===================================================================
    RCS file: /cvsroot/zwiki/zwiki/skins/default/backlinks.pt,v
    retrieving revision 1.9
    diff -c -r1.9 backlinks.pt
    *** skins/default/backlinks.pt  2 Sep 2003 20:07:24 -0000       1.9
    --- skins/default/backlinks.pt  10 Sep 2003 12:51:13 -0000
    ***************
    *** 53,59 ****
      sorted_backlinks python:sequence.sort(backlinks,
                                            (('Title', 'nocase', 'asc'),));
      ">
    ! <li tal:repeat="bl sorted_backlinks">
      <span tal:omit-tag="" tal:define="
      blpage bl/Title;
      blisparent python:(blpage in thisparents) #and zwiki_showhierarchy;
    --- 53,60 ----
      sorted_backlinks python:sequence.sort(backlinks,
                                            (('Title', 'nocase', 'asc'),));
      ">
    ! <tal:block tal:repeat="backlink sorted_backlinks">
    ! <li tal:define="bl backlink/getObject">
      <span tal:omit-tag="" tal:define="
      blpage bl/Title;
      blisparent python:(blpage in thisparents) #and zwiki_showhierarchy;
    ***************
    *** 71,76 ****
    --- 72,78 ----
      <br />
      </span>
      </li>
    + </tal:block>
      </ol>

      <p tal:condition="zwiki_showhierarchy">

  Fix backlinks templates (Part II)::

    Index: skins/zwiki_plone/backlinks.pt
    ===================================================================
    RCS file: /cvsroot/zwiki/zwiki/skins/zwiki_plone/backlinks.pt,v
    retrieving revision 1.5
    diff -c -r1.5 backlinks.pt
    *** skins/zwiki_plone/backlinks.pt      2 Sep 2003 20:07:23 -0000       1.5
    --- skins/zwiki_plone/backlinks.pt      10 Sep 2003 12:51:13 -0000
    ***************
    *** 36,42 ****
                                                (('Title', 'nocase', 'asc'),));
                         ">

    !         <li tal:repeat="bl sorted_backlinks">
              <tal:block define="
                                 blpage bl/Title;
                                 blisparent python:(blpage in thisparents) #and zwiki_showhierarchy;
    --- 36,43 ----
                                                (('Title', 'nocase', 'asc'),));
                         ">

    !         <tal:block tal:repeat="backlink sorted_backlinks">
    !         <li tal:define="bl backlink/getObject">
              <tal:block define="
                                 blpage bl/Title;
                                 blisparent python:(blpage in thisparents) #and zwiki_showhierarchy;
    ***************
    *** 59,64 ****
    --- 60,66 ----

              </tal:block>
              </li>
    +         </tal:block>
          </ol>

          <p tal:condition="zwiki_showhierarchy">


comments:

(new) --Simon Michael, Wed, 10 Sep 2003 11:26:42 -0700 reply
Magog wrote:

"backlinksFor" returns a list of CatalogBrains? if a Catalog is used for searching, otherwise a list of Page-Objects gets returned.

The functions that call backlinksFor always expect brain-like objects to be returned and will fail if a list of objects gets returned.

Aieee! Not even released and this has been spotted..

You are quite right - only, which functions do you have in mind ? I made the default backlinks template handle either. But yes,:

        The backlinksFor method now returns catalog brains (results) if
        possible, otherwise page objects as before. This means you'll need
        a new backlinks template for this release - if you have a
        customized backlinks template lying around you'll probably need to
        update or remove it.

which is ugly and inconsistent with:

        The pages method now returns catalog brains if possible, otherwise
        brain-like objects.

The problem was, returning brain-like objects (see metadataFor()) gave authentication problems for the backlinks template in CMF/Plone that I couldn't understand.

I would love someone to solve this, so that these methods can always return brain-like objects. In fact I'll make a GoldOffer of $10!

part 2: backwards compatibility --Simon Michael, Wed, 10 Sep 2003 12:24:02 -0700 reply
The second problem is that "old customized backlinks templates will need to be upgraded". In fact looking at it now I can't see why they shouldn't keep working, if the page brains include page_url and linkTitle attributes. I've added these to PageBrain? objects in the trunk.

So now, if we get past the authentication problem previously mentioned and return PageBrains? when there is no catalog, custom backlinks templates will not need to be upgraded in that case. When there is a catalog, eg in plone sites, custom backlinks templates will still need to be upgraded, or the catalog will need to have page_url and linkTitle added to it's metadata.

So it's more likely to be backwards compatible, but still not guaranteed. This tweak will go into 0.23 unless we find a fix for part 1 today.

part 1: brain authentication problem --SimonMichael, Wed, 10 Sep 2003 12:57:11 -0700 reply
And now I remember, you posted a patch (didn't see it at first). Which looks like it actually solves the problem (surprise! :). Let me try.

part 1: brain authentication problem --SimonMichael, Wed, 10 Sep 2003 13:54:15 -0700 reply
Super! Let me know your paypal address so I can send the $10 :)

Instead of your backlinks.pt patches it's now:

                tal:define="blid bl/id"
                tal:attributes="href python:here.wiki_url()+'/'+blid;
                                title bl/linkTitle|nothing;"

as the whole point of this is to avoid touching the actual page objects if possible, to improve caching - while working with every possible CMF/non-CMF and catalog configuration, and if possible being fully backward compatible with legacy backlinks templates. Which I think we've achieved - thanks!

fixed for 0.22 --SimonMichael, Wed, 10 Sep 2003 13:55:17 -0700 reply
Severity: critical => normal Status: open => closed

part 1: brain authentication problem --SimonMichael, Wed, 10 Sep 2003 14:05:33 -0700 reply

Which I think we've achieved

Except for only this case: when there is a catalog with meta_type, path, and canonicalLinks indexes but without page_url and linkTitle metadata (unlikely).

(new) --Magog, Thu, 11 Sep 2003 00:42:08 -0700 reply
The methods I meant - Ups, just noticed it's only one :) - is "rename", where on each item in self.backlinksFor() "getObject" gets called.

(new) --Simon Michael, Thu, 11 Sep 2003 00:54:28 -0700 reply
Ha, that explains why I saw a couple of attribute errors there.

(new) --Magog, Thu, 11 Sep 2003 01:54:53 -0700 reply
:)

spambots messed this up --betabug, Wed, 14 Feb 2007 01:03:19 -0800 reply
Name: #604 christie => #604 backlinksFor and CatalogBrains/Objects mixup Status: open => closed