CPSDocumentPatch.py 3.59 KB
Newer Older
Sebastien Robin's avatar
Sebastien Robin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
# (C) Copyright 2004 Nexedi SARL <http://nexedi.com>
# Authors: Sebastien Robin <seb@nexedi.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as published
# by the Free Software Foundation.
#
# 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.
#

from Products.CPSDocument.CPSDocument import CPSDocument
from Products.CPSSchemas.BasicFields import CPSImageField, CPSFileField, CPSDateTimeField
21
from Products.CPSSchemas.BasicFields import CPSStringField
Sebastien Robin's avatar
Sebastien Robin committed
22
from Products.ERP5Type.Base import Base
23 24 25 26
from Products.ERP5Type.Utils import UpperCase
from Acquisition import aq_base, aq_inner
from AccessControl import ClassSecurityInfo
from Products.CMFCore.CMFCorePermissions import View
Sebastien Robin's avatar
Sebastien Robin committed
27 28 29

class PatchedCPSDocument(CPSDocument):

30
  security = ClassSecurityInfo()
Sebastien Robin's avatar
Sebastien Robin committed
31

32 33 34 35 36 37 38 39
  def _propertyMap(self):
    """
      Returns fake property sheet
    """
    property_sheet = []
    for schema in self.getTypeInfo().getSchemas():
      for field in schema.objectValues():
        #LOG('testjp',0,'field: %s' % str(field))
40
        f_type = None
41 42 43 44 45
        for p in field._properties:
          if p['id'] == 'default':
            f_type = p['type']
        if isinstance(field,CPSImageField):
          f_type = 'object'
46 47 48
        elif isinstance(field,CPSStringField):
          f_type = 'string'
        elif isinstance(field,CPSDateTimeField):
49
          f_type = 'date'
50
        elif isinstance(field,CPSFileField):
51
          f_type = 'object'
52 53
        elif isinstance(field,CPSDocument):
          pass
54
        prop_id = schema.getIdUnprefixed(field.id)
55 56 57
        #if prop_id in ('file_text','content','attachedFile',
        #                      'attachedFile_html','attachedFile_text', 'content'):
        #  f_type = 'object' # this should be string, but this strings
58 59
                            # do so bad xml
        #if not (prop_id in ('file_text','content','attachedFile','attachedFile_html','attachedFile_text')):
60 61
        #if not (prop_id in ('content',)):
        if f_type is not None:
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
          property_sheet.append(
            {
              'id'    :   prop_id,
              'type'  :   f_type
            }
            )
    return tuple(property_sheet + list(getattr(self, '_local_properties', ())))


  security.declareProtected( View, 'getProperty' )
  def getProperty(self, key, d=None):
    """
      Previous Name: getValue

      Generic accessor. Calls the real accessor
    """
    accessor_name = 'get' + UpperCase(key)
    aq_self = aq_base(self)
    if hasattr(aq_self, accessor_name):
      method = getattr(self, accessor_name)
      return method()
    prop_type = self.getPropertyType(key) # XXX added by Seb
    if prop_type in ('object',):
      if hasattr(aq_self, key):
        value = getattr(aq_self, key)
        value = aq_base(value)
        return value
      return None
    elif hasattr(aq_self, key):
      value = getattr(aq_self, key)
      if callable(value): value = value()
      return value

CPSDocument.getProperty = PatchedCPSDocument.getProperty
Sebastien Robin's avatar
Sebastien Robin committed
96 97
CPSDocument._propertyMap = PatchedCPSDocument._propertyMap
CPSDocument.setProperty = Base.setProperty
98
CPSDocument._setProperty = Base._setProperty
99
CPSDocument.asXML = Base.asXML
100
CPSDocument._edit = Base._edit