Beispiel #1
0
class SetSetter(BaseSetter):
    """
      Sets a category value through a provided value (List mode)
    """
    _need__name__ = 1

    # This can not be called from the Web

    def __init__(self, id, key, warning=0):
        self._id = id
        self.__name__ = id
        self._key = key
        self._warning = warning

    def __call__(self, instance, value, *args, **kw):
        if self._warning:
            LOG("ERP5Type Deprecated Setter Id:", 0, self._id)
        value = tuple(OrderedDict.fromkeys(value))
        instance._setValue(self._key,
                           value,
                           spec=kw.get('spec', ()),
                           filter=kw.get('filter', None),
                           portal_type=kw.get('portal_type', ()),
                           keep_default=1,
                           checked_permission=kw.get('checked_permission',
                                                     None))
        return (instance, )

    psyco.bind(__call__)
Beispiel #2
0
class ValueListGetter(Base.Getter):
    """
      Gets an attribute value. A default value can be
      provided if needed
    """
    _need__name__=1

    # Generic Definition of Method Object
    # This is required to call the method form the Web
    func_code = func_code()
    func_code.co_varnames = ('self',)
    func_code.co_argcount = 1
    func_defaults = ()

    def __init__(self, id, key, property_type, portal_type=None, storage_id=None, default=None):
      self._id = id
      self.__name__ = id
      self._key = key
      self._property_type = property_type
      self._null = type_definition[property_type]['null']
      self._default = default
      if storage_id is None:
        storage_id = "%s%s" % (ATTRIBUTE_PREFIX, key)
      elif type(storage_id) is not type([]):
        storage_id = [storage_id]
      self._storage_id = storage_id
      self._portal_type = portal_type

    def __call__(self, instance, *args, **kw):
      # We return the list of matching objects
      return instance.contentValues(filter = {'portal_type': self._portal_type,
                                              'id' : self._storage_id})

    psyco.bind(__call__)
Beispiel #3
0
class DefaultGetter(BaseGetter):
    """
      Gets a default reference object
    """
    _need__name__ = 1

    # Generic Definition of Method Object
    # This is required to call the method form the Web
    func_code = func_code()
    func_code.co_varnames = ('self', 'args', 'kw')
    func_code.co_argcount = 1
    func_defaults = ()

    def __init__(self, id, key, warning=0):
        self._id = id
        self.__name__ = id
        self._key = key
        self._warning = warning

    def __call__(self, instance, *args, **kw):
        if self._warning:
            LOG("ERP5Type Deprecated Getter Id:", 0, self._id)
        return instance._getDefaultAcquiredValue(self._key, **kw)

    psyco.bind(__call__)
Beispiel #4
0
class ItemListGetter(BaseGetter):
    """
      Gets a category value list
    """
    _need__name__ = 1

    # Generic Definition of Method Object
    # This is required to call the method form the Web
    func_code = func_code()
    func_code.co_varnames = (
        'self',
        'args',
        'kw',
    )
    func_code.co_argcount = 1
    func_defaults = ()

    def __init__(self, id, key):
        self._id = id
        self.__name__ = id
        self._key = key

    def __call__(self, instance, *args, **kw):
        return instance._getAcquiredCategoryMembershipItemList(self._key,
                                                               base=0,
                                                               **kw)

    psyco.bind(__call__)
Beispiel #5
0
class ListGetter(BaseGetter):
    """
  Gets a list of reference objects
  """
    _need__name__ = 1

    # Generic Definition of Method Object
    # This is required to call the method form the Web
    func_code = func_code()
    func_code.co_varnames = ('self', )
    func_code.co_argcount = 1
    func_defaults = ()

    def __init__(self, id, key, warning=0):
        self._id = id
        self.__name__ = id
        self._key = key
        self._warning = warning

    def __call__(self, instance, *args, **kw):
        if self._warning:
            LOG("ERP5Type", WARNING, "Deprecated Getter Id: %s" % self._id)
        assert not 'validation_state' in kw, "validation_state parameter is not supported"
        assert not 'simulation_state' in kw, "simulation_state parameter is not supported"
        return instance._getRelatedPropertyList(
            self._key,
            'relative_url',
            spec=kw.get('spec', ()),
            filter=kw.get('filter', None),
            portal_type=kw.get('portal_type', ()),
            checked_permission=kw.get('checked_permission', None))

    psyco.bind(__call__)
Beispiel #6
0
class ListGetter(BaseGetter):
    """
      Gets a list of reference objects
    """
    _need__name__ = 1

    # Generic Definition of Method Object
    # This is required to call the method form the Web
    # XXX This does not work yet completely in URL mode
    func_code = func_code()
    func_code.co_varnames = ('self', 'args', 'kw')
    func_code.co_argcount = 1
    func_defaults = ()

    def __init__(self, id, key, warning=0):
        self._id = id
        self.__name__ = id
        self._key = key
        self._warning = warning

    def __call__(self, instance, *args, **kw):
        if self._warning:
            LOG("ERP5Type Deprecated Getter Id:", 0, self._id)
        if args:
            kw['default'] = args[0]
        return instance.getAcquiredValueList(self._key, **kw)

    psyco.bind(__call__)
Beispiel #7
0
class DefaultGetter(BaseGetter):
    """
      Gets a default category value
    """
    _need__name__ = 1

    # Generic Definition of Method Object
    # This is required to call the method form the Web
    func_code = func_code()
    func_code.co_varnames = ('self', )
    func_code.co_argcount = 1
    func_defaults = ()

    def __init__(self, id, key):
        self._id = id
        self.__name__ = id
        self._key = key

    def __call__(self, instance, *args, **kw):
        if len(args) > 0:
            default = args[0]
            kw['default'] = default
        else:
            default = None
        return instance._getDefaultAcquiredCategoryMembership(self._key, **kw)

    psyco.bind(__call__)
Beispiel #8
0
class ListGetter(BaseGetter):
    """
  Gets a list of reference objects
  """
    _need__name__ = 1

    # Generic Definition of Method Object
    # This is required to call the method form the Web
    func_code = func_code()
    func_code.co_varnames = ('self', )
    func_code.co_argcount = 1
    func_defaults = ()

    def __init__(self, id, key, warning=0):
        """
    'warning' argument means that this category is deprecated in the
    property sheet, so the generated method will also be deprecated
    """
        self._id = id
        self.__name__ = id
        self._key = key
        self._warning = warning

    def __call__(self, instance, *args, **kw):
        assert not 'validation_state' in kw, "validation_state parameter is not supported"
        assert not 'simulation_state' in kw, "simulation_state parameter is not supported"
        if self._warning:
            LOG("ERP5Type", WARNING, "Deprecated Getter Id: %s" % self._id)
        return instance._getRelatedValueList(self._key, *args, **kw)

    psyco.bind(__call__)
Beispiel #9
0
class IdListGetter(ListGetter):
    def __call__(self, instance, *args, **kw):
        return [
            x.getId() for x in ListGetter.__call__(self, instance, *args, **kw)
        ]

    psyco.bind(__call__)
Beispiel #10
0
class ListGetter(BaseGetter):
    """
    Get all 'key' properties from Workflow History Transitions. A
    default value can be provided if needed.
    """
    def __init__(self, id, workflow_id, transition_id, key):
        self._id = id
        self.__name__ = id
        self._workflow_id = workflow_id
        self._transition_id = transition_id
        self._key = key

    def __call__(self, instance, *args):
        try:
            default = args[0]
        except IndexError:
            default = []

        instance = aq_base(instance)
        try:
            workflow_history_dict_list = instance.workflow_history[
                self._workflow_id]
        except (AttributeError, KeyError):
            return default
        else:
            result_list = []
            for workflow_history_dict in workflow_history_dict_list:
                if workflow_history_dict['action'] == self._transition_id:
                    result_list.append(
                        workflow_history_dict.get(self._key, default))

            return result_list if result_list else default

    psyco.bind(__call__)
Beispiel #11
0
class Getter(BaseGetter):
    """
      Gets an attribute value. A default value can be
      provided if needed
    """
    _need__name__ = 1

    # Generic Definition of Method Object
    # This is required to call the method form the Web
    func_code = func_code()
    func_code.co_varnames = ('self', )
    func_code.co_argcount = 1
    func_defaults = ()

    def __init__(self, id, key):
        self._id = id
        self.__name__ = id
        self._key = key

    def __call__(self, instance):
        portal_workflow = instance.getPortalObject().portal_workflow
        wf = portal_workflow.getWorkflowById(self._key)
        return wf._getWorkflowStateOf(instance, id_only=1)

    psyco.bind(__call__)
Beispiel #12
0
class DefaultTitleOrIdGetter(DefaultGetter):
    def __call__(self, instance, *args, **kw):
        o = DefaultGetter.__call__(self, instance, *args, **kw)
        if o is None:
            return None
        return o.getTitleOrId()

    psyco.bind(__call__)
Beispiel #13
0
class DefaultPropertyGetter(DefaultGetter):
    def __call__(self, instance, key, *args, **kw):
        o = DefaultGetter.__call__(self, instance, **kw)
        if o is None:
            return args[0] if args else None
        return o.getProperty(key)

    psyco.bind(__call__)
Beispiel #14
0
class PropertyListGetter(ListGetter):
    def __call__(self, instance, key, *args, **kw):
        return [
            x.getProperty(key)
            for x in ListGetter.__call__(self, instance, *args, **kw)
        ]

    psyco.bind(__call__)
Beispiel #15
0
class TranslatedTitleListGetter(ListGetter):
    def __call__(self, instance, *args, **kw):
        return [
            x.getTranslatedTitle()
            for x in ListGetter.__call__(self, instance, *args, **kw)
        ]

    psyco.bind(__call__)
Beispiel #16
0
class PropertyTranslationDomainGetter(BaseGetter):
    """
  Get the translation domain
  """
    _need__name__ = 1

    # This can be called from the Web
    func_code = func_code()
    func_code.co_varnames = ('self', )
    func_code.co_argcount = 1
    func_defaults = ()

    def __init__(self, id, key, property_type, default=None, storage_id=None):
        self._id = id
        self.__name__ = id
        self._original_key = key.replace('_translation_domain', '')
        self._default = default
        if storage_id is None:
            storage_id = "%s%s" % (ATTRIBUTE_PREFIX, key)
        self._storage_id = storage_id
        self._is_tales_type = (property_type == 'tales')

    def __call__(self, instance, *args, **kw):
        if len(args) > 0:
            default = args[0]
        else:
            default = self._default
        # No acquisition on properties
        value = getattr(aq_base(instance), self._storage_id, None)
        if value is None:
            # second try to get it from portal type
            ptype_domain = None
            ptype = instance.getPortalType()
            ptypes_tool = instance.getPortalObject()['portal_types']
            typeinfo = ptypes_tool.getTypeInfo(ptype)
            if typeinfo is None:
                ptype_domain = ''
            else:
                domain_dict = typeinfo.getPropertyTranslationDomainDict()
                domain = domain_dict.get(self._original_key)
                if domain is None:
                    ptype_domain = ''
                else:
                    ptype_domain = domain.getDomainName()
            if ptype_domain is '' and default is not None:
                # then get the default property defined on property sheet
                value = default
            else:
                value = ptype_domain
        if value is None:
            value = ''
        if self._is_tales_type and kw.get('evaluate', 1):
            return evaluateTales(instance, value)
        else:
            return value

    psyco.bind(__call__)
Beispiel #17
0
class ValueGetter(Base.Getter):
    """
      Gets an attribute value. A default value can be
      provided if needed
    """
    _need__name__ = 1

    # Generic Definition of Method Object
    # This is required to call the method form the Web
    func_code = func_code()
    func_code.co_varnames = ('self', )
    func_code.co_argcount = 1
    func_defaults = ()

    def __init__(self,
                 id,
                 key,
                 property_type,
                 portal_type=None,
                 storage_id=None,
                 default=None):
        self._id = id
        self.__name__ = id
        self._key = key
        self._property_type = property_type
        self._null = type_definition[property_type]['null']
        self._default = default
        if storage_id is None:
            storage_id = "%s%s" % (ATTRIBUTE_PREFIX, key)
        elif type(storage_id) not in (type([]), type(())):
            storage_id = [storage_id]
        self._storage_id = storage_id
        if type(portal_type) is type('a'):
            portal_type = (portal_type, )
        self._portal_type = portal_type

    def __call__(self, instance, *args, **kw):
        # We return the first available object in the list
        if len(args) > 0:
            default_result = args[0]
        else:
            default_result = self._default
        o = None
        #LOG('ValueGetter.__call__, default',0,self._default)
        #LOG('ValueGetter.__call__, storage_id_list',0,self._storage_id_list)
        #LOG('ValueGetter.__call__, portal_type',0,self._portal_type)
        for k in self._storage_id:
            o = getattr(instance, k, None)
            #LOG('ValueGetter.__call__, o',0,o)
            if o is not None and (o.portal_type is None
                                  or o.portal_type in self._portal_type):
                #LOG('ValueGetter.__call__, o will be returned...',0,'ok')
                return o
        return default_result

    psyco.bind(__call__)
Beispiel #18
0
class DefaultLogicalPathGetter(DefaultGetter):
    _item_method = 'getTitle'

    def __call__(self, instance, *args, **kw):
        o = DefaultGetter.__call__(self, instance, *args, **kw)
        if o is None:
            return None
        return o.getLogicalPath(item_method=self._item_method)

    psyco.bind(__call__)
Beispiel #19
0
def defMethodGetter(key, method=None):
  key = convertToUpperCase(key)
  name = 'Default%sGetter' % key
  if method is None:
    method = methodcaller('get' + key)
  def __call__(self, instance, *args, **kw):
    o = DefaultGetter.__call__(self, instance, **kw)
    if o is None:
      return args[0] if args else None
    return method(o)
  psyco.bind(__call__)
  globals()[name] = type(name, (DefaultGetter,), {'__call__': __call__})

  name = '%sListGetter' % key
  def __call__(self, instance, *args, **kw):
    r = ListGetter.__call__(self, instance, **kw)
    return map(method, r) if r or not args else args[0]
  psyco.bind(__call__)
  globals()[name] = type(name, (ListGetter,), {'__call__': __call__})

  name = '%sSetGetter' % key
  def __call__(self, instance, *args, **kw):
    r = ListGetter.__call__(self, instance, **kw)
    return list({method(x) for x in r}) if r or not args else args[0]
  psyco.bind(__call__)
  globals()[name] = type(name, (ListGetter,), {'__call__': __call__})
Beispiel #20
0
def defMethodGetter(key, method=None):
    key = convertToUpperCase(key)
    name = 'Default%sGetter' % key
    if method is None:
        method = methodcaller('get' + key)

    def __call__(self, instance, *args, **kw):
        o = DefaultGetter.__call__(self, instance, **kw)
        if o is None:
            return args[0] if args else None
        return method(o)

    psyco.bind(__call__)
    globals()[name] = type(name, (DefaultGetter, ), {'__call__': __call__})

    name = '%sListGetter' % key

    def __call__(self, instance, *args, **kw):
        r = ListGetter.__call__(self, instance, **kw)
        return [method(x) for x in r] if r or not args else args[0]

    psyco.bind(__call__)
    globals()[name] = type(name, (ListGetter, ), {'__call__': __call__})

    name = '%sSetGetter' % key

    def __call__(self, instance, *args, **kw):
        r = ListGetter.__call__(self, instance, **kw)
        return list({method(x) for x in r}) if r or not args else args[0]

    psyco.bind(__call__)
    globals()[name] = type(name, (ListGetter, ), {'__call__': __call__})
Beispiel #21
0
class Getter(Base.Getter):
    """
      Gets an attribute value. A default value can be
      provided if needed
    """
    _need__name__ = 1

    # Generic Definition of Method Object
    # This is required to call the method form the Web
    func_code = func_code()
    func_code.co_varnames = ('self', 'args', 'kw')
    func_code.co_argcount = 1
    func_defaults = ()

    def __init__(self,
                 id,
                 key,
                 property_type,
                 acquired_property,
                 portal_type=None,
                 storage_id=None,
                 default=None):
        self._id = id
        self.__name__ = id
        self._key = key
        self._property_type = property_type
        self._null = type_definition[property_type]['null']
        self._default = default
        if storage_id is None:
            storage_id = "%s%s" % (ATTRIBUTE_PREFIX, key)
        elif type(storage_id) is not type([]):
            storage_id = [storage_id]
        self._storage_id_list = storage_id
        if type(portal_type) is type('a'):
            portal_type = (portal_type, )
        self._portal_type = portal_type
        self._acquired_property = acquired_property

    def __call__(self, instance, *args, **kw):
        # We return the first available object in the list
        if len(args) > 0:
            default = args[0]
        else:
            default = None
        o = None
        for k in self._storage_id_list:
            o = getattr(instance, k, None)
            if o is not None and o.portal_type in self._portal_type:
                return o.getProperty(self._acquired_property, default, **kw)
        return default

    psyco.bind(__call__)
Beispiel #22
0
class TranslatedGetter(Getter):
    """ returns the workflow state ID transated. DEPRECATED
    """
    def __call__(self, instance):
        portal = instance.getPortalObject()
        wf = portal.portal_workflow.getWorkflowById(self._key)
        state_id = wf._getWorkflowStateOf(instance, id_only=1)
        warn(
            'Translated workflow state getters, such as %s are deprecated' %
            self._id, DeprecationWarning)
        return portal.Localizer.erp5_ui.gettext(state_id).encode('utf8')

    psyco.bind(__call__)
Beispiel #23
0
class DefaultGetter(Base.Getter):
    """
      Gets the first item of a list
    """
    _need__name__ = 1

    # Generic Definition of Method Object
    # This is required to call the method form the Web
    func_code = func_code()
    func_code.co_varnames = ('self', )
    func_code.co_argcount = 1
    func_defaults = ()

    def __init__(self, id, key, property_type, default=None, storage_id=None):
        self._id = id
        self.__name__ = id
        self._key = key
        self._property_type = property_type
        self._null = type_definition[property_type]['null']
        self._default = default
        if storage_id is None:
            storage_id = "%s%s" % (ATTRIBUTE_PREFIX, key)
        self._storage_id = storage_id
        self._is_tales_type = (property_type == 'tales')

    def __call__(self, instance, *args, **kw):
        if len(args) > 0:
            default = args[0]
        else:
            default = self._default
        list_value = getattr(aq_base(instance), self._storage_id, default)
        if list_value is not None:
            if self._is_tales_type:
                if kw.get('evaluate', 1):
                    list_value = evaluateTales(instance=instance,
                                               value=list_value)
                else:
                    return list_value
            if type(list_value) in (ListType, TupleType):
                if len(list_value) > 0:
                    return list_value[0]
                else:
                    return None
            # This should not happen though
            return list_value
        if default and len(default):
            return default[0]
        return None

    psyco.bind(__call__)
Beispiel #24
0
class DefaultSetter(SetSetter):
    """
      Sets a category value through a provided value (Set mode)
    """
    _need__name__=1

    def __call__(self, instance, *args, **kw):
      if self._warning:
        LOG("ERP5Type Deprecated Setter Id:",0, self._id)
      instance._setDefaultValue(self._key, args[0],
                                                 spec=kw.get('spec',()),
                                                 filter=kw.get('filter', None),
                                                 portal_type=kw.get('portal_type',()),
                                                 checked_permission=kw.get('checked_permission', None))
      return (instance, )

    psyco.bind(__call__)
Beispiel #25
0
class Getter(BaseGetter):
    """
    Get 'key' property from Workflow History latest Transition. A
    default value can be provided if needed.
    """
    def __init__(self, id, list_accessor_name):
        self._id = id
        self.__name__ = id
        self._list_accessor_name = list_accessor_name

    def __call__(self, instance, default=None):
        value_list = getattr(instance, self._list_accessor_name)()
        try:
            return value_list[-1]
        except IndexError:
            return default

    psyco.bind(__call__)
Beispiel #26
0
class ListGetter(Base.Getter):
    """
      Gets an attribute value. A default value can be
      provided if needed
    """
    _need__name__ = 1

    # Generic Definition of Method Object
    # This is required to call the method form the Web
    func_code = func_code()
    func_code.co_varnames = ('self', )
    func_code.co_argcount = 1
    func_defaults = ()

    def __init__(self,
                 id,
                 key,
                 property_type,
                 acquired_property,
                 portal_type=None,
                 storage_id=None):
        self._id = id
        self.__name__ = id
        self._key = key
        self._property_type = property_type
        self._null = type_definition[property_type]['null']
        if storage_id is None:
            storage_id = "%s%s" % (ATTRIBUTE_PREFIX, key)
        elif type(storage_id) is not type([]):
            storage_id = [storage_id]
        self._storage_id_list = storage_id
        self._portal_type = portal_type
        self._acquired_property = acquired_property

    def __call__(self, instance, *args, **kw):
        # We return the list of matching objects
        return [
            o.relative_url
            for o in self.searchFolder(portal_type=self._portal_type,
                                       id=self._storage_id_list)
        ]

    psyco.bind(__call__)
Beispiel #27
0
class TranslatedTitleGetter(TitleGetter):
    """
      Gets the translated title of the current state
    """
    def __call__(self, instance):
        portal = instance.getPortalObject()
        localizer = portal.Localizer
        wf_id = self._key
        wf = portal.portal_workflow.getWorkflowById(wf_id)
        selected_language = localizer.get_selected_language()
        state_title = wf._getWorkflowStateOf(instance).title
        msg_id = '%s [state in %s]' % (state_title, wf_id)
        result = localizer.erp5_ui.gettext(msg_id,
                                           lang=selected_language,
                                           default='')
        if result == '':
            result = localizer.erp5_ui.gettext(state_title,
                                               lang=selected_language)
        return result.encode('utf8')

    psyco.bind(__call__)
Beispiel #28
0
class DefaultGetter(BaseGetter):
    """
  Gets a default reference object
  """
    _need__name__ = 1

    # Generic Definition of Method Object
    # This is required to call the method form the Web
    func_code = func_code()
    func_code.co_varnames = ('self', )
    func_code.co_argcount = 1
    func_defaults = ()

    def __init__(self, id, key, warning=0):
        """
    'warning' argument means that this category is deprecated in the
    property sheet, so the generated method will also be deprecated
    """
        self._id = id
        self.__name__ = id
        self._key = key
        self._warning = warning

    def __call__(self, instance, *args, **kw):
        if self._warning:
            LOG("ERP5Type", WARNING, "Deprecated Getter Id: %s" % self._id)
        assert not 'validation_state' in kw, "validation_state parameter is not supported"
        assert not 'simulation_state' in kw, "simulation_state parameter is not supported"
        return instance._getDefaultRelatedValue(
            self._key,
            spec=kw.get('spec', ()),
            filter=kw.get('filter', None),
            portal_type=kw.get('portal_type', ()),
            strict_membership=kw.get(
                'strict_membership',
                # 'strict' is deprecated
                kw.get('strict', None)),
            checked_permission=kw.get('checked_permission', None))

    psyco.bind(__call__)
Beispiel #29
0
class TitleGetter(BaseGetter):
    """
      Gets the title of the current state
    """
    _need__name__ = 1

    # Generic Definition of Method Object
    # This is required to call the method form the Web
    func_code = func_code()
    func_code.co_varnames = ('self', )
    func_code.co_argcount = 1
    func_defaults = ()

    def __init__(self, id, key):
        self._id = id
        self.__name__ = id
        self._key = key

    def __call__(self, instance):
        portal_workflow = instance.getPortalObject().portal_workflow
        wf = portal_workflow.getWorkflowById(self._key)
        return wf._getWorkflowStateOf(instance).title

    psyco.bind(__call__)
Beispiel #30
0
        if not isinstance(v, (str, unicode)):
            v = str(v)
        if not v and t == 'nb':
            if args.has_key('optional') and args['optional']:
                return 'null'
            else:
                raise ValueError, (
                    'Invalid empty string value for <em>%s</em>' % name)

        v = md.getitem('sql_quote__', 0)(v)
        #if find(v,"\'") >= 0: v=join(split(v,"\'"),"''")
        #v="'%s'" % v

    return v


psyco.bind(SQLVar_render)

# Patched by yo. datetime is added.
valid_type = {
    'int': 1,
    'float': 1,
    'string': 1,
    'nb': 1,
    'datetime': 1
}.has_key

SQLVar.render = SQLVar_render
SQLVar.__call__ = SQLVar_render
sqlvar.valid_type = valid_type
Beispiel #31
0
import PreferenceTool

from Products.Formulator.FieldRegistry import FieldRegistry
from Products.Formulator import StandardFields, HelperFields
from Products.CMFCore.utils import registerIcon


object_classes = ( Form.ERP5Form, FSForm.ERP5FSForm, PDFTemplate.PDFTemplate,
                   Report.ERP5Report, PDFForm.PDFForm)
portal_tools = ( SelectionTool.SelectionTool, PreferenceTool.PreferenceTool )
content_classes = ( )
content_constructors = ()

# Optimization
from Products.ERP5Type.PsycoWrapper import psyco
psyco.bind(ListBox.ListBoxWidget.render)
psyco.bind(ListBox.ListBoxValidator.validate)

# Finish installation
def initialize( context ):
    import Document
    initializeProduct(context, this_module, globals(),
                         document_module = Document,
                         document_classes = document_classes,
                         object_classes = object_classes,
                         portal_tools = portal_tools,
                         content_constructors = content_constructors,
                         content_classes = content_classes)

    # Initialise ERP5Form Formulator
    FieldRegistry.registerField(ProxyField.ProxyField,
Beispiel #32
0
  except KeyError:
    # either returns non callable value (ex. "Title")
    # or a FieldValue instance of appropriate class
    value, cacheable = getFieldValue(self, field, id, **kw)
    # Do not cache if the field is not stored in zodb,
    # because such field must be used for editing field in ZMI
    # and caching sometimes break these field settings at initialization.
    # As the result, we would see broken field editing screen in ZMI.
    if cacheable and self._p_oid:
      field_value_cache[cache_id] = value

  if callable(value):
    return value(field, id, **kw)
  return value

psyco.bind(get_value)

def om_icons(self):
    """Return a list of icon URLs to be displayed by an ObjectManager"""
    icons = ({'path': self.icon,
              'alt': self.meta_type, 'title': self.meta_type},)
    return icons


def _get_default(self, key, value, REQUEST):
    if value is not None:
        return value
    try:
        value = self._get_user_input_value(key, REQUEST)
    except (KeyError, AttributeError):
        # fall back on default
Beispiel #33
0
          raise FormValidationError(error_list, {})
        return result

MatrixBoxValidatorInstance = MatrixBoxValidator()

class MatrixBox(ZMIField):
    meta_type = "MatrixBox"

    widget = MatrixBoxWidgetInstance
    validator = MatrixBoxValidatorInstance

    security = ClassSecurityInfo()

    security.declareProtected('Access contents information', 'get_value')
    def get_value(self, id, **kw):
      if id=='default' and kw.get('render_format') in ('list', ):
        return self.widget.render(self, self.generate_field_key(), None,
                                  kw.get('REQUEST'),
                                  render_format=kw.get('render_format'))
      else:
        return ZMIField.get_value(self, id, **kw)

# Psyco
from Products.ERP5Type.PsycoWrapper import psyco
psyco.bind(MatrixBoxWidget.render)
psyco.bind(MatrixBoxValidator.validate)

# Register get_value
from Products.ERP5Form.ProxyField import registerOriginalGetValueClassAndArgument
registerOriginalGetValueClassAndArgument(MatrixBox, 'default')
Beispiel #34
0
            if args.has_key('optional') and args['optional']:
                return 'null'
            else:
                raise ValueError, (
                    'Invalid string value for <em>%s</em>: %r' % (name, v))
        # End of patch

        if not isinstance(v, (str, unicode)):
            v=str(v)
        if not v and t=='nb':
            if args.has_key('optional') and args['optional']:
                return 'null'
            else:
                raise ValueError, (
                    'Invalid empty string value for <em>%s</em>' % name)

        v=md.getitem('sql_quote__',0)(v)
        #if find(v,"\'") >= 0: v=join(split(v,"\'"),"''")
        #v="'%s'" % v

    return v

psyco.bind(SQLVar_render)

# Patched by yo. datetime is added.
valid_type={'int':1, 'float':1, 'string':1, 'nb': 1, 'datetime' : 1}.has_key

SQLVar.render = SQLVar_render
SQLVar.__call__ = SQLVar_render
sqlvar.valid_type = valid_type