nuxeo-checkins
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nuxeo-checkins] CVS: NuxForum Custom.py,NONE,1.1 Forum.py,1.2,1.3


From: Juan David Ibáñez Palomar
Subject: [Nuxeo-checkins] CVS: NuxForum Custom.py,NONE,1.1 Forum.py,1.2,1.3
Date: Fri, 03 May 2002 05:41:37 -0400

Update of /cvsroot/nuxeo/NuxForum
In directory subversions:/tmp/cvs-serv29412

Modified Files:
        Forum.py 
Added Files:
        Custom.py 
Log Message:
New mechanism that allows to override something that lives in
the filesystem with something that is acquired.


--- NEW FILE ---
# Copyright (c) 2002 J. David Ibáñez
#               2002 Nuxeo
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
# MA 02111-1307 USA

"""
This class defines an object that can be customized from the Zope through
aquisition.
"""


from Globals import get_request
from ExtensionClass import Base
from Acquisition import aq_acquire, aq_base


class Customizable:
    def __bobo_traverse__(self, REQUEST, name):
        self._v_root = self.getPhysicalRoot()
        self._v_path = self.getPhysicalPath()
        return getattr(self, name)


class Custom(Base):
    """ """
    def __init__(self, default, custom):
        self.default = default
        self.custom = custom

    def __of__(self, parent):
##        request = get_request()
##        path = request['PATH_INFO'].split('/')

##        custom = None
##        ob = parent._v_root
##        for x in path[1:-1]:
##            if hasattr(ob, self.custom):
##                custom = getattr(ob, self.custom)
##            ob = getattr(ob, x)

##        return custom or getattr(parent, self.default)


        ob = parent._v_root
        for x in parent._v_path[1:]:
            ob = getattr(ob, x).__of__(ob)

        try:
            custom = aq_acquire(ob, self.custom)
        except AttributeError:
            return getattr(parent, self.default)
        else:
            return aq_base(custom)

Index: Forum.py
===================================================================
RCS file: /cvsroot/nuxeo/NuxForum/Forum.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** Forum.py    29 Apr 2002 13:41:25 -0000      1.2
--- Forum.py    3 May 2002 09:41:35 -0000       1.3
***************
*** 33,40 ****
--- 33,42 ----
  
  # Modules from this product
+ from Custom import Customizable, Custom
  from Article import Article
  from Node import Node
  
  
+ 
  manage_addForumForm = LocalDTMLFile('ui/Forum_add', globals())
  def manage_addForum(self, id, title, REQUEST=None):
***************
*** 47,51 ****
  
  
! class Forum(Node):
      meta_type = 'Forum'
  
--- 49,55 ----
  
  
! class Forum(Customizable, Node):
!     """ """
! 
      meta_type = 'Forum'
  
***************
*** 94,98 ****
      # Index
      security.declareProtected('View', 'index_html')
!     index_html = LocalPageTemplateFile('ui/Forum_index', globals())
  
      # Get subjects and articles
--- 98,103 ----
      # Index
      security.declareProtected('View', 'index_html')
!     index_html_default = LocalPageTemplateFile('ui/Forum_index', globals())
!     index_html = Custom('index_html_default', 'forum_index')
  
      # Get subjects and articles




reply via email to

[Prev in Thread] Current Thread [Next in Thread]