Package Products :: Package ZenRelations :: Module ToManyRelationshipBase |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenRelations.ToManyRelationshipBase

      1  ###########################################################################
      2  #
      3  # This program is part of Zenoss Core, an open source monitoring platform.
      4  # Copyright (C) 2007, Zenoss Inc.
      5  #
      6  # This program is free software; you can redistribute it and/or modify it
      7  # under the terms of the GNU General Public License version 2 or (at your
      8  # option) any later version as published by the Free Software Foundation.
      9  #
     10  # For complete information please visit: http://www.zenoss.com/oss/
     11  #
     12  ###########################################################################
     13
     14
     15  __doc__ = """ToManyRelationshipBase
     16  Base class for 1:n relations
     17  """
     18  import logging
     19  log = logging.getLogger('zen.ToManyRelationshipBase')
     20
     21  # Base classes for ToManyRelationshipBase
     22  #from PrimaryPathObjectManager import PrimaryPathObjectManager
     23  from RelationshipBase import RelationshipBase
     24  from RelCopySupport import RelCopyContainer
     25
     26  from Globals import DTMLFile
     27  from AccessControl import ClassSecurityInfo
     28  from Globals import InitializeClass
     29  from App.Management import Tabs
     30
     31  from Products.ZenRelations.Exceptions import zenmarker
     32  from Products.ZenUtils.Utils import unused
     33
     34 -class ToManyRelationshipBase(
     35              RelCopyContainer,
     36              RelationshipBase
     37              ):
     38      """
     39      Abstract base class for all ToMany relationships.
     40      """
     41
     42      manage_options = (
     43          {
     44          'action': 'manage_main',
     45          'help': ('OFSP', 'ObjectManager_Contents.stx'),
     46          'label': 'Contents'},
     47      )
     48
     49      security = ClassSecurityInfo()
     50
     51      manage_main = DTMLFile('dtml/ToManyRelationshipMain',globals())
     52
     53      _operation = -1 # if a Relationship's are only deleted
     54
     55      _count = None
     56
     57 -    def setCount(self):
     58          self._count = len(self._objects)
     59          # persist the changes if we are on the object graph
     60          try:
     61              parent = self.__primary_parent__
     62              parent._p_changed = True
     63          except AttributeError:
     64              log.debug("Unable to persist the count of %s" % self.id)
     65
     66 -    def countObjects(self):
     67          """Return the number of objects in this relationship"""
     68          if self._count is None:
     69              self.setCount()
     70          return self._count
     71
     72
     73 -    def findObjectsById(self, partid):
     74          """Return a list of objects by running find on their id"""
     75          objects = []
     76          for id, obj in self.objectItemsAll():
     77              if id.find(partid) > -1:
     78                  objects.append(obj)
     79          return objects
     80
     81
     82 -    def _delObject(self, id, dp=1, suppress_events=False):
     83          """Emulate ObjectManager deletetion."""
     84          unused(dp)
     85          obj = self._getOb(id, False)
     86          if not obj:
     87              log.warning(
     88              "Tried to delete object id '%s' but didn't find it on %s",
     89              id, self.getPrimaryId())
     90              return
     91          self.removeRelation(obj, suppress_events)
     92          obj.__primary_parent__ = None
     93
     94
     95 -    def _setOb(self, id, obj):
     96          """don't use attributes in relations"""
     97          unused(id)
     98          unused(obj)
     99          if True:
    100              raise NotImplementedError
    101
    102
    103 -    def _delOb(self, id):
    104          """don't use attributes in relations"""
    105          if True:
    106              raise NotImplementedError
    107
    108
    109 -    def _getOb(self, id, default=zenmarker):
    110          """
    111          Return object by id if it exists on this relationship.
    112          If it doesn't exist return default or if default is not set
    113          raise AttributeError
    114          """
    115          unused(default)
    116          if True:
    117              raise NotImplementedError
    118
    119
    120 -    def manage_workspace(self, REQUEST):
    121          """if this has been called on us return our workspace
    122          if not redirect to the workspace of a related object"""
    123          id = REQUEST['URL'].split('/')[-2]
    124          if id == self.id:
    125              Tabs.manage_workspace(self, REQUEST)
    126          else:
    127              obj = self._getOb(self, id)
    128              from zExceptions import Redirect
    129              raise Redirect( (obj.getPrimaryUrlPath()+'/manage_workspace') )
    130
    131
    132  InitializeClass(ToManyRelationshipBase)
    133